Jump to content

VBA - Insert blocks made of blocks with attributes, explode, then edit Attributes


Munters

Recommended Posts

I have a drawing my company wants me to automate. I'm using AutoCAD Electrical 2017, and have created some blocks containing 2 or three blocks with attributes. I have created several forms to get information from the user, that will determine which blocks to insert in the drawing at pre-determined insertion points. My plan was after the user has put the information in, they hit a command button and the automation starts. When inserting the blocks, I was planning to use the asterisk to insert the block exploded, then use VBA code to change one or two attributes ("TAG1" and "DESC1") to an also pre-determined value.

 

So in a nutshell, I'm trying to gather info, insert blocks, change attribute values, and also change a line of text or two elsewhere in the drawing. Note, the blocks I will be editing values are provided with AutoCAD Electrical, so I can have 11 of the same blocks on a drawing, and all will have different tag (TAG1) names. I do have a list of the x-y coordinates of the insertion points if that helps to select the correct block.

 

Thanks in advance!

Link to comment
Share on other sites

This is a bit of code in VBA it uses the method of retrieving the attributes in saved order then updating, the example is pick a point and write X & Y to the block. Try changing the "Textstring" to "Tagstring"

Set SS = ThisDrawing.SelectionSets.Add("pit1sel")
SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal

For Cntr = 0 To SS.Count - 1
If SS.Item(Cntr).Name = Blkname Then
 
  attribs = SS.Item(Cntr).GetAttributes
       
    If attribs(0).TextString = pitname Then
      pt1 = ThisDrawing.Utility.GetPoint(, " pick first point")
      txtx1 = CStr(FormatNumber(pt1(0), 3))
      TXTY1 = CStr(FormatNumber(pt1(1), 3))
       attribs(1).TextString = txtx1
       attribs(2).TextString = TXTY1
      
       attribs(1).Update
       attribs(2).Update

       Cntr = SS.Count
    
    Else: End If
     
Else: End If

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...