huangbinlq 发表于 2007-8-12 22:41:00

如何删除图块对象

假设dwg文件中有很多的图块对象, 图块的名称是" 椅子",请问如何用vba将其全部删除,谢谢!

gyl 发表于 2007-8-13 07:58:00

先删除块参考,再删除块定义。

huangbinlq 发表于 2007-8-13 12:49:00

请具体点好吗,我会删除块对象,但不知如何删除块参照,请作个示例好吗

xxxtttxxx 发表于 2007-8-13 17:18:00

<p>删除块对象后,块参照对象难道还存在于modelspace中吗?</p><p>先在modelspace里面选择,用select acselectionall,,, filtertype ,filterdata</p><p>其中filtertype=2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; filterdata=blockname</p><p>for each entity in sset</p><p>entity.delete</p><p>next</p><p>请高手指正</p><p></p>

gyl 发表于 2007-8-13 21:31:00

<p>Sub DeleteBlock()<br/>&nbsp;&nbsp;&nbsp; Dim ObjBlockRef As AcadBlockReference<br/>&nbsp;&nbsp;&nbsp; Dim FilterType(0) As Integer, FilterData(0) As Variant<br/>&nbsp;&nbsp;&nbsp; Dim sset As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '选中名为"椅子"的块参照并删除<br/>&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Add("test")<br/>&nbsp;&nbsp;&nbsp; FilterType(0) = 2<br/>&nbsp;&nbsp;&nbsp; FilterData(0) = "椅子"<br/>&nbsp;&nbsp;&nbsp; sset.Select acSelectionSetAll, , , FilterType, FilterData<br/>&nbsp;&nbsp;&nbsp; For Each ObjBlockRef In sset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ObjBlockRef.Delete<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; sset.Delete<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '删除块定义<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Blocks.Item("椅子").Delete<br/>End Sub</p><p></p>

huangbinlq 发表于 2007-8-14 17:34:00

<p>不对啊,始终是选择了所有对象啊,没起到过滤的作用啊朋友们</p><p>Sub DeleteBlock()<br/>&nbsp;&nbsp;&nbsp; Dim ObjBlockRef As AcadBlockReference<br/>&nbsp;&nbsp;&nbsp; Dim FilterType(0) As Integer, FilterData(0) As Variant<br/>&nbsp;&nbsp;&nbsp; Dim sset As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '选中名为"椅子"的块参照并删除<br/>&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Add("test")<br/>&nbsp;&nbsp;&nbsp; FilterType(0) = 2<br/>&nbsp;&nbsp;&nbsp; FilterData(0) = "椅子"<br/>&nbsp;&nbsp;&nbsp; sset.Select acSelectionSetAll, , , FilterType, FilterData<br/>&nbsp;&nbsp;&nbsp; For Each ObjBlockRef In sset<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ObjBlockRef.Delete<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; sset.Delete<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '删除块定义<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Blocks.Item("椅子").Delete<br/>End Sub</p><p>不对啊,始终是选择了所有对象啊,没起到过滤的作用啊朋友们</p>

gyl 发表于 2007-8-14 18:23:00

<p>在我的机器上试验过,只删除了名为“椅子”的块参照及块定义。</p><p>你可以调试一下,检查 sset.Select acSelectionSetAll, , , FilterType, FilterData 执行之后sset中有哪些图元。</p><p>实在不行,把过滤器搞复杂一些,多设几个条件,比如增加图层之类。</p><p>没有图形文件,我也没有办法帮你更多的忙。</p>

huangbinlq 发表于 2007-8-14 22:46:00

<p>呵呵,是我错了,其实楼上朋友的代码是完全正确的,我刚复制到acad中去运行了的;只是我不会vba,其实我正在用vc自动化autocad! 选择集的过滤vba代码是sset.Select acSelectionSetAll, , , FilterType, FilterData&nbsp;&nbsp; 翻译成vc就是sel-&gt;Select(acSelectionSetAll,fitertype,fiterdata);同样的函数,同样的参数,vba的完全成功,vc的这句就只能全部选择对象而没得到过滤效果;我已经试过无数次了都是这样,好晕啊!哪位朋友能帮我啊?!</p>

guoxianlun 发表于 2008-4-17 17:55:00

高手们:使用了剪贴板板粘贴块后,指定的块定义删除不了,有没有解决办法?

windandr 发表于 2008-4-18 10:02:00

<p>遍历空间所有图形 </p><p>IF图形是块对象</p><p>&nbsp; IF块对象的名字是"椅子"</p><p>&nbsp;&nbsp;&nbsp;&nbsp; 删除块对象</p><p>&nbsp; END IF</p><p>END IF</p>
页: [1] 2
查看完整版本: 如何删除图块对象