Question

I want to convert this VBA code in C# language but I get this error: 'SolidWorks.Interop.sldworks.IFace2.Normal' is a 'property' but is used like a 'method'

Please help me how can I resolve this error.

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;
    }
}

I have one more question. How can I convert this:

VBA: `

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

`

C# (don't work) `

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

`

Was it helpful?

Solution

Change this line

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

to

Double[] vNorm = (Double[])swFace.Normal;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top