Author Topic: Block replacement lisp needed  (Read 2305 times)

0 Members and 1 Guest are viewing this topic.

cadd4la

  • Newt
  • Posts: 27
Block replacement lisp needed
« on: April 29, 2017, 05:54:18 PM »
Hi everyone,

Looking to see if someone has or can write a lisp for me that will replace existing blocks in a drawing with another one. I'm not looking for it to do it globally (like the one in the express tools) or individual, I need to select the new block, then select the old one, and then do a window around the area and only the selected existing block updates.

Thanks,

Cadd4la
Windows 10 x64 - AutoCAD 2023

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block replacement lisp needed
« Reply #1 on: April 30, 2017, 08:43:09 AM »
« Last Edit: April 30, 2017, 08:47:25 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadd4la

  • Newt
  • Posts: 27
Re: Block replacement lisp needed
« Reply #2 on: April 30, 2017, 07:03:37 PM »
 CAB,

It is only an individual block replacer, I'm looking for on that I can window over a group of different blocks and only replace the blocks that I pre-selected  :-(

Thanks,

Cadd4la
Windows 10 x64 - AutoCAD 2023

ChrisCarlson

  • Guest
Re: Block replacement lisp needed
« Reply #3 on: May 01, 2017, 07:58:34 AM »
Try this

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Block replacement lisp needed
« Reply #4 on: May 01, 2017, 08:53:48 AM »
Here's a quick one without much error checking:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:bswap (/ b1 b2 ss)
  2.   (if (and (setq b1 (car (entsel "\nPick block to copy: ")))
  3.            (setq b2 (car (entsel "\nPick block to swap: ")))
  4.            (setq ss (ssget ":L" (list '(0 . "insert") (assoc 2 (entget b2)))))
  5.       )
  6.     (foreach b (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  7.       (entmod (subst (assoc 2 (entget b1)) (assoc 2 (entget b)) (entget b)))
  8.     )
  9.   )
  10.   (princ)
  11. )
« Last Edit: May 01, 2017, 09:20:48 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Block replacement lisp needed
« Reply #5 on: May 01, 2017, 08:58:28 AM »
@ronjonp

Be aware of this old picky trick:
Code: [Select]
(cons 2 (cdr (assoc 2 (entget b2))))
Code: [Select]
(assoc 2 (entget b2))
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Block replacement lisp needed
« Reply #6 on: May 01, 2017, 09:19:49 AM »
@ronjonp

Be aware of this old picky trick:
Code: [Select]
(cons 2 (cdr (assoc 2 (entget b2))))
Code: [Select]
(assoc 2 (entget b2))
Ah yes :) .. need to finish my coffee before starting to write code.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadd4la

  • Newt
  • Posts: 27
Re: Block replacement lisp needed
« Reply #7 on: May 04, 2017, 03:33:18 PM »
ronjonp,

Thanks, your code works but I also need it to work on dynamic and/or attributed blocks as well. :?

Regards,

Cadd4la
Windows 10 x64 - AutoCAD 2023

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Block replacement lisp needed
« Reply #8 on: May 04, 2017, 03:50:15 PM »
ronjonp,

Thanks, your code works but I also need it to work on dynamic and/or attributed blocks as well. :?

Regards,

Cadd4la
That's handy info to know before hand  ;)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC