stop command in script

stop command in script

cadman777
Advisor Advisor
11,460 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
11,461 Views
78 Replies
Replies (78)
Message 21 of 79

paullimapa
Mentor
Mentor

have a great weekend!!!


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

cadman777
Advisor
Advisor

OK Paul, I tried your lsp on a single drawing in AutoCAD.

The good news is, it's 'snappy' quick, and gets the job done, except for a few things.

1. It adds a suffix to the filename (-R12) instead of overwriting the file.

    I want to overwrite the file as an R12 dxf instead.

    That's where I ran into difficulties with my script too.

2. I tried running it in ScriptPro but it doesn't run for some reason.

    This is what my script file looks like:

(LOAD "E:\\AutocadKeyFiles\\LISP\\foo.lsp")

(foo)

    Not sure why it doesn't work, since when I copy and paste each line into the AutoCAD cmd prmpt it runs just fine.

Any ideas on how I can get this to run?


Minor rant: After all these DECADES of CUSTOMER INCONVENIENCE and WASTED RESOURCES, one would think that Autodesk developers would add functions to their scripting language to remove the BLATANT LIMITATIONS that is has always had so that the NON-EXPERTS (like me) can use it without CUSSING UP A STORM due to wasting tons of time on one simple need. One would think they would TAKE CARE OF THEIR CUSTOMERS! In the legal world, we non-legal experts call this kind of thing the rich man's game of f**k you ("rich man" = investors and corporate officers).

... 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 23 of 79

ronjonp
Mentor
Mentor
Accepted solution

@cadman777 

Give this a try:

Note that setting expert to 2 or greater will suppress the prompt to overwrite the dxf if it exists.

 

(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
	   (setvar 'expert 5)
	   ;; Save as DXF R12
	   (vl-cmdf "_.DXFOUT"
		    (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)))
		    "_V"
		    "_R12"
		    "16"
	   )
	   (setvar 'expert 0)
	   ;; To modelspace
	   (setvar 'tilemode 1)
	   (vl-cmdf "_.Qsave")
    )
  )
  (princ)
)

 

 

 

0 Likes
Message 24 of 79

paullimapa
Mentor
Mentor
Accepted solution

I ran into the same problem running the script file with the foo.lsp trying to create the dxf using the same filename which is why I added the -R12 suffix. I think this is caused by AutoCAD holding on to the dxf after opening it and not allowing it to be overwritten while running inside the script.

Since you want to preserve the filename, the way to get around this is to create a subfolder "DXF-R12" and save the dxf there keeping the filename intact. So the code change inside foo.lsp looks like this:

 ; add suffix to drawing name
 ; (setq dwg (strcat(getvar"dwgprefix")(vl-filename-base(getvar"dwgname"))"-R12")) 
 ; create DXF-R12 subfolder to save dxf there using same filename
   (setq dwg (strcat (getvar"dwgprefix") "DXF-R12"))
   (if (not (vl-file-directory-p dwg))(vl-mkdir dwg))
   (setq dwg (strcat dwg "\\" (vl-filename-base(getvar"dwgname"))))

Save the attachment overwriting the previous as the latest foo.lsp and run it again using Script Writer for dxf.

As they say: "necessity is the mother of invention" So when AutoCAD fails at least programming is available to make up for it.  Let me know how this works out for you.

 


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

cadman777
Advisor
Advisor

@paullimapa 

Thanks for your explanation and lsp revision.

I appreciate your help.

Unfortunately, I'm not interested in ANOTHER Autodesk WORKAROUND.

Please do not take that personally, b/c it's not directed at you.

It's just that I've been using Autodesk products since the late 80's, and have piled up sky high work-around-upon-work-around for AutoCAD and Inventor. Rhino3D doesn't have that problem. They have Grasshopper which works wonders without the work-arounds. Unfortunately Rhino3D is a surface modeler and isn't parametric, so it's not useful for the present work. Needless to say, I'm DONE with the myriad of work-arounds that Autodesk software requires. ALL of them should have been incorporated into their software long ago. I am FED-UP with workarounds, and don't have any more patience or capacity to memorize more of them. So at this point, I just want a solution what will work without any exceptions, exclusions, etc.

Bug thank you for your help, I really do appreciate it.

I notice you use VL lisp.

Is that VisualLisp?
I never learned that language, just pain LISP.

 

@ronjonp 

I've read a number of your past posts before coming in here with my issue.

You seem to be one of the resident experts in here.

So thanks for weighing-in on this.

I never knew about EXPERT, but it looks promising, thanks for the heads-up.

Let me try your code and see how it shakes-out, and then I'll get back with the results.

... 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 26 of 79

cadman777
Advisor
Advisor

Another caveat is the Explode command fails with an error if there are no explodable entities.

When that happens with a script file, it sends an error message for every entity that isn't explodable and the script hangs.

How do I fix these kinds of problems in a script file?

Where is the detailed documentation for each and every command that informs us how to use them properly in a Script file or Macro for every different scenario (exceptions, exclusions, etc.)?

At this point, I'm beginning to believe that Scripts are F**king joke.

They're another half-arsed trinket added to AutoCAD for marketing purposes.

Nothing I've ever used in Autodesk software is thorough, NOTHING.

If I did my job like that even once, I'd be on the bread line...

... 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 27 of 79

cadman777
Advisor
Advisor

OK, I tried it.

Your Qsave hangs.

I commented it out and reran.

Then your _DXFOUT hangs.

Too bad I can't remember any of the LISP I used to know!

... 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 28 of 79

cadman777
Advisor
Advisor

So far I've tried Scripting, Macros and forum LISP code and nothing has worked.

I tried them all in conjunction with a forum LISP script compiler and ScriptPro, and can't get it to work.

This simple thing I wanna do can't be this complex, can it

Maybe Autodesk should humble themselves and pay the McNeel group to write them a TRUE visual coding language that we all can use due to its drag-and-drop simplicity instead of WITHHOLDING the 'tools of the trade' from us so we are forced to rely on others to do the work for us when we SHOULD be able to do it ourselves?? WTF Autodesk!

... 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 29 of 79

paullimapa
Mentor
Mentor

AutoCAD while running within the script behaves a bit differently compared to just opening the dxf file alone. So it hangs onto it refusing to let any operation overwrite the dxf file. This is not the same with how dwg files are handled. 


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

paullimapa
Mentor
Mentor

If the simple code that selects all and attempts to explode all items selected is  hanging things up, I’m sure @ronjonp can very easily modify foo.lsp to accommodate. Just ask him nicely 


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

paullimapa
Mentor
Mentor

found this code that may deal with your explode issues and incorporate it into foo.lsp

give it a try

 


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

cadman777
Advisor
Advisor

Thanks for this code, Paul.

I'll see if I can get my head into it and let you know the results.

Just tried the link you provided and it was dead.

How did you link to it and I can't?

 

UPDATE:
It works without hanging. But if I close the dxf without saving, and then reopen it, it isn't saved to the new-and-improved state that the lsp routine was supposed to create. Why would that be?

... 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 33 of 79

cadman777
Advisor
Advisor

Hey @ronjonp, can you tell me how to cancel a command in a script file and have the script file continue to process the remaining commands? That's what I started this thread for, and that's really all I want to know how to do. I don't want some complex work-around for a simple function that SHOULD BE in the scripting language. I'm all ears...

... 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 34 of 79

paullimapa
Mentor
Mentor

After running Script Writer on a folder of DXFs or foo.lsp on a single DXF file, did you open the DXF file that's now saved in the subfolder DXF-R12 which is where the foo.lsp saves all the updated DXFs to see if it's now saved to the new-and-improved state?


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

cadman777
Advisor
Advisor

Sorry Paul, I missed that.

 

I guess I can consider that an acceptable work-around b/c I won't have to do any more work except delete the original files, move the new files into the old folder, then delete the new folder.

 

So let me test it with ScriptPro to see how it works.

 

UPDATE:

 

ScriptPro doesn't work.

It takes 3 minutes to process 1 drawing and most of them fail.

Maybe ScriptPro should be called ScriptNO or ScriptBLOW?

 

Another thing I tried that I didn't mention is make a tool button macro.

What I wanted to do (by concession!) is open a pile of dxf files, and then click the button once for each drawing.

But I wanted it to have the macro Close each drawing when it's done processing it so I can be ready to press the button once again for the next drawing...and so on.

I'm trying to do that with a macro, but having difficulties getting it to work.

The problem is, I don't know how to do any of this stuff using the basic rules of Scripts and Macros.

And LISP is out of the question for re-learning at this point in my life.

 

This is how I sounded in the iLogic forum. I was always bitching about this or that or some other complex thing. I learned a LOT of iLogic (and VBA), but never was able to learn enough to do any substantial coding. I spent A WHOLE GODDAMNED YEAR learning it on my own with a lotta help from the forum members but still couldn't do what I wanted to do. It was just too complex and required an extensive amount of learning that I didn't have the time or energy to do. If there's one thing I learned over the years it's, CODING IS A SEPARATE, FULL-TIME CAREER, not a simple past-time adjunct to a design and drafting career. People who can do BOTH WELL are the exception to the rule.

... 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 36 of 79

cadman777
Advisor
Advisor

No, everything is done in Mspace.

It's processing DXF sheetmetal flat patterns for importing into a nesting app.

... 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 37 of 79

paullimapa
Mentor
Mentor

Time to try the modified Script Writer that works with DXFs


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

paullimapa
Mentor
Mentor

I've not tried closing a drawing with a button macro but you can try by entering into the button this line for the macro:

^C^C(load"foo");foo;_.Close;_Y;


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

Kent1Cooper
Consultant
Consultant

@cadman777 wrote:

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.

....

 

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.


I haven't seen any actual Script file from you to evaluate, or even actual Script-formatted content.  [For instance, PEDIT does not have a top-level-prompt Join option, but only after the Multiple-selection option that you don't mention in the procedure outline above.]  But I did what you suggest, as far as the parts of the outline quoted above.  Just from the point of view of concluding PEDIT and going on to the next thing [switching to Paper Space], the attached works for me, in Acad2024.

 

The one surprising thing to me was that I expected to need another blank line [Enter] below the EXPLODE All line, to conclude its object selection, but somehow that's not wanted.  [The PEDIT command's Multiple selection does want that extra blank line, so I assume it must be Explode-specific -- related to the way it also works differently in an AutoLisp (command) function than at the Command line, without concluding selection and for only one object.  But here it can do more than one object.]

 

This doesn't get at your other issues [DXF file business, or Explode causing an error if there's nothing to Explode, ScriptPro], just the proof that it is possible in a Script file for a PEDIT command "to be shut down and the rest of the script resumed."

Kent Cooper, AIA
0 Likes
Message 40 of 79

cadman777
Advisor
Advisor

Thanks for taking the time, Kent.

Let me try it and get back to you.

Also, the reason I didn't post any script file is b/c I tried so many different permutations that it would have been futile to know which one to put up for review.

 

UPDATE:
Doesn't work.

Hangs on Explode like all the others.

Not sure why it works for you and not me.

 

Here is my original try at it, which looks a lot like yours:

ZOOM
E
Explode
All
PEDIT
M
ALL

Y
J


FILEDIA
0
QSAVE
DXF
16
V
LT2
16

Y
FILEDIA
1
... 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