macchi Posted January 7, 2010 Share Posted January 7, 2010 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? Quote Link to comment Share on other sites More sharing options...
dbroada Posted January 7, 2010 Share Posted January 7, 2010 I've done this recently but I'm home right now with bad weather. If nobody comes along before the snow melts I'll check how I did it. Quote Link to comment Share on other sites More sharing options...
macchi Posted January 8, 2010 Author Share Posted January 8, 2010 OK, thanx. Tomorrow, they expect a lot off snow here (Kampen, Netherlands) also and they are running out of salt..... Quote Link to comment Share on other sites More sharing options...
dbroada Posted January 8, 2010 Share Posted January 8, 2010 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. Quote Link to comment Share on other sites More sharing options...
dbroada Posted January 8, 2010 Share Posted January 8, 2010 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! Quote Link to comment Share on other sites More sharing options...
macchi Posted January 8, 2010 Author Share Posted January 8, 2010 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 Quote Link to comment Share on other sites More sharing options...
dbroada Posted January 9, 2010 Share Posted January 9, 2010 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. Quote Link to comment Share on other sites More sharing options...
macchi Posted January 9, 2010 Author Share Posted January 9, 2010 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 Quote Link to comment Share on other sites More sharing options...
dbroada Posted January 9, 2010 Share Posted January 9, 2010 well done I'll see if I can remember it when I need to. Ice skating on lakes or rinks? Quote Link to comment Share on other sites More sharing options...
macchi Posted January 9, 2010 Author Share Posted January 9, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.