ntfanl 发表于 2005-12-14 17:03:00

如何获取块在图中的实体?

本帖最后由 作者 于 2005-12-14 17:31:51 编辑 <br /><br /> <P>我的意思是如果我已知块的名称为"ABC",想取得块ABC在图的实体,即想通块名称来删除图中该块实体图形.</P>
<P>我现在的一个方法如下,但我感觉不是太好太快,有没更好的呢?</P>
<P>&nbsp;&nbsp;&nbsp; Dim n</P>
<P>&nbsp;&nbsp;&nbsp; Dim sset As AcadSelectionSet</P>
<P>&nbsp;&nbsp;&nbsp; n = SetForegroundWindow(aCADapp.hwnd)<BR>&nbsp;&nbsp;&nbsp; Set sset = aCADdoc.SelectionSets.Add("SelectText")<BR>&nbsp;&nbsp;&nbsp; sset.Clear<BR>&nbsp;&nbsp;&nbsp; Dim Filtertype(0) As Integer, Filterdata(0) As Variant, Mode As Variant<BR>&nbsp;&nbsp;&nbsp; Filtertype(0) = 0<BR>&nbsp;&nbsp;&nbsp; Filterdata(0) = "BLOCK"<BR>&nbsp;&nbsp;&nbsp; Mode = acSelectionSetAll<BR>&nbsp;&nbsp;&nbsp; sset.Select Mode, Filtertype, Filterdata<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim entry As AcadBlockReference<BR>&nbsp;&nbsp;&nbsp; For Each entry In sset<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If entry.Name = "ABC" Then entry.Delete<BR>&nbsp;&nbsp;&nbsp; Next entry<BR>&nbsp;&nbsp;&nbsp; sset.Delete<BR>&nbsp;&nbsp;&nbsp; Set sset = Nothing<BR></P>

wyj7485 发表于 2005-12-14 17:31:00

建立块选择集,遍历选择集,如名称为"ABC",则删除

ntfanl 发表于 2005-12-14 17:33:00

有没有通过块名称得到该块实体的函数?

ntfanl 发表于 2005-12-14 17:41:00

另外还有一个问题是如何通VBA(或VB)删除块,我用myblock.Item(i).Delete提示无法用VBA删除块.????

wyj7485 发表于 2005-12-14 17:46:00

<P class=syntax>RetVal = Document.Blocks.Item(Index)
<P class=element>Object</P>
<P class=element-desc><A href="mk:@MSITStore:C:\Documents%20and%20Settings\gmj-wyj.MYHF\桌面\Autocad2006对象模型.chm::/all_collection_objects.htm" target="_blank" >All Collections</A>, <A href="mk:@MSITStore:C:\Documents%20and%20Settings\gmj-wyj.MYHF\桌面\Autocad2006对象模型.chm::/idh_group_object.htm" target="_blank" >Group</A>, <A href="mk:@MSITStore:C:\Documents%20and%20Settings\gmj-wyj.MYHF\桌面\Autocad2006对象模型.chm::/idh_selectionset_object.htm" target="_blank" >SelectionSet</A><BR>使用该方法的对象。
<P class=element>Index</P>
<P class=element-desc>Variant[变体]; 仅用于输入<BR>要查询的集合成员项的索引位置。<BR>索引必须为整数或字符串。如果为整数,索引必须在 0 和 N-1 间。这里 N 为集合或选择集的对象数量。
<P class=element>RetVal</P>
<P class=element-desc>Object[对象]<BR>在集合或选择集中给定索引位置的对象。 </P>
<P class=Bullet2-end>虽然blocks集合继承Delete方法,用户仍然无法真正删除集合。 企图删除blocks集合会产生错误</P>
<P class=body-code-begin>说明</P>
<P class=body-code-begin>该方法支持使用字符串。例如,如果用以下语句创建了名称为 BLOCK1 的块:</P><PRE class=Code>Set block1 = Blocks.Add("BLOCK1")
</PRE>
<P class=body-code-begin>则可通过以下语句引用该对象:</P><PRE class=Code>Set whichblock = Blocks.Item("BLOCK1")
</PRE>

wyj7485 发表于 2005-12-14 17:49:00

参考<A href="http://www.mjtd.com/object/acad2004/" target="_blank" >http://www.mjtd.com/object/acad2004/</A>

ntfanl 发表于 2005-12-15 11:25:00

<PRE class=Code>回楼上的</PRE><PRE class=Code>Set whichblock = Blocks.Item("BLOCK1")
只是得到块"BLOCK1",那么如何用它来得到该块在图中的实体(集)呢?</PRE><PRE class=Code>即我想通过块获得块的具体在图中的实体,来将进行删除等操作.</PRE><PRE class=Code>另外,如果该块的在图中的实体都已删除了,那么如何来删除该块呢?</PRE><PRE class=Code>即类似于CAD命令中的PURGE.</PRE>

ntfanl 发表于 2005-12-15 11:32:00

<P>我现在是通过如下方法实现的,但感觉效率不是太高,有没有更好的方法呢?</P>
<P>Dim n</P>
<P>Dim sset As AcadSelectionSet<BR>Dim RetVal As AcadBlock<BR><BR>&nbsp;&nbsp;&nbsp; n = SetForegroundWindow(aCADapp.hwnd)<BR>&nbsp;&nbsp;&nbsp; Set sset = aCADdoc.SelectionSets.Add("SelectText")<BR>&nbsp;&nbsp;&nbsp; sset.Clear<BR>&nbsp;&nbsp;&nbsp; Dim Filtertype(0) As Integer, Filterdata(0) As Variant, Mode As Variant<BR>&nbsp;&nbsp;&nbsp; Filtertype(0) = 0<BR>&nbsp;&nbsp;&nbsp; Filterdata(0) = "BLOCK"<BR>&nbsp;&nbsp;&nbsp; Mode = acSelectionSetAll<BR>&nbsp;&nbsp;&nbsp; sset.Select Mode, Filtertype, Filterdata<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim entry As AcadBlockReference<BR>&nbsp;&nbsp;&nbsp; For Each entry In sset<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If entry.Name = "ABC" Then entry.Delete<BR>&nbsp;&nbsp;&nbsp; Next entry<BR>&nbsp;&nbsp;&nbsp; sset.Delete<BR>&nbsp;&nbsp;&nbsp; Set sset = Nothing</P>
<P><BR>&nbsp;&nbsp;&nbsp; Set RetVal = aCADdoc.Blocks.Item("ABC")<BR>&nbsp;&nbsp;&nbsp; RetVal.Delete<BR>&nbsp;&nbsp;&nbsp; Set RetVal = Nothing<BR></P>
页: [1]
查看完整版本: 如何获取块在图中的实体?