IF statement in a .scr file

IF statement in a .scr file

GMart1997
Participant Participant
3,370 Views
7 Replies
Message 1 of 8

IF statement in a .scr file

GMart1997
Participant
Participant

I have a scrip that is fairly simple... in the starting stages, but I am under the impression that in .scr files, you can't have "logic" so to speaks.  Meaning, I wasn't sure if I can put an 'IF' / 'THEN' / 'ELES' statement in one.  Here's what I have.

 

FILEDIA
0
CMDDIA
0
sdi
0
OPEN
C:\Project\Test_001.dwg
-XREF
D
*
-IMAGE
D
*
DXFOUT

 

Something simple to detach xref's and images from a drawing before exporting to a dxf.  The issue is, what if that drawing doesn't exist?  As it stands, the script will bomb out and stop.  What I'd like it to do instead of bombing out... go to that directory and create the dxf, then finish the rest of the script.  Is that possible?

0 Likes
3,371 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

No if statements in a script file. But you can do this using AutoLisp.  Is there a reason why you don't want to create a lisp code to do this?

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales |Exchange App Store


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

GMart1997
Participant
Participant

We're trying to automate a process without having to manually go inside AutoCAD and running the lisp routine.  And because I don't really know how to write lisp routines. 🙂

0 Likes
Message 4 of 8

paullimapa
Mentor
Mentor

If you're calling these scripts to run outside of AutoCAD and using the good old DOS batch file commands, you may want to look into the

"IF EXIST ... ELSE ..." code:

http://www.msfn.org/board/topic/143962-batch-dont-work-if-file-exist-run-else-exit/

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator
Layer Apps | List on Steroids | VP Zoom Scales |Exchange App Store


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

GMart1997
Participant
Participant

Ok, thanks.  I'll look into it.

0 Likes
Message 6 of 8

doni49
Mentor
Mentor

In addition, the script could also call autolisp functions.  So although scripts can't do if tests, you can get around it.  For example

 

If you wanted your script run the IMAGE command only if a certain setting (setvar) contains a specific value:

 

(if (EQ(getvar "myvar") 1)(command "-Image" "D" "*"))

 Now you'd put that instead of

-IMAGE
D
*

Autolisp is a pretty powerful language and once you get the hang of it, it's actually pretty simple.

 

Here are a few resources to help get a handle on it.

 

www.AfraLISP.net
www.JefferyPSanders.com
www.Lee-Mac.com



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 7 of 8

Anonymous
Not applicable
 
0 Likes
Message 8 of 8

Anonymous
Not applicable

tbayxxxvii,

 

(please Ignore my previous Post, this one is more Visual... )

 

If I understand correctly, you have bunch of .dwg files in a certain folder and you want to run one script file inside each one of the drawings inside that folder. assuming that you are using Windows as an OS.

 

In this case your best bet is to create a .bat file with the following statement:

 

FOR %%f IN ("C:\Project\*.dwg") DO "C:\Program Files\Autodesk\AutoCAD 2014\accoreconsole.exe" /i "%%f" /s "C:\Scripts\ScriptFileName.scr"

Save it as .bat and double click and it should work fine.

 

Please note that:

  1. The "C:\Project\*.dwg" is the folder of your choosing the *.dwg is to run the script on every file in the mentioned folder.
  2. DO "C:\Program Files\Autodesk\AutoCAD 2014\accoreconsole.exe" please make sure that the location of the "accoreconsole.exe" is correct, by default it is in this location make sure to check the "program files vs. Program files 86" folders for AutoCAD.... and the AutoCAD 2014, AutoCAD 2015 depending on what of your product year?
  3. C:\Scripts\ScriptFileName.scr is the location where you save your script file.
  4. Add qsave at the end of your script file so the batch file does not stop and ask you if you want to save.
  5. make sure all dwg files are closed because it will stop and ask you if you want to open read only.

 

If you need further expolaination please let me know.

 

Sincerely,

Sean

0 Likes