stop command in script

stop command in script

cadman777
Advisor Advisor
7,077 Views
78 Replies
Message 1 of 79

stop command in script

cadman777
Advisor
Advisor

Hi,

After 3 hours of searching and trying I'm in here inquiring.

Would someone please tell me how to stop (cancel) an AutoCAD command while running a script file, but not stop the script so it can continue to process all of the remaining commands to the end?

I tried using ASCII characters to emulate the ESC key, but not luck.

I also tried running a simple LISP routine to cycle the command line, but no luck.

Couldn't figure out how to get LISP to run inside a script file.

Finally found out how to get LISP to run from a script file.

But that didn't help b/c once the LISP file terminates the script command, it also terminates the remainder of the script file.

I've been using AutoCAD since R10, but quit using it for Inventor since R6, so I'm a bit rusty on all of this AutoCAD stuff.

Any help is appreciated.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
7,078 Views
78 Replies
Replies (78)
Message 2 of 79

ronjonp
Mentor
Mentor

Did you try (exit) or (command)?

0 Likes
Message 3 of 79

Kent1Cooper
Consultant
Consultant

@cadman777 wrote:

....

Would someone please tell me how to stop (cancel) an AutoCAD command while running a script file?

....


Do you mean to stop just the command, but to have the Script continue?  Or to stop the entire Script?  Some commands can be "concluded" rather than "cancelled" by just a blank line in the Script, providing their concluding Enter, for example LAYER or LINE or PLINE or COPY when in Multiple mode.  Can you describe an example?

Kent Cooper, AIA
0 Likes
Message 4 of 79

john.kaulB9QW2
Advocate
Advocate
(quit) it, ronjonp.
another swamper
0 Likes
Message 5 of 79

cadman777
Advisor
Advisor

Yes, I tried (command) but it didn't work. But get this: While waiting for a forum answer, I rebooted AutoCAD and tried (command) again, and it worked. Go figure!

 

Now I need to 'resume' the script, b/c the command termination was for only one of a string of commands, some of which need to continue.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 6 of 79

paullimapa
Mentor
Mentor

You should be able to use Backspace key on your keyboard to pause the script and then enter command Resume to continue

Scroll to the bottom to read about these features 

https://help.autodesk.com/view/ACDLT/2022/ENU/?guid=GUID-BE44AE86-7638-48C9-BE5B-C1DF8E4C8808


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 79

cadman777
Advisor
Advisor

Thanks, but I want the script to be fully automated.

Note: I do NOT want to PAUSE the script.
I plan on using ScriptPro to apply the script to a directory of drawings.
Any other ideas?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 8 of 79

cadman777
Advisor
Advisor

 

 

Do you mean to stop just the command, but to have the Script continue?

 

 

Yes

 

I want to run a script on a directory of DXFs.

First I need to make a reliable script.

I got it to work on a toolbar button (macro), but want a script instead to use w/ScriptPro.

So at least I know it does work.

 

Example:

Zoom Extents

then

Explode All

then

Pedit Join All

then

Tilemode 0

then

SaveAs DXF R12

then

Tilemode 1

 

Pedit needs to be shut down and the rest of the script resumed.

 

Thanx for your input... 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 9 of 79

ronjonp
Mentor
Mentor

@cadman777 Why not use the "JOIN" command?

 

Not sure I understand what shutting down pedit means.

0 Likes
Message 10 of 79

paullimapa
Mentor
Mentor

Unfortunately you cannot pause a script for user input. All the info need to be already there in the script file and must run to completion. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 79

ronjonp
Mentor
Mentor

@paullimapa wrote:

Unfortunately you cannot pause a script for user input. All the info need to be already there in the script file and must run to completion. 


You can pause a lisp being called from a script .. but that defeats the purpose of scripting

 

_.OPEN "C:\Path\To\File\TEST.dwg"
(C:MYLISP)
_.CLOSE

 

0 Likes
Message 12 of 79

cadman777
Advisor
Advisor

 

 

Not sure I understand what shutting down pedit means.

 

 

Try this:

Draw a few lines that are connected at the ends but are not a polyline.

Invoke Pedit and go through the prompts.

Then make a script that does the same thing, except add some other commands after the script.

See what happens.

 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 13 of 79

ronjonp
Mentor
Mentor

@cadman777 wrote:
Not sure I understand what shutting down pedit means.

Try this:

drawing a few lines that are connected at the ends but are not a polyline.

Invoke Pedit and go through the prompts.

Then make a script that does the same thing, except add some other commands after the script.

See what happens.

 


Use the JOIN command.

 

Is your purpose to explode all in mspace then switch to pspace after?

0 Likes
Message 14 of 79

cadman777
Advisor
Advisor

OK guys, I'm beginning to see that my 'little' endeavor into scripting has become another MEGA PROJECT due to Autodesk's FUBAR 'programming' system. I can't remember how to code LISP, which I was fair at in the past (90's). Back then I was pretty good at scripts. I have some of my old scripts that setup drawings for different customer's standards. It combined Scripts and LISP, but that was too long ago! Anyway, I also got pretty good at hacking my way through iLogic with Inventor relying on a LOTTA help from the forum gurus. But now, I'm pretty much not 1/2 the man I used to be, so am struggling w/this. Here's what I discovered today after about 8 hours of fumbling around in this old world:

 

If there are no entities that can be Exploded, then the rest of my script fails. So I need to have error checking at that point. Can't recall how to do that. Next caveat is if all the entities are already joined or if none of the entities can be joined. Need error handling for that too. Also, if all the entities are non-polylines, same thing. Then there's Qsave or SaveAs. Another typical case of if/and/but/exceptions/etc. So at this point, I am cursing Autodesk for making this so g/d difficult for those of us who don't have the gray matter to force our way through it to get 'productive'. I've ranted like this in the Inventor Customization forum more than I'd like to admit.

 

By way of comparison, Rhino3D has a GUI programming environment. It's complex but not too difficult to learn by comparison. We all work in the GUI environment with ALL Autodesk products. One would think...or COMMON SENSE would dictate that we also would use a GUI programming language to handle these things. Anyway, that's my rant b/c I don't have the graystuff to get this done. Too many other irons in the fire, so not enough time to 'power through' it.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 15 of 79

ronjonp
Mentor
Mentor

Here's the bulk of it sorted out .. assuming you're zooming extents, exploding, then joining all in MODELSPACE.

 

(defun c:foo (/ s)
  ;; To modelspace?
  (setvar 'tilemode 1)
  ;; If we have a selection in modelspace
  (if (setq s (ssget "_X" '((410 . "Model"))))
    (progn ;; Zoom
	   (command "_Zoom" "_Extents")
	   ;; Explode
	   (vl-catch-all-apply 'vl-cmdf (list "_.Explode" s ""))
	   ;; Join
	   (initcommandversion)
	   (vl-catch-all-apply 'vl-cmdf (list "_.Join" "_All" ""))
	   ;; To paperspace
	   (setvar 'tilemode 0)
	   ;; Add your line to save as DXF12 below
      
	   ;; To modelspace
	   (setvar 'tilemode 1)
    )
  )
  (princ)
)

 

 

 

0 Likes
Message 16 of 79

cadman777
Advisor
Advisor

Well...there you have it!

I added Qsave and all the switches, and it works.

It works on one file only.

Thanks for making this for me.

I hesitate to ask how long it took you, considering I spent 8 hours and got nowhere!

What? 10 minutes? Maybe 5?

Anyway, thanx for helping with this.

Do you know if there's a utility I can get that I can apply this LISP to multiple files on disk?

 

UPDATE:
I can't get Qsave to work right.

I can't get past the "file already exists, do you want to replace it" prompt.

Here's the line I added to the LSP file:

 

(command "filedia" 0)
(command "_Qsave" "dxf" "v" "lt2" 16 "y")
(command "filedia" 1)
(command "Close")

 

Got any hints at what I may be doing wrong?

 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 17 of 79

paullimapa
Mentor
Mentor

The easiest way for you to apply this lisp for example named foo.lsp to all drawings in a specific folder is with Lee Mac's Script Writer:

http://www.lee-mac.com/scriptwriter.html

First make sure foo.lsp is saved in a trusted folder location specified in AutoCAD using command: Options>Files>Trusted Locations

paullimapa_2-1690583904780.png

 

Next, download & run ScriptWriterV1-2.lsp in an empty drawing by entering at the command prompt: 

WScript

paullimapa_1-1690583741495.png

For Script Line enter the following:

_.Open *file* (load"foo") (c:foo) _.Close

Click Directory button and select a folder where you want this to be applied to all the drawings

Finally, click Run Script!

Then if all works as expected, you should see AutoCAD open each drawing and run foo.lsp before closing.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 18 of 79

cadman777
Advisor
Advisor

Have you tried ScriptWriter with DXF files?
Have you tried it using LISP files?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 19 of 79

paullimapa
Mentor
Mentor

**Also the newly saved dxf files have an addtional "-R12" added to the filename so the original is not changed.

I modified Lee's Script Writer and created this version I've named: ScriptWriterV1-2dxf.lsp

This now will open only dxf (instead of dwg) files in the selected folder for you to run foo.lsp

The Script Line needs to be modified to this:

_.Open *file* (load"foo") (c:foo) _.Close _Y

paullimapa_0-1690587487769.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 20 of 79

cadman777
Advisor
Advisor

Thanks a lot for doing that for me.

I have to close down for the day but will be back at it next week to try out your new app.

 

Thanks everyone for helping me with this so far.

Much obliged!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes