如何获得已知块名的块的位置??
有vba的例程吗?objectarx的也可以 用选择集选择图形中指定块名的块,然后遍历所有的图块,并取得插入点位置或框位置。 下面的两种方法都可以实现:
Sub Test1()
Dim BlockRefObj As AcadBlockReference
Dim EntObj As AcadEntity
Dim BlockName As String
BlockName = "块名"
'遍历模型空间,判断实体的类型。如果是块,判断块名。
For Each EntObj In ThisDrawing.ModelSpace
If TypeOf EntObj Is AcadBlockReference Then
Set BlockRefObj = EntObj
If BlockRefObj.Name = BlockName Then
Debug.Print "插入点位置: " & BlockRefObj.InsertionPoint(0) & BlockRefObj.InsertionPoint(1)
End If
End If
Next
End Sub
Sub Test2()
Dim BlockRefObj As AcadBlockReference
Dim EntObj As AcadEntity
Dim SSetObj As AcadSelectionSet
Dim BlockName As String
BlockName = "块名"
'使用过滤机制,全部选中指定名称的块。
On Error Resume Next
Set SSetObj = ThisDrawing.SelectionSets("Test")
If Err Then
Err.Clear
Set SSetObj = ThisDrawing.SelectionSets.Add("Test")
End If
SSetObj.Clear
On Error GoTo 0
Dim GroupCode(0 To 1) As Integer
Dim DataValue(0 To 1) As Variant
GroupCode(0) = 0
DataValue(0) = "INSERT"
GroupCode(1) = 2
DataValue(1) = BlockName
SSetObj.Select acSelectionSetAll, , , GroupCode, DataValue
For Each EntObj In SSetObj
Set BlockRefObj = EntObj
If BlockRefObj.Name = BlockName Then
Debug.Print "插入点位置: " & BlockRefObj.InsertionPoint(0) & BlockRefObj.InsertionPoint(1)
End If
Next
End Sub
有个奇怪的问题,
我用的是AddLWPolyLine来创建的对象
选择时用
“LightWeightPolyLine"却不行
用“polyline"才可以,
这是什么道理
我用AddPolyLine创建的对象
选择时用“Polyline"也不行了,不知道用什么好 <p>有没有C#的例子啊</p>
<p> </p> 谢谢了,帮助很大,终于让我可以已知块名改此块的属性了,大好人了 谢谢,这个对我的帮助也挺大的! 还是选择集靠谱。遍历图纸的画,如果图形数据较多,半天都没反应啊!
页:
[1]