有关块属性的读取
再次麻烦版主了,lzh741206知道块名:a;块属性标记:如图号的属性标记值为:th;
如何快速找到这个块,并把图号的属性标记值为th的文字内容读出来,我用vb6.0,引用object cad 2004库,请列出源代码,谢谢!
回复
依据块名作选择集; 然后用下面方法得到属性:' Get the attributes for the block reference<BR> Dim varAttributes As Variant<BR> varAttributes = blockRefObj.GetAttributes<BR> <BR> Dim strAttributes As String<BR> Dim I As Integer<BR> For I = LBound(varAttributes) To UBound(varAttributes)<BR> strAttributes = strAttributes & " Tag: " & varAttributes(I).<FONT color=#0938f7>TagString</FONT> & _<BR> " Value: " & varAttributes(I).<FONT color=#f79709>textString</FONT> & " "<BR> Next<BR> 依据块名作选择集,怎么做,谢谢 (entget(car(entsel)))
命令行键入,选择一个块看看结果
回复
作选择集:Public Sub test()<BR> ' Create the selection set<BR> Dim ssetObj As AcadSelectionSet<BR> Set ssetObj = ThisDrawing.SelectionSets.Add("SSET")
Dim mode As Integer
mode = acSelectionSetAll
<BR> ' Add all the Circles to the selection set that lie within the crossing of (28,17,0) and<BR> ' (-3.3, -3.6,0) by filtering from the current drawing<BR> Dim gpCode(0 To 1) As Integer<BR> Dim dataValue(0 To 1) As Variant<BR> gpCode(0) = 0<BR> dataValue(0) = "Insert"<BR> gpCode(1) = 2<BR> dataValue(1) = "a" '块名<BR> <BR> Dim groupCode As Variant, dataCode As Variant<BR> groupCode = gpCode<BR> dataCode = dataValue<BR> <BR> ssetObj.Select mode, , , groupCode, dataCode
MsgBox ssetObj.Count<BR>
'然后你循环ssetObj中的每个块实体...
<BR>End Sub 这样吧:
Sub test()<BR> Dim blks As AcadBlocks<BR> Dim blk As AcadBlock<BR> <BR> Set blks = ThisDrawing.Blocks<BR> <BR> Set blk = blks.Item("a")<BR> <BR> Dim i As Integer<BR> <BR> For i = 0 To blk.Count - 1<BR> Dim obj As AcadObject<BR> Set obj = blk.Item(i)<BR> Dim str As String<BR> str = obj.ObjectName<BR> If obj.ObjectName = "AcDbAttributeDefinition" Then<BR> Dim attrObj As AcadAttribute<BR> Set attrObj = obj<BR> Dim tag, prompt, value As String<BR> tag = attrObj.TagString<BR> prompt = attrObj.PromptString<BR> value = attrObj.TextString<BR> MsgBox "Tag: " & tag & vbCr & "Value: " & value & vbCr & "Value: " & value & vbCr<BR> End If<BR> Next<BR> <BR>End Sub
测试dwg:
<DIV><FONT size=2><A name=59541><FONT color=#990000><B>王咣生</B></FONT></A>版主:</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>我能看到你的dwgtext的内容,但运行程序就是看不到我的图框里的内容,百思不得其解,麻烦你看看是怎么回事,比如我想看块tbz00的drawno标记的属性文字,总为空,读drawno这个tagstring倒是可以读到。</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>dwg图已发到你的邮箱里了,谢谢</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV> </DIV>
页:
[1]