检查块是否存在..
您好,我如何检查某个块是否存在或插入到图形中,该图形可以位于任何布局或模型空间中,而无需在布局中循环检查
是否正在使用此Drawing.Blocks。项目(“”)?我真的想按名称检查一个名为“Fixing_Chart”的块
**** Hidden Message ***** 你可以做这样的事情:
Function BlockExists(ByRef blockName as String) as Boolean
Dim block as AcadBlock
On Error Resume Next
Set block = ThisDrawing.Blocks(blockName)
If Err = 0 then
BlockExists = True
Else
BlockExists = False
End If
Err.Clear
On Error Goto 0
Set block = Nothing
End Function
我通常不是内联错误处理的粉丝,但有时例外是必要的。 或者使用选择集
Set sset1 = ThisDrawing.SelectionSets.Add("SSbks")
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 2: FilterData(1) = "MyBlockName"
sset1.Select acSelectionSetAll, , , FilterType, FilterData
然后
检查选择集计数
如果sset1.count=0,则该块不存在
哎呀。 我想我没有仔细阅读。 我的只会告诉你块定义是否存在于块表中。
最初的请求要求“检查某个程序块是否存在”(您的程序块存在),或者“被插入到图形中”(hendie的程序块存在),所以我认为这个操作是包含在内的... 您好,
感谢你们两位的输入。
好的,用这两种方法之一,检查块是否存在,我如何检查属性值。现在我知道我只能在插入了块引用的情况下检查它们,所以我知道现在我可以检查块集合中是否存在块,但我需要检查的是是否插入了块,但不需要在所有布局中循环,我希望它几乎是即时的,因此当用户表单加载时,它检查插入的块并在表单上显示属性值。<br>我可以进行属性检查并填充表单,它只检查插入块,而不检查我不知道的每个布局。<br> 啊,对不起,当最后两篇帖子进来时,我正在输入,哈哈
嗨,
所以使用亨迪的代码:
Set sset1 = ThisDrawing.SelectionSets.Add("SSbks")
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 2: FilterData(1) = "MyBlockName"
sset1.Select acSelectionSetAll, , , FilterType, FilterData
…如何访问块,选择集中的对象处于什么状态?它是AcadEntity,还是AcadObject或AcadBlockReference,还是作为其他内容存储在选择集中。我现在想从这里访问属性,但为了检查它是否是正确的对象类型,我需要放置什么?/选择集中项目的变量名是什么 0 Then
Set BlockX = sset1.Item(0)
If BlockX.HasAttributes Then
attribX = BlockX.GetAttributes
For countz = LBound(attribX) To UBound(attribX)
Select Case attribX(countz).TagString
Case "FIX1"
fx1descTXT.text = attribX(countz).TextString
Case "FIX2"
fx2descTXT.text = attribX(countz).TextString
Case "FIX3"
fx3descTXT.text = attribX(countz).TextString
Case "FIX4"
fx4descTXT.text = attribX(countz).TextString
Case "FIX5"
fx5descTXT.text = attribX(countz).TextString
Case "FIX6"
fx6descTXT.text = attribX(countz).TextString
Case "FIX7"
fx7descTXT.text = attribX(countz).TextString
Case "FIX8"
fx8descTXT.text = attribX(countz).TextString
Case "FIX9"
fx9descTXT.text = attribX(countz).TextString
Case "FIX10"
fx10descTXT.text = attribX(countz).TextString
End Select
Next 'End countx HasAttributes check loop..
End If
End If
我希望这能把事情弄清楚 如果图形中有多个,则需要将设置的 BlockX 和属性代码放在 for-next 循环中。 为大家干杯,让它像梦一样工作。使用Hendie和Keith的代码的组合,它以我需要的方式工作,但是我总是有一件事与选择集,我摔倒了,永远不记得如何为它编码....
.....当我运行代码一次它很好,但第二次,它标记出选择集已经存在....现在,每个人检查集合是否存在的最佳方法和最简单的方法是什么。
我根本没有使用过选择集,最后一个是很久以前的,所以不记得我用过什么,但是,我敢肯定我只是用了sset1。删除,但我无法让它工作,或者也许我把它放在错误的地方。
页:
[1]
2