wimal Posted August 23, 2018 Posted August 23, 2018 I need to explode the block and move all entities to given layer. Pl. give me a LISP code. Quote
dlanorh Posted August 23, 2018 Posted August 23, 2018 Here you go (defun rh:ex2layer ( obj lyr / objs) (cond ( (vlax-method-applicable-p obj 'explode) (setq objs (vlax-safearray->list (vlax-variant-value (vla-explode obj)))) (foreach e_obj objs (vlax-put-property e_obj 'layer lyr) );end_foreach ) );end_cond );end_defun Quote
eldon Posted August 23, 2018 Posted August 23, 2018 Have you tried the existing XPLODE command? Quote
wimal Posted August 23, 2018 Author Posted August 23, 2018 (command "-layer" "N" "lyr" "") (command "insert" "QkBeam" "non" (LIST 0 0) 100 100 "0") (setq OBJ (entlast)) (rh:ex2layer) (defun rh:ex2layer ( obj lyr / objs) (cond ( (vlax-method-applicable-p obj 'explode) (setq objs (vlax-safearray->list (vlax-variant-value (vla-explode obj)))) (foreach e_obj objs (vlax-put-property e_obj 'layer lyr) );end_foreach ) );end_cond );end_defun ur It is not working.Something wrong somewhere. Quote
ronjonp Posted August 23, 2018 Posted August 23, 2018 (edited) You are not calling the subfunction with the correct arguments... Perhaps something a little easier for you to use: (defun c:foo (/ l lyr o s) ;; RJP » 2018-08-23 (setq lyr "test") (or (tblobjname "layer" lyr) (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) lyr) ) (cond ((setq s (ssget ":L" '((0 . "insert,*polyline,region")))) (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq o (vlax-ename->vla-object x)) (cond ((= 'list (type (setq l (vl-catch-all-apply 'vlax-invoke (list o 'explode))))) (foreach y l (vla-put-layer y lyr)) (entdel x) ) ) ) ) ) (princ) ) (vl-load-com) Edited August 24, 2018 by ronjonp poor grammar ;\ 1 Quote
dlanorh Posted August 23, 2018 Posted August 23, 2018 4 hours ago, wimal said: (command "-layer" "N" "lyr" "") (command "insert" "QkBeam" "non" (LIST 0 0) 100 100 "0") (setq OBJ (entlast)) (rh:ex2layer) (defun rh:ex2layer ( obj lyr / objs) (cond ( (vlax-method-applicable-p obj 'explode) (setq objs (vlax-safearray->list (vlax-variant-value (vla-explode obj)))) (foreach e_obj objs (vlax-put-property e_obj 'layer lyr) );end_foreach ) );end_cond );end_defun ur It is not working.Something wrong somewhere. No, it is working but you're not using it correctly. It is a function and needs to be called like this: (rh:ex2layer object "layer name") It needs to be an object but you are setting obj to an entity. This needs to be converted by replacing your setq with this (setq obj (vlax-ename->vla-object (entlast))) "layer name" needs to be the layer name of any valid layer that exists in the drawing. And while we are there you will need (vl-load-com) somewhere in your lisp. If you want to use it "inline" I suggest this (command "-layer" "N" "lyr" "");YOU DON'T HAVE TO CREATE A NEW LAYER (command "insert" "QkBeam" "non" (LIST 0 0) 100 100 "0") (setq lyr "lyr" ;REPLACE "lyr" WITH THE NAME OF THE LAYER YOU WANT THE EXPLODED ITEMS TO GO TO obj (vlax-ename->vla-object (entlast)) );end_setq (vl-load-com) (cond ( (vlax-method-applicable-p obj 'explode) (setq objs (vlax-safearray->list (vlax-variant-value (vla-explode obj)))) (foreach e_obj objs (vlax-put-property e_obj 'layer lyr) );end_foreach ) );end_cond 1 Quote
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.