See the top rated post in this thread. Click here

Results 1 to 8 of 8

Thread: Removing unwanted blocks and renaming blocks.

  1. #1
    Member
    Join Date
    2016-09
    Posts
    2
    Login to Give a bone
    0

    Default Removing unwanted blocks and renaming blocks.

    Hi,
    Very new to programming but need to achieve the following in Autocad 2014.

    In brief, I use a scaffolding software that produces a lot of unwanted blocks, and its naming convention isn't good.

    I need a script or routine to remove a load of unwanted blocks (so select all blocks definitions with that name and delete, dont care about the block definition itself, just all instances of it in the drawing)

    _deck_end
    _donut
    _donutt6

    etc....

    and then to rename a load of block definitions so they can be exported into another software program.

    _Deck_0 to Boards
    _Deck_Toe to Kicks
    _hop_7 to 2BHU

    etc....

    If possible, I could also do with renaming certain blocks that would be selected by name & also by the value in the geometry, scale X properties value.. That one might be tricky I know..

    Any help would be amazing, either by example code or a pointer to a similar routine so I can try and reverse engineer it and modify to suit my needs..

    Thanks

    Tony

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Removing unwanted blocks and renaming blocks.

    This should do the trick:
    Code:
    (defun c:blkDelRen ( / ss count)
    	(setq ss (ssget "X" '((0 . "INSERT")(2 . "_deck_end,_donut,_donutt6")))
    	      count (1- (sslength ss))
    	)
    	(while (> count 0) 
    		(princ (ssname ss count))
    		(entdel (ssname ss count))
    		(setq count(1- count))
    	)
    	(command "-rename" "_Deck_0" "Boards")
    	(command "-rename" "_Deck_Toe" "Kicks")
    	(command "-rename" "_hop_7" "2BHU")
    )
    After loading run the blkDelRen command.

  3. #3
    Member
    Join Date
    2016-09
    Posts
    2
    Login to Give a bone
    0

    Default Re: Removing unwanted blocks and renaming blocks.

    Brilliant...

    Thank you so much Tom..

  4. #4
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Removing unwanted blocks and renaming blocks.

    Quote Originally Posted by Tony_9D View Post
    Brilliant...

    Thank you so much Tom..
    Whenever you go to a more current version you will need to change those "command" calls to "command-s" as that was recent change. Glad it worked for you. Hope you enjoy the AUGI Forum, it's been quite valuable for me over the years.

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    1

    Default Re: Removing unwanted blocks and renaming blocks.

    i almost exclusively us vl-cmf instead of command or command-s. vl-cmdf returns T for success and nil for faliure. P=

  6. #6
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Removing unwanted blocks and renaming blocks.

    Quote Originally Posted by peter View Post
    i almost exclusively us vl-cmf instead of command or command-s. vl-cmdf returns T for success and nil for faliure. P=
    It would have been a better choice for this code as it's been around for some time vl-cmdf would work in his and future versions.

    AutoCAD's help compares both vl-cmdf and command-s to command, but not each other. Command-s returns nil or error. I've been using the newer command-s lately, but bow to your expertice in error handling.

  7. #7
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    0

    Default Re: Removing unwanted blocks and renaming blocks.

    Tom a couple of suggestions, once you have the selection set ss why not just delete it ? Rather than delete each entity.

    A repeat could be used to do the rename using a slightly different list
    Code:
    (setq x 0)
    (setq lst ("_Deck_0" "Boards" _Deck_Toe" "Kicks" "_hop_7" "2BHU"))
    (repeat (length (/ lst 2)) 
    (command-s "rename" (nth x lst) (nth (+ x 1)) lst)
    (setq x (+ x 2))
    )

  8. #8
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Removing unwanted blocks and renaming blocks.

    Quote Originally Posted by BIG-AL View Post
    Tom a couple of suggestions, once you have the selection set ss why not just delete it ? Rather than delete each entity.
    I could have used
    Code:
    (sssetfirst nil ss)(command-s "erase")
    or ronjonp's code https://www.theswamp.org/index.php?t...3255#msg503255
    Code:
    (mapcar '(lambda (e) (vla-delete (vlax-ename->vla-object e))) (mapcar 'cadr (ssnamex ss)))

Similar Threads

  1. renaming blocks
    By d_m_hopper in forum AutoLISP
    Replies: 16
    Last Post: 2010-06-21, 04:24 AM
  2. Renaming blocks
    By csorensen in forum CAD Management - General
    Replies: 12
    Last Post: 2008-03-05, 09:14 PM
  3. Renaming *U-Blocks :
    By jfoster.72059 in forum ACA General
    Replies: 7
    Last Post: 2005-10-25, 04:59 PM
  4. Renaming Blocks
    By BCrouse in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2004-07-15, 03:48 PM

Posting Permissions

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