如何使用 VBA 在 AUTOCAD 中操作屏幕上的选定对象?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8462547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:41:18  来源:igfitidea点击:

How to manipulate the selected objects on screen in AUTOCAD using VBA?

vbaautocad

提问by sean

In autocad 2008, I want to learn how to operate the screen selected objects. There is a VBA object named ThisDrawing.SelectionSets, but it is a sets of selections, not the selected objects which are selected by user. Which VBA object represents the user selected objects?

在autocad 2008中,我想学习如何操作屏幕选定对象。有一个名为 ThisDrawing.SelectionSets 的 VBA 对象,但它是一组选择,而不是用户选择的选定对象。哪个 VBA 对象代表用户选择的对象?

回答by mohnston

There is also a "built-in" selection set you can use that represents the currently selected objects.

您还可以使用“内置”选择集来表示当前选定的对象。

Public Sub test()
    Dim ss As AcadSelectionSet
    Set ss = ThisDrawing.ActiveSelectionSet
    MsgBox ss.Count

End Sub

回答by JayP

You actually need to create your own Selection Set and add it to ThisDrawing.SelectionSets.

您实际上需要创建自己的选择集并将其添加到ThisDrawing.SelectionSets.

Then when the user clicks on an entity you need to add it to the Selection Set you created.

然后当用户单击一个实体时,您需要将其添加到您创建的选择集。

Finally, you can then step through every entity in the Selection Set to perform some manipulation on it.

最后,您可以逐步遍历选择集中的每个实体以对其执行一些操作。

I'm sorry I can't offer VBA code as I use C# but this is the process that you need to follow. You can however get help from within AutoCAD itself by hitting F1 and then looking under:

很抱歉,我无法提供 VBA 代码,因为我使用 C#,但这是您需要遵循的过程。但是,您可以通过按 F1 然后查看以下内容从 AutoCAD 本身获得帮助:

ActiveX and VBA Developer's Guide -> Create and Edit AutoCAD Entities -> Work with Selection Sets

ActiveX 和 VBA 开发人员指南 -> 创建和编辑 AutoCAD 实体 -> 使用选择集