Lisp to move , explode and burst some layers

Lisp to move , explode and burst some layers

S_S_SS
Advocate Advocate
1,979 Views
15 Replies
Message 1 of 16

Lisp to move , explode and burst some layers

S_S_SS
Advocate
Advocate

Hello everyone....
I want a lisp ...
I Have layers "(main) S-Decking Beam","(main) S-Decking Drop" ,"(main) S-Decking Slab","(secondary) S-Decking Beam","(secondary) S-Decking Drop"and "(secondary) S-Decking Slab"  i need a lisp to select objects in these layers and make "Burst" command on them and move them with (200000) unit in x direction......

And also select objects in "Tubes" layer and make "Explode" command on them and move them with (-200000) unit in x direction ......

then make "Purge" command 

Can someone help me about that ?? 

0 Likes
Accepted solutions (3)
1,980 Views
15 Replies
Replies (15)
Message 2 of 16

pbejse
Mentor
Mentor

@S_S_SS wrote:

Hello everyone....
I want a lisp ..
I Have layers "(main) S-Decking Beam","(main) S-Decking Drop" ,"(main) S-Decking Slab","(secondary) S-Decking Beam","(secondary) S-Decking Drop"and "(secondary) S-Decking Slab"  i need a lisp to select objects in these layers and make "Burst" command on them and move them with (200000) unit in x direction......

And also select objects in "Tubes" layer and make "Explode" command on them and move them with (-200000) unit in x direction ......

then make "Purge" command 

Can someone help me about that ?? 


Never knew you can use this symbol "(" and ")"  on a layer name. 

We assume the objects under those layer names are attribute blocks and the Tubes are regular blocks YES?

 

You mind posting a sample  drawing?

 

 

0 Likes
Message 3 of 16

S_S_SS
Advocate
Advocate

No I only show the layer name inside these symbols "" 😅 I'm sorry about that 

00000.JPG

 here you are the layer names and i attached the DWG file 
layer tube contain polylines and all other layers contain dynamic block with attributes and visibilities....
thanks in advance sir …   

0 Likes
Message 4 of 16

pbejse
Mentor
Mentor

@S_S_SS wrote:

..And also select objects in "Tubes" layer and make "Explode" command on them and move them with (-200000) unit in x direction ......

There are no blocks under "Tubes" layer, I'm assuming its blocks hence the need to explode?

You realize some of the blocks on this drawing is non-explodable. is that by design? are you suppose to leave it as that?

 

Message 5 of 16

S_S_SS
Advocate
Advocate

Yes sir

I want to get the length of objects on tubes layer by DX command so I need to explode it to convert multilines to lines so I want to explode it

 

Also I make some blocks not exploded I mean that and it is right...... 

0 Likes
Message 6 of 16

pbejse
Mentor
Mentor
Accepted solution

@S_S_SS wrote:

Yes sir

I want to get the length of objects on tubes layer by DX command so I need to explode it to convert multilines to lines so I want to explode it

 

Also I make some blocks not exploded I mean that and it is right...... 


(Defun c:LTME (/ _Explodable ssb i e ipt bnm )
(setvar 'cmdecho 0)      
(defun _Explodable ( bn  / bl Ent )     
  (cond
        ((null (setq bl (tblsearch "BLOCK" bn))))
	((and (< (logior 2 (cdr(assoc 70 bl))) 3)
	          (setq Ent (entget (cdr (assoc -2 bl)))
		        Ent (entget (cdr (assoc 330 Ent))))
              )
	(entmod (subst (cons 280  1)
                               (assoc 280 Ent) Ent)))
                   )
                 )      
(if (setq ssb (ssget "_X" '((-4 . "<OR") (-4 . "<AND")
			 (0 . "INSERT")(8 . "*S-Decking*") (-4 . "AND>")
			 (-4 . "<AND")
			 (0 . "MLINE") (8 . "TUBES") (-4 . "AND>")
			 (-4 . "OR>")))
			)
 (progn
	   (repeat (Setq i (sslength ssb))
	         (setq e (vlax-ename->vla-object (ssname ssb (Setq i (1- i)))))
	         (cond
	               ((eq (vla-get-objectname e)  "AcDbBlockReference")
	                	(if (not (member (setq bnm (vla-get-EffectiveName e)) blklst))
	             			(progn
	                                      (_Explodable bnm)
			                              (setq blklst (cons bnm blklst)))
			                     )
	                	(setq ipt (vlax-get e 'InsertionPoint))
	         		(vla-put-insertionpoint e (vlax-3D-point (cons (+ 200000 (car ipt)) (Cdr ipt))))
	         		(Vlax-invoke e 'Explode)
	         		(Vla-delete e)
	                )
	               ( T
	                (vla-move e (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point '(-200000.0 0.0 0.0)))
	                (command-s "_Explode" (ssname ssb i) "")
	                )
	         )
	   )
	    (repeat 4
	  (vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
		 )
	   )
    )
 (princ)
 )

Command: LTME

 

HTH

0 Likes
Message 7 of 16

S_S_SS
Advocate
Advocate

thanks sir 
i have two requests about that please 
i need to make burst command not exploded to layers S-Decking to make blocks in the layer of the block that exploded 
they now in layer 0 
and also i need to move layers that contain (secondary) to different place to make it easy to check about it 
you can move layers that contain (secondary) in y direction 200000 unit 
i'm sorry for that and thanks about your great help 

0 Likes
Message 8 of 16

pbejse
Mentor
Mentor

@S_S_SS wrote:

thanks sir 
i have two requests about that please 
i need to make burst command not exploded to layers S-Decking to make blocks in the layer of the block that exploded 
they now in layer 0 
and also i need to move layers that contain (secondary) to different place to make it easy to check about it 
you can move layers that contain (secondary) in y direction 200000 unit 
i'm sorry for that and thanks about your great help 


 

As usual, there's always something more. Why am i not surprise.

 

Burst is not necessary as the blocks does not even have attributes and it is extremely slow, all you need to say  is you need them to be on the oroginal layer from the get-go

 

I'm giving you more time to think of  other "request" before i even modify the code.

 

Message 9 of 16

S_S_SS
Advocate
Advocate

NO sir 
that's all that i need 
i need to learn something from you how to select objects by layer 
i mean that how to select objects in layer (tubes) as example  

0 Likes
Message 10 of 16

pbejse
Mentor
Mentor
Accepted solution
(Defun c:LMEL (/ _Explodable ssb i e ipt bnm )
  (defun _Entnext ( e )
    (if (setq e (entnext e)) (cons e (_Entnext e)))
  )        
(setvar 'cmdecho 0)      
(defun _Explodable ( bn  / bl Ent )     
  (cond
        ((null (setq bl (tblsearch "BLOCK" bn))))
	((and (< (logior 2 (cdr(assoc 70 bl))) 3)
	          (setq Ent (entget (cdr (assoc -2 bl)))
		        Ent (entget (cdr (assoc 330 Ent))))
              )
	(entmod (subst (cons 280  1)
                               (assoc 280 Ent) Ent)))
                   )
                 )      
(if (setq ssb (ssget "_X" '((-4 . "<OR") (-4 . "<AND")
			 (0 . "INSERT")(8 . "*S-Decking*") (-4 . "AND>")
			 (-4 . "<AND")
			 (0 . "MLINE") (8 . "TUBES") (-4 . "AND>")
			 (-4 . "OR>")))
			)
 (progn
	   (repeat (Setq i (sslength ssb))
	         (setq e (vlax-ename->vla-object (ssname ssb (Setq i (1- i))))
                       ln (Vla-get-layer e))
	         (cond
	               ((eq (vla-get-objectname e)  "AcDbBlockReference")
	                	(if (not (member (setq bnm (vla-get-EffectiveName e)) blklst))
	             			(progn
	                                      (_Explodable bnm)
			                              (setq blklst (cons bnm blklst)))
			                     )
                        	(vlax-invoke e 'Move '(0.0 0.0 0.0)
						(if (wcmatch (strcase ln) "*(SECONDARY)*")
                                                              	'(0.0 200000.0 0.0) '(200000.0 0.0 0.0)))
                        	(setq ang nil el (entlast) ssc (ssadd))
	         		(Vlax-invoke e 'Explode)
                        	(foreach itm (_Entnext el)
                                      (Vla-put-layer (vlax-ename->vla-object itm) ln))		
	         		(Vla-delete e)
                        	
	                )
	               ( T
                         (vlax-invoke e 'Move '(0.0 0.0 0.0) '(-200000.0 0.0 0.0))
	                (command-s "_Explode" (ssname ssb i) "")
	                )
	         )
	   )
	    (repeat 4
	  (vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
		 )
	   )
    )
 (princ)
 )

Command: LMEL

 


@S_S_SS wrote:

NO sir 
that's all that i need 
i need to learn something from you how to select objects by layer 
i mean that how to select objects in layer (tubes) as example  


You need to use a filter like this, it selects objects under layer "TUBES"  ( and its not case senstive ) on screen

(setq ss (ssget '((8 . "TUBES"))))

8 as DXF code for layer 

 

You can limit the type of object by including DXF code 0 for Entity type

(setq ss (ssget '((0 . "MLINE") (8 . "TUBES"))))

 The above line enables the user to select only "MLINE" under "TUBES" layer

 

HTH

Message 11 of 16

S_S_SS
Advocate
Advocate

I'M Very happy about that 
thanks very very much sir ❤️

0 Likes
Message 12 of 16

pbejse
Mentor
Mentor

@S_S_SS wrote:

I'M Very happy about that 
thanks very very much sir ❤️


Glad it helps. and you hope you learn from it.

Cheers 

 

Message 13 of 16

S_S_SS
Advocate
Advocate

Hello sir ..
good morning 
i wish you well 

i wait some time to use your good lisp 
and i need to make two points 
and i hope this won't bother you

 

first point is about tubes layer if i have an error about my drawing and want to undo some orders i have to make undo more to undo all tubes layer 
i wish that you select all the layer of tubes and move it in one time and explode it also in one time ....


the second point is about 
if someone forget and make the lisp twice it explode the blocks in layers s-Decking and convert them to lines and i make them not allowed to exploded 


can you help me about that please ? 

 

0 Likes
Message 14 of 16

pbejse
Mentor
Mentor
Accepted solution

@S_S_SS wrote:

first point is about tubes layer if i have an error about my drawing and want to undo some orders i have to make undo more to undo all tubes layer 
i wish that you select all the layer of tubes and move it in one time and explode it also in one time ....


We'll include an undo mark, hope that will handle the issue. if that is indeed what you meant by that

 

 


@S_S_SS wrote:

the second point is about 
if someone forget and make the lisp twice it explode the blocks in layers s-Decking and convert them to lines and i make them not allowed to exploded 


You noted before that the blocks at layer "(main) S-Decking Slab" and "(secondary) S-Decking Beam" are not explodable by design. so there's no chances of that happening. OR we can add the names of the block not to be included on the selection OR move only if the block has dyanamic properties

 

(Defun c:LMEL (/ _Explodable ssb i e ipt bnm )
  (defun _Entnext ( e )
    (if (setq e (entnext e)) (cons e (_Entnext e)))
  )        
(setvar 'cmdecho 0)      
(defun _Explodable ( bn  / bl Ent )     
  (cond
        ((null (setq bl (tblsearch "BLOCK" bn))))
	((and (< (logior 2 (cdr(assoc 70 bl))) 3)
	          (setq Ent (entget (cdr (assoc -2 bl)))
		        Ent (entget (cdr (assoc 330 Ent))))
              )
	(entmod (subst (cons 280  1)
                               (assoc 280 Ent) Ent)))
                   )
                 )
(vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))  
(if (setq ssb (ssget "_X" '((-4 . "<OR") (-4 . "<AND")
			 (0 . "INSERT")(8 . "*S-Decking*")
			    (-4 . "<NOT") (2 . "S-beam * plan")(-4 . "NOT>")
			    (-4 . "AND>")
			 (-4 . "<AND")
			 (0 . "MLINE") (8 . "TUBES") (-4 . "AND>")
			 (-4 . "OR>")))
			)
 (progn
	   (repeat (Setq i (sslength ssb))
	         (setq e (vlax-ename->vla-object (ssname ssb (Setq i (1- i))))
                       ln (Vla-get-layer e))
	         (cond
	               ((and
			  (eq (vla-get-objectname e)  "AcDbBlockReference")
			  (minusp (vlax-get e 'IsDynamicBlock))
			  )
	                	(if (not (member (setq bnm (vla-get-EffectiveName e)) blklst))
	             			(progn
	                                      (_Explodable bnm)
			                              (setq blklst (cons bnm blklst)))
			                     )
                        	(vlax-invoke e 'Move '(0.0 0.0 0.0)
						(if (wcmatch (strcase ln) "*(SECONDARY)*")
                                                              	'(0.0 200000.0 0.0) '(200000.0 0.0 0.0)))
                        	(setq ang nil el (entlast) ssc (ssadd))
	         		(Vlax-invoke e 'Explode)
                        	(foreach itm (_Entnext el)
                                      (Vla-put-layer (vlax-ename->vla-object itm) ln))		
	         		(Vla-delete e)
                        	
	                )
	               ( T
                         (vlax-invoke e 'Move '(0.0 0.0 0.0) '(-200000.0 0.0 0.0))
	                (command-s "_Explode" (ssname ssb i) "")
	                )
	         )
	   )
	    (repeat 4
	  (vla-purgeall (vla-get-activedocument (vlax-get-acad-object)))
		 )
	   )
    )
(vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))  
 (princ)
 )

HTH

 

 

 

 

Message 15 of 16

S_S_SS
Advocate
Advocate

Thanks my brother about that 
it's a perfect lisp

0 Likes
Message 16 of 16

hakangus
Advocate
Advocate

I steal the thread a little by asking if there´s a way to use a variable in the expression to select objects in a certain layer?

Rather than using a "fixed" layer name I would be able to use something like this:

(defun c:exportfeaturelines (layername)
...
  (setq sel1 (ssget "x" '((8 . layername))))
  (initcommandversion 2)
  (command "_explode" sel1 "")
(princ)
)

 

0 Likes