この VBA コードを C# 言語に変換したいのですが、次のエラーが表示されます: '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;
}
}
もう1つ質問があります。これを変換するにはどうすればよいですか:
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");
`