対象製品: IJCAD 2015 以降
IJCAD 2016 から.NET APIに同期的にコマンドを実行する為の機能が実装されました。
サンプルでは線分を作図した後にオブジェクト範囲でズームを行っています。
VB.NET
Imports GrxCAD.ApplicationServices
Imports GrxCAD.DatabaseServices
Imports GrxCAD.EditorInput
Imports GrxCAD.Geometry
Imports GrxCAD.Runtime
Public Class Sample
<CommandMethod("ADDLINE_NET")>
Public Sub AddLineCmd_NET()
Dim icDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim icEd As Editor = icDoc.Editor
'LINEコマンドの呼び出し + ズーム(オブジェクト範囲)
icEd.Command("_LINE", "0,0,0", "50,50,0", "", "ZOOM", "E")
End Sub
End Class
C#
using GrxCAD.ApplicationServices;
using GrxCAD.DatabaseServices;
using GrxCAD.EditorInput;
using GrxCAD.Geometry;
using GrxCAD.Runtime;
public class Sample
{
[CommandMethod("ADDLINE_NET")]
public void AddLineCmd_NET()
{
Document icDoc = Application.DocumentManager.MdiActiveDocument;
Editor icEd = icDoc.Editor;
//LINEコマンドの呼び出し + ズーム(オブジェクト範囲)
icEd.Command("_LINE", "0,0,0", "50,50,0", "", "ZOOM", "E");
}
}
IJCAD 2015 の .NET API にはこの機能は実装されておりません。
IJCAD 2015 でコマンドを同期的に実行する為にはP/Invoke という方法を使用して、
GRXSDK の gcedCmd() という関数を呼び出す必要があります。
Imports GrxCAD.ApplicationServices
Imports GrxCAD.DatabaseServices
Imports GrxCAD.EditorInput
Imports GrxCAD.Geometry
Imports GrxCAD.Runtime
Imports System.Runtime.InteropServices
Public Class Class1
<DllImport("gcap.dll", CallingConvention:=CallingConvention.Cdecl, EntryPoint:="gcedCmd")>
Private Shared Function acedCmd(ByVal request As IntPtr) As Integer
<CommandMethod("MYSAVE", CommandFlags.Modal)>
Public Sub MySaveCmd()
Dim icdDoc As Document = Application.DocumentManager.MdiActiveDocument
' QSAVE;CLOSE;の呼出し
Dim tvl(0 To 1) As TypedValue
tvl.SetValue(New TypedValue(5005, "QSAVE"), 0)
tvl.SetValue(New TypedValue(5005, "CLOSE"), 1)
Dim req As ResultBuffer = New ResultBuffer(tvl)
Dim ret As Integer
ret = acedCmd(req.ResbufObject)
End Sub
End Class
IJCADではgcedCmdに値を渡す際に、ResbufObjectを使用する必要があります。
AutoCADのようにUnmanagedObjectを使用すると、IJCADでは例外が発生してしまいます。
コメント