1

我想用 C# 语言转换这个 VBA 代码,但我收到了这个错误:'SolidWorks.Interop.sldworks.IFace2.Normal' 是一个'属性',但用作'方法'

请帮助我如何解决此错误。

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");

`

4

1 回答 1

4

更改此行

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

Double[] vNorm = (Double[])swFace.Normal;
于 2012-11-17T13:20:43.520 回答