Insert a block and set attributes using VBA

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am inserting a user selected block into a drawing, and exploding it to expose the nested blocks for editing. But I would like to set some of the attributes so the user does not have to edit them manually. I am using AutoCAD Electrical 2017 and inserting a block that contains 4 AutoCAD Electrical Blocks and I would like to change "Tag1" and 3 of them and "Tag2" on one. This is what I have so far to insert the user selected block:
'Insert 1st object @ 5870,230
Object1 = "1-" + Object1 'This is adding some text to the existing block selected as it get put into the first column
insertionPnt(0) = 5870: insertionPnt(1) = 230: insertionPnt(2) = 0
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, Object1, 1#, 1#, 1#, 0)
blockRefObj.Explode
blockRefObj.Delete 'I had to add this as I found this is leaving the first block "unexploded"
Everything is working as it should currently. I need to edit the attributes of (AutoCAD Electrical Made Blocks) "VMS1_002" Tag1, "VMS21P" Tag2, "VW01_5" Tag1, and "VMO14" Tag1. What this block contains is a three phase connection of a circuit containing a MMP, Contactor, Cable tag, and the motor. These tags change depending on what page (page 15) and what column. 15.1 means "VMS1_002" Tag1 will end up being MMP151, "VMS21P" Tag2 will be CON151, "VW01_5" Tag1 will be C151, and "VMO14 Tag1 will be M151. I put 5 of these circuit per page (So you will have 151, 153, 155, 156 & 158 on page 15) I am using IEC symbols and standards. While we do not use the database for BOMs like most do, you can presume this is not AutoCAD Electrical, just AutoCAD. While I could just insert plain text where I need it, I would rather edit the attributes.
Thanks so much in advance!