macro or LISP where I can select object, cut and paste to X,Y 0,0 and starts the write block command.

macro or LISP where I can select object, cut and paste to X,Y 0,0 and starts the write block command.

mkroll9in5in
Enthusiast Enthusiast
605 Views
3 Replies
Message 1 of 4

macro or LISP where I can select object, cut and paste to X,Y 0,0 and starts the write block command.

mkroll9in5in
Enthusiast
Enthusiast

I'm looking for a macro or LISP, now on LT 2024, where I can select object, cut and paste to X,Y 0,0 (at this point I would like to explode previous if possible) starts the write block command, select previous, then prompt me for file name and location.

I wrote this into a macro on my mouse because there I can use a combination of windows key commands like cut and paste. When you paste an object in CAD it puts it at the end of your cursor so that the whole of the geometry is in the upper right hemisphere of the cursor (regardless of orientation) so at that point you can specify 0,0 as your destination, followed up with a (explode previous) then write block command, select previous, and prompt name and location. quickly shooting parts one at a time to a cnc machine.

0 Likes
Accepted solutions (1)
606 Views
3 Replies
Replies (3)
Message 2 of 4

JBerns
Advisor
Advisor

@mkroll9in5in,

 

Would this be close to what you need?

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/wblock-using-a-cross-window-selectio...  

 

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

@mkroll9in5in wrote:

.... you can specify 0,0 as your destination, followed up with a (explode previous) then write block command, select previous, and prompt name and location. quickly shooting parts one at a time to a cnc machine.


Is it always a single object, never a multiple-object selection?  If multiple, I can see a problem with Exploding Previous and then Selecting Previous.  In any case, Explode Previous after copy/pasting will Explode the original(s), not the pasted one(s), which I imagine isn't what you intend.

Kent Cooper, AIA
0 Likes
Message 4 of 4

mkroll9in5in
Enthusiast
Enthusiast
Accepted solution

With ChatGPT I was able to create 2 LISPs then tie them together in a macro that does a pretty close job. Like you said there was a select previous issue with the wblock command, but much better than it was.
^C^C_xallp;_m00;\\\_wblock;

(defun c:xallp ()
(setq old_err (getvar 'ERRNO))
(setq ss (ssget "_X" '((0 . "LWPOLYLINE"))))
(setq cnt 0)

(if (setq ss_len (sslength ss))
(progn
(repeat ss_len
(setq ent (ssname ss 0))
(setq cnt (+ cnt 1))
(setq ss (ssdel ent ss))
(command "_.explode" ent "")
)
(princ (strcat "\nExploded " (itoa cnt) " polylines."))
)
(princ "\nNo polylines found.")
)

(setvar 'ERRNO old_err)
(princ)
)

(defun c:m00 ()
(setq ss (ssget)) ; Prompt the user to select a group of geometries

(if ss
(progn
(command "._cutclip" ss "") ; Cutclip the selected geometries
(command "._pasteclip" "_non" "0,0") ; Pasteclip at 0,0 coordinate
)
(prompt "\nNo geometries selected.")
)

(princ)
)

0 Likes