[求助]新手请教vba查询或得到图元
<p>想做个判断 比如 图纸中已经有 某某块 或者某某图层 就运行a命令 没有就运行 b。</p><p> </p>
<p>想知道如何判断某个图层是否存在 或者得到固定名称块的数量。</p>
<p> </p>
<p>请高手赐教啊~</p>
抄了一段autocad的帮助文件
<div class="browse"><a href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202010\help\acad_aag.chm::/WSfacf1429558a55de2ab0a1008e4bf960-7c6d.htm">创建和编辑 AutoCAD 图元</a> > <a href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202010\help\acad_aag.chm::/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6bcb.htm">使用图层、颜色和线型</a> > <a href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202010\help\acad_aag.chm::/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6bca.htm"> 使用图层</a> > </div><div class="collapseexpand">
<table class="head-text_table" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<div class="head-text"><a name="WS6fc6134053f28d3c100ab23ffb2eb5c46-7fc8"></a>图层和线型排序</div></td>
<td width="100" align="middle">
<div id="expandAllSection" class="collapseexpandAllSection"> </div>
<div id="collapseAllSection" class="collapseexpandAllSection"> </div></td></tr></tbody></table></div><a name="WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6bc9"></a><!--Body-->
<p><a name="WSfacf1429558a55dec759ddffb0eba947-6241"></a>用户可以遍历 Layers 和 Linetypes 集合来查找图形中的所有图层和线型。</p>
<div class="section"><a name="WSfacf1429558a55dec759ddffb0eba947-646c"></a>
<p class="section_title_h1"><a name="TOC_ENTRY__d0e9126"></a><a name="WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6bc8"></a>遍历 Layers 集合</p>
<p><a name="WSfacf1429558a55dec759ddffb0eba947-6240"></a>以下代码遍历 Layers 集合,以合并图形中所有图层的名称,然后将这些名称显示在消息框中。</p>
<div class="codeBlock"><pre class="codeLine">Sub Ch4_IteratingLayers()</pre><pre class="codeLine"> Dim layerNames As String</pre><pre class="codeLine"> Dim entry As AcadLayer</pre><pre class="codeLine"> layerNames = ""</pre><pre class="codeLine"> For Each entry In ThisDrawing.Layers</pre><pre class="codeLine"> layerNames = layerNames + entry.Name + vbCrLf</pre><pre class="codeLine"> Next</pre><pre class="codeLine"> MsgBox "The layers in this drawing are: " + _</pre><pre class="codeLine"> vbCrLf + layerNames</pre><pre class="codeLine">End Sub</pre></div></div> <p>好的 谢楼上 不知有没有和 lisp里面一样 类似 tblsearch 的功能 直接输入图层名称查询地。。。。</p> 我想查询出一个CAD图纸中的所有圆的圆心坐标和半径 <p>这个,也引用一段啊</p>
<p> </p>
<div class="section"><a name="WSfacf1429558a55dec759ddffb0eba947-6485"></a>
<p class="section_title_h1"><a name="TOC_ENTRY__d0e5987"></a><a name="WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6c14"></a>为选择集指定单一选择条件</p>
<p><a name="WSfacf1429558a55dec759ddffb0eba947-6385"></a>以下代码提示用户选择要包含在选择集中的对象,但仅当选择的对象是 Circle 时才将其添加到选择集中:</p>
<div class="codeBlock"><pre class="codeLine">Sub Ch4_FilterMtext()</pre><pre class="codeLine"> Dim sstext As AcadSelectionSet</pre><pre class="codeLine"> Dim FilterType(0) As Integer</pre><pre class="codeLine"> Dim FilterData(0) As Variant</pre><pre class="codeLine"> Set sstext = ThisDrawing.SelectionSets.Add("SS2")</pre><pre class="codeLine"> FilterType(0) = 0</pre><pre class="codeLine"> FilterData(0) = "Circle"</pre><pre class="codeLine"> sstext.SelectOnScreen FilterType, FilterData</pre><pre class="codeLine">End Sub</pre></div></div> 看看,学习了 如何判断某个图层是否存在?
用错误机制
on error resume next
set lay = thisdrawing.Layers("01")
if err then
页:
[1]