stop command in script

stop command in script

cadman777
Advisor Advisor
11,387 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,388 Views
78 Replies
Replies (78)
Message 41 of 79

cadman777
Advisor
Advisor

Yes Paul, I just read through this thread from the beginning and was reminded of it, so gave it a try.

It failed, but I need to review if I'm setting it up right to verify that it's not working.

Will get back to you when finished.

 

UPDATE:

Didn't work.

This is what I typed in the ScriptLine:

_.open *file* (load "e:/foo4.lsp") (foo4) _close

I couldn't find a clear statement for syntax with this app.

Is that correct?

 

When I type 'foo4' (no quotes) at the command prompt, it runs perfectly.

 

I also tried adding to the foo4.lsp file this line at various places near the end to close the file and it failed:

 

(command "Close" "N")

 

Can't make heads nor tails of this mess.

It's like a Chinaman trying to talk to a Greek who's trying to talk to a Brit, who's trying to talk to Saudi Muslim.

All speaking a different language, no meeting of the minds.

In the industry we call that a CLUSTER F**K.

 

Anyway, would you be so kind as to add a CloseFile to the end of the lsp file so I can run it off a toolbar button?

I don't mind pressing a button 200x to get a pack of DXF's processed.

It beats 5k presses resulting from doing the same thing to every file one at a time, one change at a time!

 

One of the things I bitched about in this forum and in the Inventor forum when I gave a shyt about product enhancements has to do with data management. I told them that the more data you can CREATE, the more data you must QC. That means you are adding to a person's work load exponentially. So not only does he have to create the data, but he also has to process it in a meaningful way (drawing creation), as well as QC it (checking). That also means the software is needs better tools for managing that data. That's where coding comes into play. But since most of us can't code, we need built-in functions/commands to do the tedious tasks that increased volumes of data require. The best way to do that is with a SIMPLE USER FRIENDLY MACRO LANGUAGE. That requires some savvy and work on the part of the developers to create commands that can process the data categorically. But after over THIRTY YEARS OF WAITING, where are those tools???

 

Let me give you an example of a structural job I once did using Inventor. I have a number of Inventor customizations that do a lot of the repetitive work for me, thanks to the experts in the Inventor Customization forum (and a bit of hacking around on my part). Saves an amazing amount of time and reduces the RSI to a minimum. But one thing that I could never automate with Inventor is 'automatic detail drawings' like the structural software easily does. I bitched and moaned abut that for years to no effect. Well, this one job came along and I had SEVENTY TWO SHEETS OF DRAWINGS that I had to create and QC. 1/3 of them were details (angles, w-beams, pipes, channels, formed plates, flat patterns, weldments assemblies, concrete work, and construction drawings. All the sheets were packed with infor, every square inch. All done MANUALLY b/c the developers REFUSE to add a simple function like the structural software has. These kinds of jobs that I do don't play well w/the structural software due to the custom nature of them, so renting structural software is a red light. But if I had 'automatic drawings' for the weldments and single parts, that would've saved me about a WEEK of work. So that ought to show you how important INTELLIGENT, ROUTINE DEVELOPMENT of CAD software is, like in this case. All they needed to do is add a script function that would cancel a command and give the option to either terminate the script or continue processing it. That's what I'm talking about.

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

Kent1Cooper
Consultant
Consultant

@cadman777 wrote:

....

Doesn't work.

Hangs on Explode like all the others.

Not sure why it works for you and not me.

....


So the current problem [in the area I've been concerned with, not the file-creation side] is not, in fact, about stopping the PEDIT command and continuing with the rest, but it's about Exploding -- was your test again in a situation with nothing to Explode, as in your earlier Messages?  Maybe it worked for me only because I did have Explodable things.

 

Scripts can use AutoLisp, at least within certain limits, so....

 

On the assumption that what you're Exploding are only LWPolylines [other kinds of Explodable things can easily be added in], I tried this.  I find it works if there are Polylines, and even if there are none of those to Explode, but only some contiguous Line objects, by checking whether there are any, to know whether to Explode:

 

_.ZOOM _Extents
(if (ssget "_X" '((0 . "LWPOLYLINE"))) (command "_.explode" "_all"))
_.PEDIT _Multiple _All

_Join


Tilemode 0

 

Again, it only goes far enough to find that PEDIT can be concluded [it does Join the Lines in either case] and it can go on to the next thing.  But this version accounts for whether or not there's anything to Explode.

Kent Cooper, AIA
0 Likes
Message 43 of 79

paullimapa
Mentor
Mentor

this is what happens when there have been so many posts back and forth and changes in between

But use for the Script Line:

_.Open *file* (load"e:/foo4") (c:foo4) _.Close _Y

Adding the Y at the end is very important since you've made changes to the opened DXF and AutoCAD will prompt you to quit changes before closing.

Also, the above line of code assumes you've changed the lisp to filename foo4.lsp and within the file you've changed the command to look like this: (defun c:foo4

Also again very important is that since you've saved foo4.lsp in E:\

inorder for the code to load and run, you'll need to add this path to Trusted under AutoCAD's command OPTIONS>FILES>Trusted Locations:

paullimapa_0-1690750336577.png

This is all in the name of security so that some virus won't force code to load and run without your consent

 


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

cadman777
Advisor
Advisor

Thanks for the timely reply.

Why do you put 'c:' before 'foo4'?

Everyone else I read just puts the command in parens without the 'c:'.

Also, if the lsp file saved the part already, why would you use 'y' instead of 'n' on close?

All the rest of it I knew to do, so that's not at issue.

I only needed the syntax for that app.

But thanx for confirming it anyway.

I'll try adding the 'c:' tomorrow to see how it works and get back to you.

Incidentally, the workstation is permanently offline, so I never have to worry about viruses, spyware, etc.

Besides that, I read some coders rant about that b.s. Autodesk thing b/c it really gets in the way of running code and really doesn't do much to protect the computer system.

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

paullimapa
Mentor
Mentor

Q1: "Why do you put 'c:' before 'foo4'?"

Typically when you want to add a command using lisp to run in AutoCAD that does not require any arguments you could define the function with a c: like (defun c:foo4

Then to run the lisp function at the command prompt just simply enter like any other typical AutoCAD command:

foo4

or the following would also work:

(c:foo4)

But if you need to pass predetermine variables called arguments so the lisp function can process  them within the code without further request for input then you would leave the c: out so the define function will look like (defun foo4

Now to run this at the AutoCAD command prompt you'll have to enclose the function name with open & close parenthesis like this: 

(foo4)

Now to pass say two arguments into the foo function to process you can then modify the define function code to look like this:

(defun foo4 (arg1 arg2)

Now to feed to foo4 with the following two strings as arguments: "This is 1" "This is 2"

at the AutoCAD command prompt enter:

(foo4 "This is 1" This is 2")

Q2: "Also, if the lsp file saved the part already, why would you use 'y' instead of 'n' on close?"

Now bear in mind the lisp file did not save over the DXF file because after all the attempts you've tried to overwrite it, AutoCAD refuses to let you do this. So we're now saving the DXF as a separate file in a separate folder location. Since all the changes processed with the lisp function still occurred in the currently opened DXF file, AutoCAD knowing that there's been a change in the drawing database, will prompt for saving the file before closing.

This can be seen when entering the exact command using lisp at the AutoCAD command line:

(command "_.Close" "_N")

_.close Really want to discard all changes to drawing? <N>

When "_N" is used as the response, AutoCAD will not CLOSE the DXF file but will continue to request you select a file format to save the DXF thus stopping the lisp/script file from finishing:

paullimapa_1-1690772092486.png

So in order to properly CLOSE out of the DXF file without saving, the proper command sequence is:

(command "_.Close" "_Y")

The "_Y" tells AutoCAD you really want to quit the DXF file without doing a Save.

 

So based on my answers to your questions above, this is why for the Script Line the proper syntax to use is:

_.Open *file* (load"e:/foo4") (c:foo4) _.Close _Y

or the following should also work:

_.Open *file* (load"e:/foo4") foo4 _.Close _Y


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

cadman777
Advisor
Advisor

Thanks for the detailed explanation.

 

Then to run the lisp function at the command prompt just simply enter like any
other typical AutoCAD command: 
foo4
or the following would also work:
(c:foo4)
Now to run this at the AutoCAD command prompt you'll have to enclose the function
name with open & close parenthesis like this: 
(foo4)

 

So which is it in a script file: c:foo4, (c:foo4), foo4 or (foo4)?

 

The reason I asked about the c: when invoking a command using lsp in a script is b/c all the people I found who explained how to do it didn't use the 'c:' to do it. Instead, they do it like this: (foo4). So that's what I did and it didn't work. But when I open a dxf and run the command at the command prompt, i merely type in foo4 and it runs w/no problems. So what has to happen for ScriptPro or wScript to successfully run this lisp routine from a script file?

 

The reason I asked about the 'y' vs. 'n' when invoking 'Close' is b/c the DB that appears when I invoke 'Close' is this:

cadman777_0-1690802516141.png

So I pick 'n' instead of 'y' b/c the file is already saved in a different directory and doesn't need to be saved again, which would raise a whole series of other issues that I don't want to 'code' for.

 

UPDATE:

 

I made a mistake by not clicking on the profile to check it after running foo4. I'm running AutoCAD 2010, so I've been using my own lsp JOIN command that I have always used instead of the native AutoCAD JOIN. But since I wanted to use native AutoCAD commands, that's why I used PEDIT to join the profile lines b/c AutoCAD JOIN requires a specific pick at the beginning which means it won't work in this scenario. Anyway, there are so many problems with how all of this is not working that I'm not sure what the standards are that work at this point.

 

So at this point it's BACK TO THE DRAWING BOARD (so to speak). So let's get back on track by way of review. I originally came in here to find an answer to this one simple question: What can I do to stop a command in a script and continue the script? That's what I want to know, and that alone. All this other stuff is unnecessarily complicating this otherwise simple request. It's going on a week and I still haven't found an answer to this SIMPLE REQUEST.

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

cadman777
Advisor
Advisor

UPDATE:

 

I finally figured out how to get this POS to work.

I used @ronjonp's initial code and modified it to this:

 

;NestFixBatchScript01.lsp
;Created ronjonp
;Date:   July of 2023
;Description:   Fix a DXF file for use in Nesting app
;;;;;;;;;;;;;start prog
(defun C:nfbs2 (/ 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" ""))
	   (vl-catch-all-apply 'vl-cmdf (list "_.Pedit" "_M" "_All" "" "Y" "J" "" ""))
	   ;; Quick Save as DXF12
       (command "_Qsave" "dxf" "v" "r12" 16 "" "y" "")
       (command "filedia" 1)
	   (command "Close")
    )
  )
  (princ)
)

 

It only works when run manually.

For some reason it doesn't work in ScriptPro.

Neither in wScriptDXF.

Also, I can't get it to run from a Macro button.

Not sure why YET.

What a pain in my balls!

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

paullimapa
Mentor
Mentor
Accepted solution

Q: "So which is it in a script file: c:foo4, (c:foo4), foo4 or (foo4)?

A: You must have missed the detail explanation I included which was:

"...define the function with a c: like (defun c:foo4

Then to run the lisp function at the command prompt just simply enter like any other typical AutoCAD command:

foo4

or the following would also work:

(c:foo4)

"...define function will look like (defun foo4

Now to run this at the AutoCAD command prompt you'll have to enclose the function name with open & close parenthesis like this: 

(foo4)

So to apply this to @ronjonp's lisp code, since it shows (defun c:nfbs2 then at AutoCAD's command prompt you would NOT use (nfbs2). This would fail. But you have to use either (c:nfbs2) or just nfbs2

paullimapa_0-1690820393431.png

 

Q: It only works when run manually. For some reason it doesn't work in ScriptPro. Neither in wScriptDXF.

Also, I can't get it to run from a Macro button. Not sure why YET.

A: I also answered this in my reply back in #29:

paullimapa_3-1690821134419.png

This means @ronjonp line of code which you added will fail when run inside a script:

;; Quick Save as DXF12
       (command "_Qsave" "dxf" "v" "r12" 16 "" "y" "")

This is why I replied back in # 24:

paullimapa_1-1690821016353.png

The above explanation should also partially answer next question:

paullimapa_4-1690821256880.png

AutoCAD responds differently when you enter the CLOSE command at the command prompt using:

CLOSE vs (command "CLOSE")

When you type CLOSE, yes, you'll see that dialog box. But when you run this in a lisp file using (command"CLOSE") you'll get a different request as I stated again in detail in my most recent reply:

paullimapa_5-1690821446042.png

Finally....

Q: "I originally came in here to find an answer to this one simple question: What can I do to stop a command in a script and continue the script? "

A: My replay back in msg 6

paullimapa_6-1690821492141.png

But if your meaning "to stop a command" is to manually cancel it so the script can continue to the next command then the answer is NO you cannot. You can only pause a script while it's in action and then resume from where it's paused. But if you cancel it by like hitting the Escape key on the keyboard then the script just ceases to continue like a typical AutoCAD command after cancelling.  

 

 


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

cadman777
Advisor
Advisor

I appreciate your detailed explanations Paul.

The problem here is I don't have a ready reference to look up any given command and see what it's syntax is supposed to be when used:

1. at the command prompt

2. in scriipts

3. in lisp

4. in vba.

So at this point, I'm nit picking this stuff in bits and pieces from you guys in this forum.

Please tell me where I can download a pdf file with this info in it.

That way I can figure this out for myself.

I have to say, Autodesk has been severely negligent in this area, b/c I ran into the same exact SHYT with Inventor when learning iLogic and VBA for Inventor. WTF?!? Are we supposed to mentally absorb this myriad pile of info from the vacuum spaces in the air?

 

Anyway, I appreciate your help, but I REALLY need a BOOK that LISTS all the commands in ALPHA-NUMERIC ORDER that spells out the SYNTAX for each application, the way I said above. This haphazard piecemeal method of absorbing all these details DOES NOT WORK FOR ME.

 

So please tell me where I can download a pdf with this info in it.

 

Thanx...

 

PS: The fact that you have to absorb and micromanage such a vast amount of information just to automate a simple task like the one I want to do is evidence that Autodesk is operating a goddamned criminal syndicate. Common sense tells us that, if we have the eyes to see it. I remember when I used SolidWorks. If we had a function that we needed, they were quick to add it to the software. They were not so quick to make changes to the drawing environment, I will admit, but functions for modeling they were very keen on adding. But Autodesk...WTF??

 

Tell me Paul, would you agree that having to navigate this massive obstacle course just to accomplish a simple automation is UNREASONABLE?

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

cadman777
Advisor
Advisor

Where did someone tell me this earlier on in this thread?

 

But if your meaning "to stop a command" is to manually cancel it so the script
can continue to the next command then the answer is NO you cannot. ...
But if you cancel it by like hitting the Escape key on the keyboard
then the script just ceases to continue like a typical AutoCAD command after cancelling.

 

 

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

paullimapa
Mentor
Mentor

Unfortunately, as with any app, consistent implementation and exploration is required to learn the ins & outs and this is especially true of AutoCAD. AutoCAD typically provides the latest & greatest manuals now all on-line for reference.

For example the Customization Guide for 2024 can be found here:

https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-91E01021-96F3-47E8-944D-72BC90BA06CC

Unfortunately, this only goes as far back as version 2018. So you are out of luck with your stone age version of AutoCAD. But there are lots of resources on-line. I've learned tons now with so much of wealth of information shared by others on this forum as well as others. But unless you have the time to explore, experiment & trial & error, then this will be tough to learn & pick up.


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

paullimapa
Mentor
Mentor

because we all got sidetrack with the programming...but at least you got your answer now.


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

john.kaulB9QW2
Advocate
Advocate

Scriptpro is horrible (to be fair, I used it a few times years ago). I coded up a windows batchscript thing that uses accoreconsole (it runs scripts, keeps a log file, and does NOT hold your hand). If you want a link to that let me know and you'd have to sign up to get to the link. HOWEVER, theswamp is a serious programmers forum (don't just sign up to get the tool and never come back--I feel like my script tool might be a bit above your head so you may want to stick with ScriptPro if you can get it working for you).

 

I only glanced at the code you're trying to run, but I was wondering why everything was wrapped up in an IF? `Cancel command`. Do you guys mean something like what I do for the `explode` section below (-i.e. if the explode command hangs, I escape out)?

(defun nfbs2 ( / ss)
  (defun *error* (msg) (mapcar 'eval #error_lst#) (setq #error_lst# nil))
  (defun *error-push-vars* (lst / push->lst)
    (defun push->lst (sym lst) (set lst (cons sym (eval lst))))
    (mapcar
      (function
        (lambda (x)
          (push->lst
            (list 'setvar (car x) (getvar (car x)))
            '#error_lst#)
          (if (cadr x) (setvar (car x) (cadr x)))))
      lst
      )
    )

  (*error-push-vars* '(("TILEMODE" 1) ("FILEDIA" 0)))
  ;; set vars and save initial values for resetting back later.
  ;; 
  ;; -I'm not sure why tilemode needs to be switched.

  ;; zoom extents. 
  ;; - I'm not sure why zoom is needed.
  (command "_.zoom" "extents")

  ;; -Initial code wrapped everything in a IF, I assume this was 
  ;; only to explode the items found in MS and not the `dxfout`, 
  ;; `close`, etc. commands. 
  (set 'ss (ssget "_X" '((410 . "Model"))))
  (if ss 
    (progn
      (command "_.explode" ss ) ;; -Explode the Selection set.
      (command) (command)       ;; -Cancle the command if it hangs.
      )
    )

  (command "_.pedit" "_M" "_All" "" "Y" "J" "" "")      ;; -I assume this shouldnt be wrapped up in the IF.

    (command "_.dxfout" (strcat 
                          (getvar 'DWGPREFIX) 
                          (vl-filename-base (getvar 'DWGNAME)) ".dxf") 
             "Version" "lt22" "16" "")

 (quit)                         ;; -Reset the variables that were changed.
 )

 

another swamper
0 Likes
Message 54 of 79

cadman777
Advisor
Advisor

Here's a revision to my last lsp that works manually and in a Macro.

But it doesn't work in ScriptPro or wScriptDXF.

I don't know why and don't know how to make the screen go 'verbose'.

 

 

;NestFixBatchScript03.lsp
;Created ronjonp
;Date:   July of 2023
;Description:   Fix a DXF file for use in Nesting app
;;;;;;;;;;;;;start prog
(defun C:nfbs3 (/ s)
  ;; To modelspace?
  ; 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))(setvar 'tilemode 1)
   (setq dwg (strcat dwg "\\" (vl-filename-base(getvar"dwgname"))))
  ;; 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" ""))
	   (vl-catch-all-apply 'vl-cmdf (list "_.Pedit" "_M" "_All" "" "Y" "J" "" ""))
	   ;; Quick Save as DXF12
       ;(command "_Qsave" "dxf" "v" "r12" 16 "" "y")
       ;; Add your line to save as DXF12 below replacing over current dxf
       (vl-cmdf "_.DXFOUT" dwg "_V" "_R12" "16")
	   ;(command "filedia" 1)
	   (command "Close" "y")
    )
  )
  (princ)
)

 

I fixed it by adding that 'make directory' thing you did as a WORK-AROUND to this cluster-f**k of lsp. At least it works in a Macro. Now I'm off to look at John's code to see if I can learn something that will help and be easier than 'holding my hand' while the routine runs.

 

At least NOW if I can't go any further, I can LIMP ALONG with this hack job...

 

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

cadman777
Advisor
Advisor

Thanks for weighing in John.

Yeah, I've seen some posts in the Swamp along the way this time around.

I'm no coder, so the Swamp may not be for me.

Not enough time to dedicate to it.

But thanx for sharing your code.

I'm going to see how it works and try to do something with it.

Will get back to you...

 

FYI:

 

(defun nfbs2 ( / ss)
  (defun *error* (msg) (mapcar 'eval #error_lst#) (setq #error_lst# nil))
  (defun *error-push-vars* (lst / push->lst)
    (defun push->lst (sym lst) (set lst (cons sym (eval lst))))
    (mapcar
      (function
        (lambda (x)
          (push->lst
            (list 'setvar (car x) (getvar (car x)))
            '#error_lst#)
          (if (cadr x) (setvar (car x) (cadr x)))))
      lst
      )
    )

  (*error-push-vars* '(("TILEMODE" 1) ("FILEDIA" 0)))
  ;; set vars and save initial values for resetting back later.
  ;; 
  ;; -I'm not sure why tilemode needs to be switched.
  ;; IT DOESN'T

  ;; zoom extents. 
  ;; - I'm not sure why zoom is needed.
  ;; THE DXF PROFILE EXPORTS SO ONLY A SMALL PIECE OF IT CAN BE SEEN.
  ;; THE BURN TABLE GUYS NEED TO SEE THE WHOLE THING
  ;; ZOOM E IT SAVES THEM TIME AND EFFORT
  (command "_.zoom" "extents")

  ;; -Initial code wrapped everything in a IF, I assume this was 
  ;; only to explode the items found in MS and not the `dxfout`, 
  ;; `close`, etc. commands. 
  '' NOT SURE B/C HAVEN'T LOOKED CLOSELY AT THAT.
  (set 'ss (ssget "_X" '((410 . "Model"))))
  (if ss 
    (progn
      (command "_.explode" ss ) ;; -Explode the Selection set.
      (command) (command)       ;; -Cancle the command if it hangs.
      )
    )

  (command "_.pedit" "_M" "_All" "" "Y" "J" "" "")    
  ;; -I assume this shouldnt be wrapped up in the IF.
  ;; CORRECT
    (command "_.dxfout" (strcat 
                          (getvar 'DWGPREFIX) 
                          (vl-filename-base (getvar 'DWGNAME)) ".dxf") 
             "Version" "lt22" "16" "")

 (quit)                         ;; -Reset the variables that were changed.
 )

 

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

john.kaulB9QW2
Advocate
Advocate

You could write down what you want to do in simple statements which will help a programmer write up what you want/need. Aside: that is a simple exercise done in intro to computer science classes (which is a lot of fun to watch when someone "dump an entire pitcher of water on the lectern"). 

 

For example:
1. switch to modelspace
   1a. I want to leave the drawing in model space.
2. zoom extents
   2a. I want to leave the drawing showing all items found in modelspace.
3. explode all items in model space
   3a. I don't like blocks...
4. dxfout to drawing to a folder.
   4a. I don't like networks, so I want all drawings on my C: drive.
5. make coffee.
6. save drawing.
7. quit drawing.

another swamper
0 Likes
Message 57 of 79

cadman777
Advisor
Advisor

I agree.

I learned that in CIM class in the late 80's.

And that I did in abbreviated form @ MESSAGE 10 of this thread (minus the beverages)

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

cadman777
Advisor
Advisor
Accepted solution

Here's my final working version that I put on a Macro button to press my way through a stack of drawings. It certainly is not ideal, but at least I can get the job done at the rate of 1 second per drawing instead of 1 minute per drawing. Saves on the RSI as well. Hopefully I'll have time in the near future to try to get this to run independently as a batch applet. No thanks to Autodesk for providing such a lame POS programming environment. A special thanks goes out to @paullimapa and especially to @ronjonp for generously offering their valuable skills in this endeavor!

 

;NestFixBatchScript03.lsp
;Created ronjonp
;Date:   July of 2023
;Description:   Fix a DXF file for use in Nesting app
;;;;;;;;;;;;;start prog
(defun C:nfbs3 (/ s)
  ;; To modelspace?
  ; 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))(setvar 'tilemode 1)
   (setq dwg (strcat dwg "\\" (vl-filename-base(getvar"dwgname"))))
  ;; Zoom everything
   (command "_Zoom" "_Extents")
  ;; If we have a selection in modelspace
  (if (setq s (ssget "_X" '((410 . "Model"))))
    (progn 
	   ;; Explode
	   (vl-catch-all-apply 'vl-cmdf (list "_.Explode" s ""))
	   ;; Join
	   (initcommandversion)
	   ;(vl-catch-all-apply 'vl-cmdf (list "_.Join" "_All" ""))
	   (vl-catch-all-apply 'vl-cmdf (list "_.Pedit" "_M" "_All" "" "Y" "J" "" ""))
	   ;; Quick Save as DXF12
       ;(command "_Qsave" "dxf" "v" "r12" 16 "" "y")
       ;; Add your line to save as DXF12 below replacing over current dxf
       (vl-cmdf "_.DXFOUT" dwg "_V" "_R12" "16")
	   ;(command "filedia" 1)
	   (command "Close" "y")
    )
  )
  (princ)
)

 

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

paullimapa
Mentor
Mentor
Accepted solution

since you included this inside your lisp: (command "Close" "y") 

then when you run WScript, the Script Line should no longer include the CLOSE command. 

So when the Script Line is changed to look like this then it works:

_.Open *file* (load"e:/nfbs3") (c:nfbs3)

paullimapa_0-1690831308423.png

It's like a domino affect...one thing changes impacts other things downstream...

 


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

ronjonp
Mentor
Mentor

@cadman777 wrote:

Here's my final working version that I put on a Macro button to press my way through a stack of drawings. It certainly is not ideal, but at least I can get the job done at the rate of 1 second per drawing instead of 1 minute per drawing. Saves on the RSI as well. Hopefully I'll have time in the near future to try to get this to run independently as a batch applet. No thanks to Autodesk for providing such a lame POS programming environment. A special thanks goes out to @paullimapa and especially to @ronjonp for generously offering their valuable skills in this endeavor!


 So where is the code hanging when run from a script? Sorry if I missed something already, this thread TLDR. 😃

0 Likes