C# で図面を生成するための外部 WPF アプリケーションを開発しました。Autodesk.AutoCAD.Interop を使用して、アプリケーションで必要な描画、寸法記入、ブロックの追加、その他すべてを行うことができました。
私が見たすべての例は、AutoCAD 内でアプリケーションをプラグインとして実行する必要があるメカニズムに基づいています。実のところ、使用される行の挿入は、ModelSpace.InsertLine を使用した 1 行または 2 行のコードですが、今では少なくとも 8 行のコードです!
Autodesk.AutoCAD.Interop を使用してこの機能を実現する方法はありますか? または、相互運用機能を使用して、外部の exe から呼び出すことができるプラグインと組み合わせる方法はありますか?
これに関する任意のポインタをいただければ幸いです。
ありがとう。
編集 説明するには:
// before - Draw Line with Autodesk.AutoCAD.Interop
private static AcadLine DrawLine(double[] startPoint, double[] endPoint)
{
AcadLine line = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint);
return line;
}
// Now - Draw line with Autodesk.AutoCAD.Runtime
[CommandMethod("DrawLine")]
public static Line DrawLine(Coordinate start, Coordinate end)
{
// Get the current document and database
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Create a line that starts at 5,5 and ends at 12,3
Line acLine = new Line(start.Point3d, end.Point3d);
acLine.SetDatabaseDefaults();
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acLine);
acTrans.AddNewlyCreatedDBObject(acLine, true);
// Save the new object to the database
acTrans.Commit();
return acLine;
}
}