一般用法是ThisDrawing.ModelSpace ThisDrawing.Application.ActiveDocument.ModelSpace的用法虽然正确,但不常用。 见下载程序的两个示例。 Sub EditLwPolyline() Dim objLwPl As AcadLWPolyline Dim xy(5) As Double xy(0) = 100: xy(1) = 200 xy(2) = 300: xy(3) = 300 xy(4) = 500: xy(5) = 600 Set objLwPl = ThisDrawing.Application.ActiveDocument.ModelSpace.AddLightWeightPolyline(xy) objLwPl.Closed = True '闭合 objLwPl.ConstantWidth = 0 '全局宽度 objLwPl.Linetype = "10421" '线型(加载了才可用) objLwPl.Highlight True '高亮显示 MsgBox "ID=" & objLwPl.ObjectID MsgBox "类型=" & objLwPl.ObjectName MsgBox "句柄=" & objLwPl.Handle MsgBox "多段线坐标为:(" & objLwPl.Coordinates(0) & "," & objLwPl.Coordinates(1) & "),(" & objLwPl.Coordinates(2) & "," & objLwPl.Coordinates(3) & "),(" & objLwPl.Coordinates(4) & "," & objLwPl.Coordinates(5) & ")" End Sub Sub EditText() Dim objText As AcadText Dim xy(2) As Double xy(0) = 100: xy(1) = 200: xy(2) = 300 Set objText = ThisDrawing.Application.ActiveDocument.ModelSpace.AddText("Hello World!", xy, 30) MsgBox "插入点位置" & objText.insertionPoint(0) & "," & objText.insertionPoint(1) & "," & objText.insertionPoint(2) & ")" objText.Alignment = acAlignmentBottomRight '对齐方式 objText.height = 20 '高度 objText.StyleName = "STANDARD" '样式 objText.TextString = "AutoCAD VBA 测绘" '文字内容 End Sub |