我可以使用 COM api 过滤 AutoCAD 选择集吗?

Posted

技术标签:

【中文标题】我可以使用 COM api 过滤 AutoCAD 选择集吗?【英文标题】:Can I filter an AutoCAD SelectionSet with the COM api? 【发布时间】:2019-09-09 06:49:21 【问题描述】:

我正在为 AutoCAD 编写一个外部工具(使用 COM api),我需要过滤一个 SelectionSet,但我无法确定“FilterType”和“FilterData”参数的正确类型。

我知道它已经过时了,但我需要使用 COM api,而且我一辈子都找不到任何文档。有更多经验的人可以帮我解决这个问题吗?

这些是有问题的行:

AcadApplication app = Marshal.GetActiveObject(AppID) as AcadApplication;
AcadSelectionSet SelectionSet = app.ActiveDocument.SelectionSets.Add(name);

int[] filterType = new int[1];
object[] filterData = new object[1];

filterType[0] = (int)DxfCode.BlockName;
filterData[0] = "T-siman";

SelectionSet.SelectOnScreen(filterType, filterData);

最后一行返回以下异常: System.ArgumentException: 'SelectOnScreen 中的参数 FilterType 无效'

【问题讨论】:

【参考方案1】:

我一直在寻找解决方案,因为我被卡住了,但后来我找到了THIS QUESTION 并注意到这个人使用“短”类型的数组而不是“int”类型的数组作为“FilterType”参数。这样做对我有用。

我的工作代码:

AcadApplication app = Marshal.GetActiveObject(AppID) as AcadApplication;
AcadSelectionSet SelectionSet = app.ActiveDocument.SelectionSets.Add(name);

short[] filterType = new short[1];
object[] filterData = new object[1];

filterType[0] = (short)DxfCode.BlockName;
filterData[0] = "T-siman";

SelectionSet.SelectOnScreen(filterType, filterData);

【讨论】:

以上是关于我可以使用 COM api 过滤 AutoCAD 选择集吗?的主要内容,如果未能解决你的问题,请参考以下文章