Need a Lisp to Explode, Copy and Undo

Need a Lisp to Explode, Copy and Undo

saqib_tipa
Advocate Advocate
765 Views
8 Replies
Message 1 of 9

Need a Lisp to Explode, Copy and Undo

saqib_tipa
Advocate
Advocate

 

Hello all,

I need a lisp to select objects then Explode them, select previous and Copybase 0,0 and make undo before Explode.

I am trying but it only selects 1st exploded object from selection and copy that not all exploded objects.

 

(defun c:CopyExplodeUndo (/ ss exploded-ss)
  ;; Start an undo group
  (command "_.UNDO" "BEGIN")

  ;; Ask the user to select objects
  (setq ss (ssget))

  ;; If the user selects objects, proceed
  (if ss
    (progn
      ;; Explode the selected objects
      (command "_.EXPLODE" ss)
      
      ;; Select all exploded objects
      (setq exploded-ss (ssget "_P"))

      ;; Copy the exploded objects from base point 0,0
      (command "_.COPYBASE" '(0 0) exploded-ss "")
    )
  )

  ;; Undo all actions in this group
  (command "_.UNDO" "END")
  (command "_.UNDO" "1")
  
  ;; End the routine
  (princ)
)

 

 

Thank you.

0 Likes
Accepted solutions (1)
766 Views
8 Replies
Replies (8)
Message 2 of 9

robske
Participant
Participant

Why do you use undo, you can also copy the original object and explode the copy for the same result.

0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@saqib_tipa wrote:

.... but it only selects 1st exploded object from selection and copy that not all exploded objects. ....


That is because, for some unknown reason, the EXPLODE command, when used inside an AutoLisp (command) function without certain tricks, can Exlode only one object.  It didn't Explode them and then select only one, but rather it Exploded only one and then selected the result(s) of that.

 

This is one [probably the easiest -- there is at least one other way] trick to use:

....
(if ss
  (progn
    ;; Explode the selected objects
    (initcommandversion)
    (command "_.EXPLODE" ss "")

    ;; Select all exploded objects
    (setq exploded-ss (ssget "_P"))
....

Kent Cooper, AIA
Message 4 of 9

saqib_tipa
Advocate
Advocate

 

@robske 

 

Yes, for simple Autocad objects it can be done but I want to make it for Civi3d objects. 

0 Likes
Message 5 of 9

saqib_tipa
Advocate
Advocate

 

@Kent1Cooper 

It's not working.

 


This is one [probably the easiest -- there is at least one other way] trick to use:

....
(if ss
  (progn
    ;; Explode the selected objects
    (initcommandversion)
    (command "_.EXPLODE" ss "")

    ;; Select all exploded objects
    (setq exploded-ss (ssget "_P"))
....


 

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

I wonder about something:  Would the User ever select objects that include some basic [non-Explodable] ones like Lines and Arcs, and want those included along with the results of EXPLODEng the Explodable things, in what is COPYBASEd out?  The code as written, with the (initcommandversion) adjustment, would not include those other things, but only the things that are the result of the EXPLODE command.  Is your process such that only things subject toe EXPLODE would ever be selected?

Kent Cooper, AIA
0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@saqib_tipa wrote:

.... It's not working. ....


Did you catch it too quickly?  I originally forgot the "" Enter to complete selection in the Explode command, but edited that in pretty soon after.  Does it work for you with that included?  [It does for me.]

Kent Cooper, AIA
Message 8 of 9

saqib_tipa
Advocate
Advocate

 

These are simple commands which work but not with Lisp to automate this work.


-------------------------------------

Command: SELECT
Select objects: Specify opposite corner: 5 found
Select objects:
Command: EXPLODE
5 found
Command: SELECT
Select objects:
Command: SELECT
Select objects: p
15 found
Select objects:
Command: COPYBASE
Specify base point: 0,0
15 found

--------------------------

I have to copy sometimes few Civil3d objects like Labels, Profile lines etc. so it works there.

Thank you.

0 Likes
Message 9 of 9

saqib_tipa
Advocate
Advocate

 

@Kent1Cooper 

 

I got first quickly and applied that but now It is working for me too.

 

Thank you so much for your quick reply and help.

 



Did you catch it too quickly?  I originally forgot the "" Enter to complete selection in the Explode command, but edited that in pretty soon after.  Does it work for you with that included?  [It does for me.]


 

0 Likes