<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: access the objects in the block definition object in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8195540#M6448</link>
    <description>&lt;P&gt;You do not need to explode to find entities in a block definition (AcadBlock). Simply loop through the block definition to identiy the entity in the block definition. In your case, Assume, the block definition has a closed LwPolyline, which you need to know its area. So the code would be like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3913128"&gt;@jeremye86&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;        FilterData(0) = "INSERT"
        FilterType(0) = 0
        Set oSset = acadDoc.SelectionSets.Add("SS1")
        oSset.Select acSelectionSetAll, FilterType, FilterData
        rowperimsht = 1
        lngRow = 1&lt;BR /&gt;        &lt;BR /&gt;        &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Dim area As Double&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;
        For Each objInSelect In oSset
            On Error Resume Next
            effName = objInSelect.EffectiveName
            On Error GoTo 0
           
            If effName = "perimShtDyn" Then
                BlkAtts = objInSelect.GetAttributes
                PerimShtDimsArray(rowperimsht, 1) = BlkAtts(0).textString  ' pm name
                PerimShtDimsArray(rowperimsht, 2) = 1  'qty
                BlkAtts = objInSelect.GetDynamicBlockProperties
                PerimShtDimsArray(rowperimsht, 3) = Round(BlkAtts(0).Value, 3) 'radius
                PerimShtDimsArray(rowperimsht, 4) = Round(BlkAtts(2).Value, 3) 'left len
                PerimShtDimsArray(rowperimsht, 5) = Round(BlkAtts(4).Value, 3)  'right len
                PerimShtDimsArray(rowperimsht, 6) = Round(BlkAtts(6).Value, 3)  ' bottom len
                PerimShtDimsArray(rowperimsht, 7) = Round(BlkAtts(8).Value, 3)   'sht angle
                &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;area = GetArea(objInSelect.Name)&lt;/STRONG&gt;
                &lt;STRONG&gt;PerimShtDimsArray(rowperimsht, 8) = area&lt;/STRONG&gt;&lt;/FONT&gt;
                rowperimsht = rowperimsht + 1
            End If
            effName = ""
        Next objInSelect&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Private Function GetArea(blkName As String) As Double&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim area As Double&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim blk As AcadBlock&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim ent As AcadEntity&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim poly As AcadLWPolyline&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Set blk=ThisDrawing.Blocks(blkName)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; For Each ent In blk&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If TypeOf ent Is AcadLWPolyline Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set poly = ent&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; area = poly.Area&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Exit For&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; GetArea=area&lt;/P&gt;
&lt;P&gt;End Function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Aug 2018 13:49:35 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2018-08-13T13:49:35Z</dc:date>
    <item>
      <title>access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191725#M6444</link>
      <description>&lt;P&gt;how can i access the objects in the block definition object?&lt;/P&gt;&lt;P&gt;I have a book that says&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;set objentity=blockobject.item(index)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;set objentity=blockobject(index)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This does not work for me and the only way i could get it to work is to explode block as follows&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;blockObjects2 = objBlockRef.Explode&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Set &lt;SPAN&gt;objentity&lt;/SPAN&gt;= blockObjects2(0)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;How can i do this without exploding the block?&amp;nbsp; I just want to access the first item, thus the 0 for index.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 14:28:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191725#M6444</guid>
      <dc:creator>jeremye86</dc:creator>
      <dc:date>2018-08-10T14:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191791#M6445</link>
      <description>&lt;P&gt;Can you show all your code? What do you want to do? Are you trying to access the block definition or the reference?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 14:41:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191791#M6445</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2018-08-10T14:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191873#M6446</link>
      <description>&lt;PRE&gt;        FilterData(0) = "INSERT"
        FilterType(0) = 0
        Set oSset = acadDoc.SelectionSets.Add("SS1")
        oSset.Select acSelectionSetAll, FilterType, FilterData
        rowperimsht = 1
        lngRow = 1
        For Each objInSelect In oSset
            On Error Resume Next
            effName = objInSelect.EffectiveName
            On Error GoTo 0
           
            If effName = "perimShtDyn" Then
                BlkAtts = objInSelect.GetAttributes
                PerimShtDimsArray(rowperimsht, 1) = BlkAtts(0).textString  ' pm name
                PerimShtDimsArray(rowperimsht, 2) = 1  'qty
                BlkAtts = objInSelect.GetDynamicBlockProperties
                PerimShtDimsArray(rowperimsht, 3) = Round(BlkAtts(0).Value, 3) 'radius
                PerimShtDimsArray(rowperimsht, 4) = Round(BlkAtts(2).Value, 3) 'left len
                PerimShtDimsArray(rowperimsht, 5) = Round(BlkAtts(4).Value, 3)  'right len
                PerimShtDimsArray(rowperimsht, 6) = Round(BlkAtts(6).Value, 3)  ' bottom len
                PerimShtDimsArray(rowperimsht, 7) = Round(BlkAtts(8).Value, 3)   'sht angle
                blockObjects2 = objInSelect.Explode
                PerimShtDimsArray(rowperimsht, 8) = blockObjects2(0).Area
                rowperimsht = rowperimsht + 1
            End If
            effName = ""
        Next objInSelect&lt;/PRE&gt;&lt;P&gt;I'm trying to get the area of the polyline in the block.&amp;nbsp; The code above gets the area correctly but i don't want to the block exploded.&amp;nbsp; I attached the block in reply.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 15:07:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191873#M6446</guid>
      <dc:creator>jeremye86</dc:creator>
      <dc:date>2018-08-10T15:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191883#M6447</link>
      <description>&lt;P&gt;i believe i am accessing the reference&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 15:09:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8191883#M6447</guid>
      <dc:creator>jeremye86</dc:creator>
      <dc:date>2018-08-10T15:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8195540#M6448</link>
      <description>&lt;P&gt;You do not need to explode to find entities in a block definition (AcadBlock). Simply loop through the block definition to identiy the entity in the block definition. In your case, Assume, the block definition has a closed LwPolyline, which you need to know its area. So the code would be like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3913128"&gt;@jeremye86&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;        FilterData(0) = "INSERT"
        FilterType(0) = 0
        Set oSset = acadDoc.SelectionSets.Add("SS1")
        oSset.Select acSelectionSetAll, FilterType, FilterData
        rowperimsht = 1
        lngRow = 1&lt;BR /&gt;        &lt;BR /&gt;        &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Dim area As Double&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;
        For Each objInSelect In oSset
            On Error Resume Next
            effName = objInSelect.EffectiveName
            On Error GoTo 0
           
            If effName = "perimShtDyn" Then
                BlkAtts = objInSelect.GetAttributes
                PerimShtDimsArray(rowperimsht, 1) = BlkAtts(0).textString  ' pm name
                PerimShtDimsArray(rowperimsht, 2) = 1  'qty
                BlkAtts = objInSelect.GetDynamicBlockProperties
                PerimShtDimsArray(rowperimsht, 3) = Round(BlkAtts(0).Value, 3) 'radius
                PerimShtDimsArray(rowperimsht, 4) = Round(BlkAtts(2).Value, 3) 'left len
                PerimShtDimsArray(rowperimsht, 5) = Round(BlkAtts(4).Value, 3)  'right len
                PerimShtDimsArray(rowperimsht, 6) = Round(BlkAtts(6).Value, 3)  ' bottom len
                PerimShtDimsArray(rowperimsht, 7) = Round(BlkAtts(8).Value, 3)   'sht angle
                &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;area = GetArea(objInSelect.Name)&lt;/STRONG&gt;
                &lt;STRONG&gt;PerimShtDimsArray(rowperimsht, 8) = area&lt;/STRONG&gt;&lt;/FONT&gt;
                rowperimsht = rowperimsht + 1
            End If
            effName = ""
        Next objInSelect&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Private Function GetArea(blkName As String) As Double&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim area As Double&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim blk As AcadBlock&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim ent As AcadEntity&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Dim poly As AcadLWPolyline&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; Set blk=ThisDrawing.Blocks(blkName)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; For Each ent In blk&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If TypeOf ent Is AcadLWPolyline Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set poly = ent&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; area = poly.Area&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Exit For&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; End If&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; GetArea=area&lt;/P&gt;
&lt;P&gt;End Function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 13:49:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8195540#M6448</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2018-08-13T13:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8197043#M6449</link>
      <description>&lt;P&gt;&lt;SPAN&gt;thanks for the help but not working as well&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;error 438 (object doesnt support this property or method) with this line&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Set blk=ThisDrawing.Blocks(blkName)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 23:55:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8197043#M6449</guid>
      <dc:creator>jeremye86</dc:creator>
      <dc:date>2018-08-13T23:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8198527#M6450</link>
      <description>&lt;P&gt;Well,&amp;nbsp;not seeing all your code (and the drawing the code runs upon), I am not sure what is wrong. But to quickly prove my point, following code works perfectly with my AutoCAD 2018:&lt;/P&gt;
&lt;PRE&gt;Option Explicit

Public Sub GetArea()

    Dim ent As AcadEntity
    Dim pt As Variant
    Dim blkRef As AcadBlockReference
    
    ThisDrawing.Utility.GetEntity ent, pt, vbCr &amp;amp; "Select a block:"
    If Not ent Is Nothing Then
        If TypeOf ent Is AcadBlockReference Then
            Set blkRef = ent
            GetBlockArea blkRef
        Else
            MsgBox "Selected entity is not a block!"
        End If
    End If
    
End Sub

Private Sub GetBlockArea(blkRef As AcadBlockReference)
    
    Dim blkName As String
    Dim blk As AcadBlock
    Dim ent As AcadEntity
    Dim poly As AcadLWPolyline
    Dim area As Double
    
    blkName = blkRef.Name
    Set blk = ThisDrawing.Blocks(blkName)
    For Each ent In blk
        If TypeOf ent Is AcadLWPolyline Then
            Set poly = ent
            If poly.Closed Then
                area = poly.area
                Exit For
            End If
        End If
    Next
    
    If area &amp;gt; 0# Then
        MsgBox "Block Name" &amp;amp; vbTab &amp;amp; blkRef.Name &amp;amp; "(" &amp;amp; blkRef.EffectiveName &amp;amp; ")" &amp;amp; vbCrLf &amp;amp; _
        "Block Area: " &amp;amp; vbTab &amp;amp; area
    Else
        MsgBox "cannot find closed polyline in the selected block """ &amp;amp; blkName &amp;amp; """!"
    End If
    
End Sub&lt;/PRE&gt;
&lt;P&gt;The following video shows how the code works with 3 block references (of a dynamic block definition):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="iframe-container"&gt;&lt;IFRAME width="640" height="590" src="https://screencast.autodesk.com/Embed/Timeline/95274e66-6ff1-4310-aa0e-3064d6ae8dfe" frameborder="0" scrolling="no" allowfullscreen="allowfullscreen" webkitallowfullscreen="webkitallowfullscreen"&gt;&lt;/IFRAME&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 14:19:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8198527#M6450</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2018-08-14T14:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8198668#M6451</link>
      <description>&lt;P&gt;thanks Norman, i was able to get your code to work.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm going to do a speed test to see if your code or&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;exploding a block reference to get&amp;nbsp; the objects that define it is faster.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I found that i can just delete the exploded objects after getting the properties.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 14:59:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8198668#M6451</guid>
      <dc:creator>jeremye86</dc:creator>
      <dc:date>2018-08-14T14:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: access the objects in the block definition object</title>
      <link>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8204213#M6452</link>
      <description>&lt;P&gt;Norman,&lt;/P&gt;&lt;P&gt;I did a speed test and your method is almost 3 times faster &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;.&amp;nbsp; Also you helped me answer my original question.&amp;nbsp;&amp;nbsp;Instead of looping through all object in the block definition i was able to get&amp;nbsp;the first object by using 0 as index.&lt;/P&gt;&lt;P&gt;blkName = objInSelect.Name&lt;BR /&gt;Set blk = acadDoc.Blocks(blkName)&lt;BR /&gt;PerimShtDimsArray(rowperimsht, 8) = blk(0).area&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 14:31:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/access-the-objects-in-the-block-definition-object/m-p/8204213#M6452</guid>
      <dc:creator>jeremye86</dc:creator>
      <dc:date>2018-08-16T14:31:50Z</dc:date>
    </item>
  </channel>
</rss>

