如何获取块在图中的实体?
我的意思是如果我已知块的名称为"ABC",想取得块ABC在图的实体,即想通块名称来删除图中该块实体图形.我现在的一个方法如下,但我感觉不是太好太快,有没更好的呢?
Dim n
Dim sset As AcadSelectionSet
n = SetForegroundWindow(aCADapp.hwnd)
Set sset = aCADdoc.SelectionSets.Add("SelectText")
sset.Clear
Dim Filtertype(0) As Integer, Filterdata(0) As Variant, Mode As Variant
Filtertype(0) = 0
Filterdata(0) = "BLOCK"
Mode = acSelectionSetAll
sset.Select Mode, Filtertype, Filterdata
Dim entry As AcadBlockReference
For Each entry In sset
If entry.Name = "ABC" Then entry.Delete
Next entry
sset.Delete
Set sset = Nothing
建立块选择集,遍历选择集,如名称为"ABC",则删除 有没有通过块名称得到该块实体的函数? 另外还有一个问题是如何通VBA(或VB)删除块,我用myblock.Item(i).Delete提示无法用VBA删除块.???? RetVal = Document.Blocks.Item(Index)
Object
, ,
使用该方法的对象。
Index
Variant[变体]; 仅用于输入
要查询的集合成员项的索引位置。
索引必须为整数或字符串。如果为整数,索引必须在 0 和 N-1 间。这里 N 为集合或选择集的对象数量。
RetVal
Object[对象]
在集合或选择集中给定索引位置的对象。
虽然blocks集合继承Delete方法,用户仍然无法真正删除集合。 企图删除blocks集合会产生错误
说明
该方法支持使用字符串。例如,如果用以下语句创建了名称为 BLOCK1 的块:
Set block1 = Blocks.Add("BLOCK1")
则可通过以下语句引用该对象:
Set whichblock = Blocks.Item("BLOCK1")
参考 <RE class=Code>回楼上的<RE class=Code>Set whichblock = Blocks.Item("BLOCK1")
只是得到块"BLOCK1",那么如何用它来得到该块在图中的实体(集)呢?<RE class=Code>即我想通过块获得块的具体在图中的实体,来将进行删除等操作.<RE class=Code>另外,如果该块的在图中的实体都已删除了,那么如何来删除该块呢?<RE class=Code>即类似于CAD命令中的PURGE. 我现在是通过如下方法实现的,但感觉效率不是太高,有没有更好的方法呢?
Dim n
Dim sset As AcadSelectionSet
Dim RetVal As AcadBlock
n = SetForegroundWindow(aCADapp.hwnd)
Set sset = aCADdoc.SelectionSets.Add("SelectText")
sset.Clear
Dim Filtertype(0) As Integer, Filterdata(0) As Variant, Mode As Variant
Filtertype(0) = 0
Filterdata(0) = "BLOCK"
Mode = acSelectionSetAll
sset.Select Mode, Filtertype, Filterdata
Dim entry As AcadBlockReference
For Each entry In sset
If entry.Name = "ABC" Then entry.Delete
Next entry
sset.Delete
Set sset = Nothing
Set RetVal = aCADdoc.Blocks.Item("ABC")
RetVal.Delete
Set RetVal = Nothing
页:
[1]