Jump to content

Rename a block with VBA


macchi

Recommended Posts

I want to rename a block with VBA.

I need to rename a titleblock with attributes (e.g. A1 or A2 or A3 to VX_TITLE).

 

I don't want to use:

ThisDrawing.SendCommand "_-rename" & vbCr & "b" & vbCr & "A1" & vbCr & "VX_TITLE" & vbCr

 

Who can help me?

Link to comment
Share on other sites

sounds much the same here. I can get to within about 2km of my work on main roads - no problem. BUT the final bit is up a single track lane. I don't want to drive an hour to there and then find I can't get in so I still don't know if I'll try today or not.

Link to comment
Share on other sites

OK, this is what I did...

gpCode(0) = 0 'item
gpCode(1) = 2 '?
groupCode = gpCode
dataValue(0) = "INSERT" 'item type
dataValue(1) = "STL*" '?
dataCode = dataValue
Set mySelSet = ThisDrawing.SelectionSets.Add("Blocks")
mySelSet.Select acSelectionSetAll, , , groupCode, dataCode
For Each myItem In mySelSet
If UCase(Left$(myItem.Name, 5)) = "STLA1" Then BlockName = "H:\Design_Office\E343\Blanks\E343T-A1.dwg"
If UCase(Left$(myItem.Name, 5)) = "STLA2" Then BlockName = "H:\Design_Office\E343\Blanks\E343T-A2.dwg"
If UCase(Left$(myItem.Name, 5)) = "STLA3" Then BlockName = "H:\Design_Office\E343\Blanks\E343T-A3.dwg"
If BlockName <> "" Then
   Set x = ThisDrawing.ModelSpace.InsertBlock(BlockPos, BlockName, objScale, objScale, objScale, 0)
   x.Delete
   myItem.Name = BlockName
   BlockName = ""
   End If
Next myItem

all our drawings should have a drawing frame called STL* so I create a selection set of all the block instances just in case somebody has more than one frame inserted. There SHOULD only be one though!

 

I then decide what the new name is going to be based on what is already in the drawing. I then create an instance of the block to be inserted. Note that I don't insert it into the drawing, just prepare it.

 

and finally I get to the line where I rename the existing block! I would think you should be able to do the selection set and then rename it. Give it a try!

Link to comment
Share on other sites

ok, you gave me an idea to solve my problem.

The title block needs to be the same name: VX_TITLE, whether it is a A0, A1, A2, A3 or A4. Other applications look for a title block called VX_TITLE and uses its attributes.

I'm thinking about creating different directories named \A0, \A1, etc.

Then using code like yours and change BlockName to e.g. "c:\A0\VX_TITLE.dwg", "c:\A1\VX_TITLE.dwg", etc. Off course in each dir it's a different title block.

I try to test it this weekend.

 

There must me a easier way. At the command prompt it's so simple (-rename)

Isn't there a simple method or whatever in vba?

 

Thanks,

Marco

Link to comment
Share on other sites

there may well be a simpler way, I stumbled upon my way when I was working out how to replace the existing block with a new (renamed) definition so it worked for me. Keep us posted with your progress as I am sure I will need something similar soon.

 

For what I was doing, my way actually saved me a couple of expected steps so I was pleased! :)

 

Still snowing over there? We have had a small fall overnight and a few flakes this morning but nothing of significance. More is expected tonight though.

Link to comment
Share on other sites

Found it!

 

 
Dim objBlock As AcadBlock
For Each objBlock In ThisDrawing.Blocks
  objBlock.Name = Replace(objBlock.Name, "A3", "VX_TITLE")
Next

 

In the south its snowing, here it's still dry. The kids have a lot off fun with ice skating now.

 

 

Marco

Link to comment
Share on other sites

Thanks,

They skate on rinks, small canals, lakes in forest and on the edges od greater lakes. But the ice is not so good because of the snow.

Have a nice weekend.

 

Marco

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