renaming blocks

Discussion in 'AutoCAD' started by jlw-, May 20, 2004.

  1. jlw-

    jlw- Guest

    I'm trying to rename some specific blocks, it appears to be in a cont. loop though. Can anyone help.

    (defun rename ()
    (setvar "cmdecho" 0)
    (setq nextblock (tblnext "block" T))
    (setq blocklist (list "CWSURF" "WSURF" "CHAIR"))
    (setq blocknew ( list "CWSURF_OLD" "WSURF_OLD" "CHAIR_OLD"))
    (while nextblock
    (setq nameofblock (cdr (assoc 2 nextblock)))
    (if (member nameofblock blocklist)
    (progn
    (setq newnameofblock (strcat nameofblock "_old"))
    (if (/= nextblock blocknew)
    (command ".rename" "b" nameofblock newnameofblock)
    (setq nextblock (tblnext "block"))
    )
    )
    )
    )
    )
    ;
     
    jlw-, May 20, 2004
    #1
  2. jlw-

    Jeff Mishler Guest

    try this out....
    Jeff

    (defun rename (/ nextblock blocklist blocknew nameofblock newnameofblock)
    ;(setvar "cmdecho" 0) ; shouldn't change this without setting it back
    (setq nextblock (tblnext "block" T))
    (setq blocklist (list "CWSURF" "WSURF" "CHAIR"))
    (while nextblock
    (setq nameofblock (cdr (assoc 2 nextblock)))
    (if (member nameofblock blocklist)
    (progn
    (setq newnameofblock (strcat nameofblock "_old"))
    (command ".rename" "b" nameofblock newnameofblock)
    )
    )
    (setq nextblock (tblnext "block"))
    )
    (princ)
    )
     
    Jeff Mishler, May 20, 2004
    #2
  3. jlw-

    jlw- Guest

    Thanks.

    I get a error:

    ; error: bad argument type: stringp nil
     
    jlw-, May 20, 2004
    #3
  4. jlw-

    Jeff Mishler Guest

    Hmm, not sure why as it works fine here.
    But here's a different one to try:

    (defun rename2 ()
    (vl-load-com)
    (vlax-for blk (vla-get-blocks
    (vla-get-activedocument
    (vlax-get-acad-object)))
    (if (wcmatch (vla-get-name blk) "CWSURF,WSURF,CHAIR")
    (vla-put-name blk (strcat (vla-get-name blk) "_old"))
    )
    )
    (princ)
    )

    Jeff
     
    Jeff Mishler, May 20, 2004
    #4
  5. jlw-

    ECCAD Guest

    In original code:
    (if (/= nextblock blocknew)
    (command ".rename" "b" nameofblock newnameofblock)
    (setq nextblock (tblnext "block"))
    .........
    only increments to next block (tblnext)..when if fails..
    should increment all the time. Try:
    (if (/= nextblock blocknew)
    (command ".rename" "b" nameofblock newnameofblock))
    (setq nextblock (tblnext "block")
    ......... instead

    Bob
     
    ECCAD, May 20, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.