Jump to content

Block Explode and send all entities to a given layer.


wimal

Recommended Posts

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  

 

Link to comment
Share on other sites

(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.

Link to comment
Share on other sites

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 by ronjonp
poor grammar ;\
  • Thanks 1
Link to comment
Share on other sites

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      

 

  • Thanks 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...