Author Topic: LISP to insert block and rename  (Read 1104 times)

0 Members and 1 Guest are viewing this topic.

like_citrus

  • Newt
  • Posts: 114
LISP to insert block and rename
« on: May 15, 2022, 10:51:06 PM »
Hi, is there a LISP anyone has to insert a block from another drawing and rename it with a suffix, to differentiate from the original block.
Something like Open, Select file, Paste, Rename with suffix.

mhupp

  • Bull Frog
  • Posts: 250
Re: LISP to insert block and rename
« Reply #1 on: May 16, 2022, 03:04:46 PM »
For importing blocks
http://www.lee-mac.com/steal.html

This is what i use to rename blocks.
Code - Auto/Visual Lisp: [Select]
  1. ;;----------------------------------------------------------------------------;;
  2. ;; Add Prefix/Suffix to Block Name
  3. (defun C:BLKRENAME (/ blklst SS blk lst c a n)
  4.   (vl-load-com)  
  5.   (prompt "\nSelect Block(s) or Enter To Rename All")
  6.   (if (or (setq ss (ssget '((0 . "INSERT")))) (setq ss (ssget "_X" '((0 . "INSERT")))))
  7.     (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  8.       (setq blk (cdr (assoc 2 (entget e))))  ;Get Block Name
  9.       (if (not (vl-position blk lst))        ;If Block Name is not in List Add
  10.         (setq lst (cons blk lst))
  11.       )
  12.     )
  13.   )
  14.   (setq c 0)        ;Count
  15.   (initget "Prefix Suffix")
  16.   (setq rep
  17.     (cond
  18.       ((getkword "\n Specify your aim [Prefix/Suffix] :")) ( "Suffix")
  19.     )
  20.   )
  21.   (cond
  22.     ((= rep "Prefix")
  23.       (setq prfx (getstring "\nEnter Prefix: "))
  24.       (foreach n lst
  25.         (vla-put-Name (vla-item blklst n) (strcat prfx n))
  26.         (setq c (1+ c))
  27.       )
  28.     )
  29.     ((= rep "Suffix")
  30.       (setq sufx (getstring "\nEnter Suffix: "))
  31.       (foreach n lst
  32.         (vla-put-Name (vla-item blklst n) (strcat n sufx))
  33.         (setq c (1+ c))
  34.       )
  35.     )
  36.   )
  37.   (prompt (strcat "\n" (rtos c 2 0) " Block(s) Renamed"))
  38.   (princ)
  39. )

like_citrus

  • Newt
  • Posts: 114
Re: LISP to insert block and rename
« Reply #2 on: May 16, 2022, 07:45:47 PM »
Thanks for sending this. I'll look into it soon.

ScottMC

  • Newt
  • Posts: 191
Re: LISP to insert block and rename
« Reply #3 on: May 17, 2022, 08:57:23 AM »
Check out this persons helpful library.
http://www.lee-mac.com/copyblock.html

like_citrus

  • Newt
  • Posts: 114
Re: LISP to insert block and rename
« Reply #4 on: May 17, 2022, 08:03:24 PM »
Thanks, will do.