TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: econnerly on March 07, 2012, 10:50:45 AM

Title: Insert block on top of other blocks?
Post by: econnerly on March 07, 2012, 10:50:45 AM
Does anyone have a lisp that will allow me to insert a block on top of another block so that it will insert using the existing blocks insertion point and rotation? I have been doing a work around by copying the blocks out to a new drawing, redefining them (house footprints) with only the info I want to add (driveways), then exploding them and finally pasting back into my original drawing.
Title: Re: Insert block on top of other blocks?
Post by: CAB on March 07, 2012, 11:51:51 AM
You can modify this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ ent ent1 ent2 ss i blkobj blkname activespace)
  2.   (if (and (setq ent1 (car (entsel "\nSelect the destination block for name.")))
  3.            (setq ent2 (car (entsel "\nSelect the block to be inserted.")))
  4.            (princ "\nSelect the destination blocks.")
  5.            (setq ss (ssget (list (assoc 2 (entget ent1)))))
  6.       )
  7.     (progn
  8.       (setq activespace
  9.              (if (or (= acmodelspace (vla-get-activespace doc))
  10.                      (= :vlax-true (vla-get-mspace doc))
  11.                  )
  12.                (vla-get-modelspace doc)
  13.                (vla-get-paperspace doc)
  14.              )
  15.       )
  16.       (setq blkname (cdr (assoc 2 (entget ent2))))
  17.       (setq i -1)
  18.       (while (setq ent (ssname ss (setq i (1+ i))))
  19.         (setq blkobj
  20.                (vla-insertblock
  21.                  activespace
  22.                  (vlax-3d-point (cdr (assoc 10 (entget ent))))
  23.                  blkname
  24.                  1.0 ; xscale
  25.                  1.0 ; yscale
  26.                  1.0 ; zscale
  27.                  0.0 ; rotation
  28.                )
  29.         )
  30.       )
  31.     )
  32.   )
  33.   (princ)
  34. )
Title: Re: Insert block on top of other blocks?
Post by: econnerly on March 07, 2012, 01:48:18 PM
Thanks CAB,
Im not good at lisp and still in the learning stages. I don't know how to write it to match the rotation of the blocks im picking.
Title: Re: Insert block on top of other blocks?
Post by: danallen on March 07, 2012, 02:00:25 PM
Try this, do a copy (as in for copy/paste)

paste into a blank drawing, in that drawing, rename the block definition to the block you want them to be

copy those newly named blocks and paste back into the original drawing, they will all be the same layer, scale, rotation, but with the correct definition
Title: Re: Insert block on top of other blocks?
Post by: Lee Mac on March 07, 2012, 02:09:36 PM
Try this, do a copy (as in for copy/paste)

paste into a blank drawing, in that drawing, rename the block definition to the block you want them to be

copy those newly named blocks and paste back into the original drawing, they will all be the same layer, scale, rotation, but with the correct definition

I have been doing a work around by copying the blocks out to a new drawing, redefining them (house footprints) with only the info I want to add (driveways), then exploding them and finally pasting back into my original drawing.

 :wink:
Title: Re: Insert block on top of other blocks?
Post by: CAB on March 07, 2012, 03:59:38 PM
Try this, also updates the layer as example of how to modify other properties.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ ent ent1 ent2 ss i blkobj blkname activespace)
  2.   (if (and (setq ent1 (car (entsel "\nSelect the destination block for name.")))
  3.            (setq ent2 (car (entsel "\nSelect the block to be inserted.")))
  4.            (princ "\nSelect the destination blocks.")
  5.            (setq ss (ssget (list (assoc 2 (entget ent1)))))
  6.       )
  7.     (progn
  8.       (setq activespace
  9.              (if (or (= acmodelspace (vla-get-activespace doc))
  10.                      (= :vlax-true (vla-get-mspace doc))
  11.                  )
  12.                (vla-get-modelspace doc)
  13.                (vla-get-paperspace doc)
  14.              )
  15.       )
  16.       (setq blkname (cdr (assoc 2 (entget ent2))))
  17.       (setq i -1)
  18.       (while (setq ent (ssname ss (setq i (1+ i))))
  19.         (setq blkobj
  20.                (vla-insertblock
  21.                  activespace
  22.                  (vlax-3d-point (cdr (assoc 10 (entget ent))))
  23.                  blkname
  24.                  1.0 ; xscale
  25.                  1.0 ; yscale
  26.                  1.0 ; zscale
  27.                  (cdr (assoc 50 (entget ent))) ; rotation
  28.                )
  29.         )
  30.         (vla-put-layer blkobj (cdr (assoc 8 (entget ent)))) ; use layer of original block1
  31.       )
  32.     )
  33.   )
  34.   (princ)
  35. )
Title: Re: Insert block on top of other blocks?
Post by: econnerly on March 07, 2012, 05:56:42 PM
You are the man! Works perfect! Thank you so very much!
Title: Re: Insert block on top of other blocks?
Post by: CAB on March 07, 2012, 10:42:35 PM
Glad to be of service.