【发布时间】:2012-03-17 02:21:27
【问题描述】:
我需要通过 C# 插件将外部 DWG 插入到 AutoCAD 图形中。 我需要向用户“询问”插入块的插入点和旋转。 到目前为止,我一直使用一个调用命令“._-insert”的 lisp 函数,它给出了鼠标下块的缩略图,允许用户单击绘图以设置插入点,并且从该点开始允许用户再单击一次以设置旋转。 现在我想避免使用 Lisp 或使用 AutoCAD 的低级 API,因为我需要一个可以在各种 CAD 环境中运行的解决方案。 我发现是这样的:
public static void InsertDwg(string dwgName)
{
CADAPI.ApplicationServices.Document doc = CADAPI.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
CADDB.Database db = doc.Database;
CADAPI.EditorInput.Editor ed = doc.Editor;
CADDB.ObjectId ObjId;
using (CADDB.Transaction trx = db.TransactionManager.StartTransaction())
{
CADDB.BlockTable bt = db.BlockTableId.GetObject(CADDB.OpenMode.ForRead) as CADDB.BlockTable;
CADDB.BlockTableRecord btrMs = bt[CADDB.BlockTableRecord.ModelSpace].GetObject(CADDB.OpenMode.ForWrite) as CADDB.BlockTableRecord;
using (CADDB.Database dbInsert = new CADDB.Database(false, true))
{
dbInsert.ReadDwgFile(dwgName, CADDB.FileOpenMode.OpenForReadAndAllShare, true, string.Empty);
ObjId = db.Insert(Path.GetFileNameWithoutExtension(dwgName), dbInsert, true);
}
CADAPI.EditorInput.PromptPointOptions ppo = new CADAPI.EditorInput.PromptPointOptions("\nInsertion Point");
CADAPI.EditorInput.PromptAngleOptions ppa = new CADAPI.EditorInput.PromptAngleOptions("\nInsert Rotation");
CADAPI.EditorInput.PromptPointResult ppr;
ppr = ed.GetPoint(ppo);
CADAPI.EditorInput.PromptDoubleResult ppd = ed.GetAngle(ppa);
if (ppr.Status == CADAPI.EditorInput.PromptStatus.OK)
{
CADGEOM.Point3d insertPt = ppr.Value;
CADDB.BlockReference bref = new CADDB.BlockReference(insertPt, ObjId);
btrMs.AppendEntity(bref);
trx.AddNewlyCreatedDBObject(bref, true);
trx.Commit();
}
}
}
但是在这里我有两个问题: 最主要的是鼠标下没有预览。 二是用户需要点击 3 次而不是 2 次来设置插入点和旋转。
有没有什么方法不使用某种SendCommand 并做所有这些事情?
TIA
【问题讨论】:
-
请标记C#而不是在标题中使用它
标签: c# .net insert thumbnails autocad