您可以直接引用对象,也可以通过用户定义的变量引用对象。若要直接引用对象,请将对象包含在调用层次结构中。 例如,以下语句在模型空间中添加一行。请注意,层次结构以 开头,转到对象,然后调用该方法:ThisDrawingModelSpaceAddLine Dim startPoint(0 To 2) As Double, endPoint(0 To 2) As Double Dim LineObj as AcadLine startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0 endPoint(0) = 30: endPoint(1) = 20: endPoint(2) = 0 Set LineObj = ThisDrawing.ModelSpace.AddLine(startPoint,endPoint) 若要通过用户定义的变量引用对象,请将变量定义为所需类型,然后将变量设置为适当的对象。例如,以下代码定义一个类型为 () 的变量,并将该变量设置为等于当前模型空间:moSpaceAcadModelSpace Dim moSpace As AcadModelSpace Set moSpace = ThisDrawing.ModelSpace 然后,以下语句使用用户定义的变量向模型空间添加一行: Dim startPoint(0 To 2) As Double, endPoint(0 To 2) As Double Dim LineObj as AcadLine startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0 endPoint(0) = 30: endPoint(1) = 20: endPoint(2) = 0 Set LineObj = moSpace.AddLine(startPoint,endPoint) 检索模型空间中的第一个实体下面的示例返回模型空间中的第一个实体对象。类似的代码可以对纸张空间实体执行相同的操作。请注意,所有图形对象都可以定义为对象:AcadEntity Sub Ch2_FindFirstEntity() ' This example returns the first entity in model space On Error Resume Next Dim entity As AcadEntity If ThisDrawing.ModelSpace.count <> 0 Then Set entity = ThisDrawing.ModelSpace.Item(0) MsgBox entity.ObjectName + _ " is the first entity in model space." Else MsgBox "There are no objects in model space." End If End Sub |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:08
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.