c# - 有没有办法使用 C# 获取 autocad (.dwg) 中的所有多段线?

标签 c# autocad autocad-plugin

我不想在运行时选择特定的折线。有没有一种方法可以在运行时使用 C# 直接获取 .dwg 文件中的所有多段线而无需选择? AutoCAD有一个叫DATAEXTRACTION的命令可以获取不同对象的相关信息(例如折线、圆、点...等),但我不知道它是否可以在C#中调用和使用。

仅供引用:在运行时从
http://through-the-interface.typepad.com/through_the_interface/2007/04/iterating_throu.html 获取特定折线的示例代码:

Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
   DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);
   Polyline lwp = obj as Polyline; // Get the selected polyline during runtime
   ...
}

最佳答案

听起来您正在寻找这样的东西。如果不需要,请删除图层标准。

public ObjectIdCollection SelectAllPolylineByLayer(string sLayer)
{
    Document oDwg = Application.DocumentManager.MdiActiveDocument; 
    Editor oEd = oDwg.Editor;

    ObjectIdCollection retVal = null;

    try {
        // Get a selection set of all possible polyline entities on the requested layer
        PromptSelectionResult oPSR = null;

        TypedValue[] tvs = new TypedValue[] {
            new TypedValue(Convert.ToInt32(DxfCode.Operator), "<and"),
            new TypedValue(Convert.ToInt32(DxfCode.LayerName), sLayer),
            new TypedValue(Convert.ToInt32(DxfCode.Operator), "<or"),
            new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE"),
            new TypedValue(Convert.ToInt32(DxfCode.Start), "LWPOLYLINE"),
            new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE2D"),
            new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE3d"),
            new TypedValue(Convert.ToInt32(DxfCode.Operator), "or>"),
            new TypedValue(Convert.ToInt32(DxfCode.Operator), "and>")
        };

        SelectionFilter oSf = new SelectionFilter(tvs);

        oPSR = oEd.SelectAll(oSf);

        if (oPSR.Status == PromptStatus.OK) {
            retVal = new ObjectIdCollection(oPSR.Value.GetObjectIds());
        } else {
            retVal = new ObjectIdCollection();
        }
    } catch (System.Exception ex) {
        ReportError(ex);
    }

    return retVal;
}

关于c# - 有没有办法使用 C# 获取 autocad (.dwg) 中的所有多段线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27825550/

相关文章:

c# - 用 C# 模仿 AutoCAD 的 viewcube 的行为

c# - .NET Core 2.2 HttpClient/WebClient vs Curl - .NET 库对于某些服务器来说非常慢

c# - 上下文菜单中的绑定(bind)命令

c# - C# 中的计算开销 - 使用 getter/setter 与直接修改数组和转换速度

autocad - SaveAs in COM挂AutoCAD

c# - Visual Studio 2015 - Windows CE 6.0 (Compact Framework 3.5) 编程

lisp - AutoCAD 中的 AutoLISP 函数错误参数

c# - 如何根据第一条折线转换第二条折线

c# - C# 旋转函数的奇怪行为