【问题标题】:CAD insert block with thumbnail under mouse鼠标下带有缩略图的 CAD 插入块
【发布时间】: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


【解决方案1】:

您将需要使用 AcEdJig 类。它提供了预览。您必须编写代码来收集插入点和旋转并相应地转换块。

Here 是我的谷歌搜索示例使用代码的第一个链接。

【讨论】:

  • 你知道一些 .NET 包装器吗?
【解决方案2】:

似乎 Jigging 是允许预览的方法。我为你准备了三个链接。

第一个是使用折线创建简单夹具的示例 - 您可以将其扩展到块。

第二个链接类似,但对混音应用了轮换。这适用于矩形,但可以再次修改以容纳块。

第三个链接描述了一种不同的方法——AutoCAD 的瞬态图形界面。您必须使用 AutoCAD 2009 或更高版本才能使用此方法。

最后两个链接来自 Through the Interface 博客,您可以在其中找到更多示例,如果您遇到问题,这是一个很好的起点,尤其是对于 C# 编码。

【讨论】:

  • 谢谢,从简单的概述来看,它似乎可以解决问题,但我无法使用此解决方案,因为其他 CAD 环境(特别是 BricsCAD)没有 Jig 逻辑。我想知道这两种环境的独特解决方案,但现在我认为避免 SendCommands 可能是不可能的。无论如何谢谢你的建议。
猜你喜欢
  • 2020-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-27
  • 2014-05-05
  • 2014-09-23
  • 2018-03-10
  • 2017-04-24
相关资源
最近更新 更多