首页 > 电脑

请问怎么用vba获取cad中所有指定的块的坐标。

更新时间2018-08-23 17:12:38

1.要改两个部份,第一步,改首行的private 为 public
2.ss_dim.Select acSelectionSetAll, , , dxf_code, dxf_value
改正:
ss_dim.SelectOnScreen dxf_code, dxf_value
这样就是输出选中对象了。
----------------------------
Public Sub GetLWPOLYLINECoordinates()
Dim ss_dim As AcadSelectionSet, ent As AcadLWPolyline
Dim dxf_code() As Integer, dxf_value() As Variant
Dim i As Long, j As Long
Dim dbCor As Variant, x As Double, y As Double, z As Double
Set ss_dim = ThisDrawing.SelectionSets.Add("ssLine1")
ReDim dxf_code(0), dxf_value(0)
dxf_code(0) = 0: dxf_value(0) = "LWPOLYLINE"
'ss_dim.Select acSelectionSetAll, , , dxf_code, dxf_value
ss_dim.SelectOnScreen dxf_code, dxf_value
Open "d:aaaaa.txt" For Append As #1
For Each ent In ss_dim
For j = 0 To UBound(ent.Coordinates) 2
x = ent.Coordinates(j * 2)
y = ent.Coordinates(j * 2 + 1)
Print #1, (j); ",," & x & "," & y
Next
Next
Close #1
ss_dim.Clear
ss_dim.Delete
End Sub1.要改两个部份,第一步,改首行的private 为 public
2.ss_dim.Select acSelectionSetAll, , , dxf_code, dxf_value
改正:
ss_dim.SelectOnScreen dxf_code, dxf_value
这样就是输出选中对象了。
----------------------------
Public Sub GetLWPOLYLINECoordinates()
Dim ss_dim As AcadSelectionSet, ent As AcadLWPolyline
Dim dxf_code() As Integer, dxf_value() As Variant
Dim i As Long, j As Long
Dim dbCor As Variant, x As Double, y As Double, z As Double
Set ss_dim = ThisDrawing.SelectionSets.Add("ssLine1")
ReDim dxf_code(0), dxf_value(0)
dxf_code(0) = 0: dxf_value(0) = "LWPOLYLINE"
'ss_dim.Select acSelectionSetAll, , , dxf_code, dxf_value
ss_dim.SelectOnScreen dxf_code, dxf_value
Open "d:aaaaa.txt" For Append As #1
For Each ent In ss_dim
For j = 0 To UBound(ent.Coordinates) 2
x = ent.Coordinates(j * 2)
y = ent.Coordinates(j * 2 + 1)
Print #1, (j); ",," & x & "," & y
Next
Next
Close #1
ss_dim.Clear
ss_dim.Delete
End Sub

上一篇:饥荒代码问题

下一篇:请教大神帮忙咋弄