我开发了一个外部 WPF 应用程序来在 c# 中生成绘图。我已经能够使用 Autodesk.AutoCAD.Interop 绘制、标注、添加块以及应用程序所需的所有其他内容,但是我似乎无法填充标题栏或生成零件列表。
我见过的所有示例都基于要求应用程序在 AutoCAD 中作为插件运行的机制。事实是,使用ModelSpace.InsertLine插入一行是一两行代码,现在,至少是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;
}
}