Results 1 to 8 of 8

Thread: Multiple block Rename

  1. #1
    All AUGI, all the time BCrouse's Avatar
    Join Date
    2003-04
    Location
    Bethlehem, PA
    Posts
    980
    Login to Give a bone
    0

    Default Multiple block Rename

    Does anyone know of of lisp that would allow you to find and replace blocks names? Right when you want to rename a block you use the rename command to do that. This idea would allow you to find all blocks that has similar namse and replaces it with something different.

    Example: you have 10 blocks with BK in the name. Now you want to change the names of the 10 blocks that has BK in it to CG.

    Thank you,

    brad

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Multiple block Rename

    Give this vba code a shot.

    Code:
    Sub foo()
    Dim item As AcadBlock
    For Each item In ThisDrawing.Blocks
        item.Name = Replace(item.Name, "BK", "CG")
    Next item
    End Sub
    R.K. McSwain | CAD Panacea |

  3. #3
    All AUGI, all the time BCrouse's Avatar
    Join Date
    2003-04
    Location
    Bethlehem, PA
    Posts
    980
    Login to Give a bone
    0

    Default Re: Multiple block Rename

    Quote Originally Posted by rkmcswain
    Give this vba code a shot.

    Code:
    Sub foo()
    Dim item As AcadBlock
    For Each item In ThisDrawing.Blocks
    item.Name = Replace(item.Name, "BK", "CG")
    Next item
    End Sub
    What is the command to invoke it?

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Multiple block Rename

    Use the VBARUN command to open the Macros Dialog Box to select FOO.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Multiple block Rename

    Quote Originally Posted by BCrouse
    What is the command to invoke it?
    In it's present form, "foo". But that was just provided as a sample. Rename as desired.

    There are a couple of methods to run this.

    1) Type in VBAMAN, create a new project, highlight that project and click the "Visual Basic Editor" button. Find that project in the Project Pane in the VBA editor, double click on "ThisDrawing". Paste the code in the edit box. Put your cursor somewhere in the code, and press F5. Done. (this doesn't save anything - one time use)

    2). Repeat above, except click the save button, and save this code to a DVB file. In the future, use VBAMAN to load the DVB file, and VBARUN to run this code.

    3) Many other ways to do things such as "autoload" this routine, run from a command line shortcut, run from a toolbar button, etc. Let me know your ultimate intentions.
    R.K. McSwain | CAD Panacea |

  6. #6
    All AUGI, all the time BCrouse's Avatar
    Join Date
    2003-04
    Location
    Bethlehem, PA
    Posts
    980
    Login to Give a bone
    0

    Thumbs up Re: Multiple block Rename

    Quote Originally Posted by rkmcswain
    In it's present form, "foo". But that was just provided as a sample. Rename as desired.

    There are a couple of methods to run this.

    1) Type in VBAMAN, create a new project, highlight that project and click the "Visual Basic Editor" button. Find that project in the Project Pane in the VBA editor, double click on "ThisDrawing". Paste the code in the edit box. Put your cursor somewhere in the code, and press F5. Done. (this doesn't save anything - one time use)

    2). Repeat above, except click the save button, and save this code to a DVB file. In the future, use VBAMAN to load the DVB file, and VBARUN to run this code.

    3) Many other ways to do things such as "autoload" this routine, run from a command line shortcut, run from a toolbar button, etc. Let me know your ultimate intentions.
    I like item number #3.

    Thank you very much!

    Brad

  7. #7
    All AUGI, all the time
    Join Date
    2015-12
    Location
    Central Oregon
    Posts
    591
    Login to Give a bone
    0

    Default Re: Multiple block Rename

    Or, do the same thing in lisp.....
    Code:
    (defun c:foo ()
      (vlax-for blk (vla-get-blocks
    		  (vla-get-activedocument
    		    (vlax-get-acad-object)
    		    )
    		  )
        (if (vl-string-search "BK" (strcase (vla-get-name blk)))
          (vla-put-name blk (vl-string-subst "CG" "BK" (vla-get-name blk)))
          )
        )
      (princ)
      )
    But I suspect that this isn't really what Brad wants......this only renames the block definitions (and, by default, the Inserts, too). What I think he wants is to rename the Block References to be a different block.......correct?

  8. #8
    100 Club
    Join Date
    2004-12
    Posts
    153
    Login to Give a bone
    0

    Default Re: Multiple block Rename

    You know you can also use wildcards in the RENAME command. So if you wanted to change every block that started wtih W2, you can type in W2* and use it in the rename to box as well. It will highlight and change every block that starts with W2* to the new name.

Similar Threads

  1. Rename multiple blocks
    By knutsen in forum AutoLISP
    Replies: 4
    Last Post: 2012-09-06, 07:48 AM
  2. Replies: 6
    Last Post: 2012-08-15, 04:55 PM
  3. Rename block name
    By yazgunesi02 in forum AutoLISP
    Replies: 1
    Last Post: 2010-04-16, 09:57 PM
  4. Rename Layout tabs on multiple .dwg
    By Dave Lewis in forum AutoCAD General
    Replies: 3
    Last Post: 2008-03-19, 07:40 PM
  5. Rename multiple Xrefs in dwg
    By Steve_Bennett in forum AutoLISP
    Replies: 11
    Last Post: 2006-04-25, 12:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •