Get Block Elements Properties Without Attributes

Get Block Elements Properties Without Attributes

Anonymous
Not applicable
793 Views
1 Reply
Message 1 of 2

Get Block Elements Properties Without Attributes

Anonymous
Not applicable

Hello,

I would like to know, if it is possible to access to a block, without attributes, to get a polyline length, for example.

If it’s a dynamic block, I know that I can access at those Properties (“AllowedValues”,”Description”,”PropertyName”,”ReadOnly”,”show”, UnitsType” and “Value”). But I was expecting it has a property like “Element” or “item” that gives me a list of elements inside the block, that I can access and get the information that I want.

Thanks in advance.

BestRegards

0 Likes
Accepted solutions (1)
794 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

The term "block" you used here is block reference (AcadBlockReference), which does not have "elements" in it (except for attributes -AcadAttributeReference), it is just a REFERENCE of a block definition (AcadBlock), or an "image" of a block definition being placed in Model/PaperSpace. To know the block elements' properties, you need to go to the block definition.

 

Following code shows how to do it, assume you let user to select a block (block reference);

 

Dim ent as AcadEntity

Dim pt As Variant

Dim blkRef As AcadBlockRefernece

Dim blkDef As AcadBlock

Dim blkName As String

 

Dim line As AcadLine

Dim circel As AcadCircle

...

ThisDrawing.Utility.GetEntity ent, pt, vbCr & "Select a Block:"

If TypeOf ent Is AcadBlockReference Then

  Set blkRef=ent

  blkName=blkRef.Name

  '' Get the block definition of selected block reference

  Set blkDef=ThisDrawing.Blocks(blkName)

  '' access each element in the block definition

  For Each ent in blkDef

    If TypeOf ent IsAcadLine Then

      Set line=ent

      Msgbox "Line in block: Length->" & line.Length

    ElseIf TypeOf ent Is AcadCircle Then

      Set circle=ent

      MsgBox "Circle in block: Radius=>" & circle.Radius

    ElseIf ....

      ... ...

    End If

  Next

End Id

 

 

Norman Yuan

Drive CAD With Code

EESignature