2012-11-17 75 views
0

我想用C#語言轉換此VBA代碼,但出現此錯誤:'SolidWorks.Interop.sldworks.IFace2.Normal'是'屬性',但像'方法'一樣使用從VBA轉換爲C#

請幫我解決這個錯誤。

VBA:

Option Explicit On 
Sub main() 
    Dim swApp As SldWorks.SldWorks 
    Dim swModel As SldWorks.ModelDoc2 
    Dim swSelMgr As SldWorks.SelectionMgr 
    Dim swFace As SldWorks.face2 
    Dim vNorm As Object 

    swApp = Application.SldWorks 
    swModel = swApp.ActiveDoc 
    swSelMgr = swModel.SelectionManager 
    swFace = swSelMgr.GetSelectedObject5(1) 

    vNorm = swFace.Normal 
    Debug.Print("Normal = (" & vNorm(0) & ", " & vNorm(1) & ", " & vNorm(2) & ")") 
End Sub 

C#:

using SolidWorks.Interop.sldworks; 
using SolidWorks.Interop.swconst; 
using System.Runtime.InteropServices; 
using System; 
using System.Diagnostics; 

namespace NORMAL.csproj 
{ 
    public partial class SolidWorksMacro 
    { 
     public void Main() 
     { 

      SldWorks swApp = default(SldWorks); ModelDoc2 swModel = default(ModelDoc2); SelectionMgr swSelMgr = default(SelectionMgr); Face2 swFace = default(Face2); 

      swModel = (ModelDoc2)swApp.ActiveDoc; 
      swSelMgr = (SelectionMgr)swModel.SelectionManager; 
      swFace = (Face2)swSelMgr.GetSelectedObject6(1, -1); 

      Double[] vNorm = (Double[])swFace.Normal(); 
      Debug.Print("vNorm: " + vNorm[0]); 
     } 
     /// <summary> 
     /// The SldWorks swApp variable is pre-assigned for you. 
     /// </summary> 
     public SldWorks swApp; 
    } 
} 

我有一個問題。 我如何轉換這樣:

VBA: `

Set swXform = swDocExt.GetCoordinateSystemTransformByName(sAxisName) 
Debug.Print " Rotational sub-matrix 1 = (" & swXform.ArrayData(2) & ")" 

`

C#(不工作) `

swXform = swDocExt.GetCoordinateSystemTransformByName(sAxisName); 
Debug.Print(" Rotational sub-matrix 1 = (" + swXform.ArrayData[2] + ") mm"); 

`

回答

3

變化這條線

Double[] vNorm = (Double[])swFace.Normal(); 

Double[] vNorm = (Double[])swFace.Normal; 
+0

非常感謝你。 – user1817942

+0

@ user1817942不客氣:) – BlackBear

+0

我又增加了一個問題,請回答。 – user1817942