Jump to content

Select block in Autocad and read attribute(VBA)


ZORANCRO

Recommended Posts

:) My problem is how to select Acadblock in modelspace and read en attribute in him. I have meny block with attribute, one attribute is text who preseant Z coordinate(Z coordinate = 0,00). I wont to change Z coordinate of Acadblock with val (attribute text).Help me!

 

Brian thank you! I want to select global set of block.

Link to comment
Share on other sites

  • 2 weeks later...
:) My problem is how to select Acadblock in modelspace and read en attribute in him. I have meny block with attribute, one attribute is text who preseant Z coordinate(Z coordinate = 0,00). I wont to change Z coordinate of Acadblock with val (attribute text).Help me!

 

Are you wanting to select a single block or a global set of blocks?

 

Brian

Link to comment
Share on other sites

You can try this. It worked for selecting a single block and then changing the value of the attribute with the tag of "Z".

 

I hope this helps you on your way.

 

Brian

 

Private Sub Change_it()
   Dim obj As AcadBlockReference
   Dim inspt As Variant

   ThisDrawing.Utility.GetEntity obj, inspt, "Select object:"

   ' Checks if you selected a block.
   If obj.ObjectName = "AcDbBlockReference" Then

       ' Check for attributes.
       If obj.HasAttributes Then

           Dim AttList As Variant

           ' Build a list of attributes for the current block.
           AttList = obj.GetAttributes

           ' Cycle throught the list of attributes.
           For I = LBound(AttList) To UBound(AttList)

               ' Check for the correct attribute tag.
               If AttList(I).TagString = "Z" Then

                   Dim InputString As String

                   ' Get the new value for the attribute.
                   InputString = ThisDrawing.Utility.GetString(True, "New value for z: ")

                   ' Set the new value for the attribute.
                   AttList(I).TextString = InputString

               End If

           Next

       End If

   Else
       MsgBox "You did not select a block."
   End If
End Sub

Link to comment
Share on other sites

Are you wanting to select a single block or a global set of blocks?

 

Brian

 

 

 

 

Brian thank you! I whant to select global set of block.

 

Zoran

Link to comment
Share on other sites

Here is another version of the same thing pick a block and then update the attributes

 

Public Sub ModifyLabelSTNcoords()
' adds x and y co ords of picked point to labelstn block

Dim objENT As AcadEntity

Dim pt1 As Variant
Dim attribs As Variant

On Error Resume Next
ThisDrawing.Utility.GetEntity objENT, basepnt, "pick Label stn block : "
         attribs = objENT.GetAttributes


pt1 = ThisDrawing.Utility.GetPoint(, " pick stn point")

txtx1 = "E " + CStr(FormatNumber(pt1(0), 3))
TXTY1 = "N " + CStr(FormatNumber(pt1(1), 3))
TXTz1 = "RL " + CStr(FormatNumber(pt1(2), 3))

attribs(2).TextString = txtx1
attribs(2).Update

attribs(3).TextString = TXTY1
attribs(3).Update
attribs(4).TextString = TXTz1
attribs(4).Update

End Sub

Edited by SLW210
Code Tags!!!!!!!!!!
Link to comment
Share on other sites

  • 4 months later...
  • 4 years later...
You can try this. It worked for selecting a single block and then changing the value of the attribute with the tag of "Z".

 

I hope this helps you on your way.

 

Brian

 

Private Sub Change_it()
   Dim obj As AcadBlockReference
   Dim inspt As Variant

   ThisDrawing.Utility.GetEntity obj, inspt, "Select object:"

   ' Checks if you selected a block.
   If obj.ObjectName = "AcDbBlockReference" Then

       ' Check for attributes.
       If obj.HasAttributes Then

           Dim AttList As Variant

           ' Build a list of attributes for the current block.
           AttList = obj.GetAttributes

           ' Cycle throught the list of attributes.
           For I = LBound(AttList) To UBound(AttList)

               ' Check for the correct attribute tag.
               If AttList(I).TagString = "Z" Then

                   Dim InputString As String

                   ' Get the new value for the attribute.
                   InputString = ThisDrawing.Utility.GetString(True, "New value for z: ")

                   ' Set the new value for the attribute.
                   AttList(I).TextString = InputString

               End If

           Next

       End If

   Else
       MsgBox "You did not select a block."
   End If
End Sub

 

 

Can you post the code changes to select a group of blocks?

 

thx

Link to comment
Share on other sites

MONIZ If your happy with pick pick pick then just add loop at start of code above and repeat. Some like For J =50.... next look at code above. A smarter way is also check for object picked nil = exit replace the Else Msgbox with J=50

 

Selecting multiple blocks can be done depending on how you intend to select "entities" "W" "C" 1 at a time etc Problem with multiple blocks do they all have same Z ? It would be complicated to select a whole lot at once then somehow jump to each one so you can put the correct Z in.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...