tnvsb Posted October 9, 2018 Share Posted October 9, 2018 Dear Helpers, I nead a lisp that should copy selected multiple nested blocks from master block. Suppose I have a master block from a Architect, that contains chairs and tables as blocks inside the master block. The lisp code should copy only the selected nested blocks to outside. Please have a look on attached dwg and image. I got a lisp code that can copy nested elements from master block, The requirement is instead of copying nested elements the lisp should copy only selected nested blocks from master block. (defun c:MCN1 (/ lastent ss) (setq lastent (entlast)) (setq ss (ssadd)) (command "_.ncopy") (while (> (getvar "cmdactive") 0) (command pause "0,0" "0,0") ) (while (setq lastent (entnext lastent)) (ssadd lastent ss) ) ) [/CODE] Regards, T.Brahmanandam NESTED COPY OF MULTIPLE BLOCKS FROM MASTER BLOCK.dwg Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted October 9, 2018 Share Posted October 9, 2018 This returns the nested block: (car (last (nentsel ))) But if the client selects something else than a block (for example a line), then the parent block itself gets selected, which is not intended. So most of the rest of the code is to exclude that, by checking the parent: (setq parent (cdr (assoc 330 nent))) If that parent says "*Paper_Space" or "*Model_Space" I exclude it. (vl-load-com) (defun _InsertBlock ( blockname ip scl rot / acadObj doc) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) ;; Insert the block (setq insertionPnt (vlax-3d-point ip)) (setq modelSpace (vla-get-ModelSpace doc)) (setq blockRefObj (vla-InsertBlock modelSpace insertionPnt blockname scl scl scl rot)) ) ;; BIB for block in block (defun c:BIB ( / nent blk ip blkname parent has_parent) ;; select a block nested inside a block (setq nent (entget (setq blk (car (last (nentsel "\nSelect a block nested inside a block: ")))))) ;; check that the selected entity isn't the block itself (setq parent (cdr (assoc 330 nent))) (if (or (= "*Paper_Space" (cdr (assoc 2 (entget parent)))) (= "*Model_Space" (cdr (assoc 2 (entget parent)))) ) (setq has_parent nil) (setq has_parent T) ) ;; check if it's a nested block (if (and has_parent (= "INSERT" (cdr (assoc 0 nent))) ) (progn (setq ip (getpoint "\nSet inset point: ")) ;; feel free to change the message ;; (setq blkname (vla-get-effectivename (vlax-ename->vla-object blk))) (princ blkname ) (_InsertBlock blkname ip 1.0 0.0 ) ;; 1.0 is scale, 0.0 is rotation. ) ;; else, (princ "\nThat's not a nested block.") ;; feel free to change the message ) (princ) ) Quote Link to comment Share on other sites More sharing options...
tnvsb Posted October 9, 2018 Author Share Posted October 9, 2018 Thank you Sir 1 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 9, 2018 Share Posted October 9, 2018 You may be interested in my Extract Nested Block program. 1 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.