Thursday, November 10, 2011

"Invisible" problems in AutoCAD script files

Even with all of the AutoCAD programming enhancements and version upgrades over the years, script files still can provide a streamlined way to automate AutoCAD functionality. Another attractive feature about script files is they are simple (and fun!) to create.

A script file is essentially a macro that will execute a series of AutoCAD commands. Repetitive tasks in AutoCAD present an opportunity for automation. Automation can mean everything from developing a high-powered .dll application, to an AutoLISP application, to a script file.

There is not a lot of syntax to worry about in a script file (except for invisible problems...keep reading) and the contents of the file should mimic the command line in AutoCAD.

Here is an example of a script file that creates a new layer, assigns the color, and sets it current:

(Note: the green comments are not part of the actual script file. Script files can be created using notepad and saving as a .scr file extension)

-LAYER      use the dash to suppress the command dialog
N           choose new option
SLD-EXAMPLE define layer name
C           choose color option
CYAN        define color
SLD-EXAMPLE specify layer to receive color
S           choose set option
SLD-EXAMPLE specify layer to set current


Now, the reason that inspired me to write this post is an invisible problem when troubleshooting a script. What I mean by invisible are blank (space) characters. AutoCAD treats the "space" character as an Enter (remember, it is identical to the command line in AutoCAD). If there is an extra "space" at the end of one of your lines in the script your command sequence will be off track. The best way to troubleshoot this is to notice where the script is breaking during runtime and then look near that line of code for an extra space. Another invisible problem is if there is not an EOL (carriage return) at the end of your last command the script file will not close out completely when executed. Remember to always enter a carriage return after your last command. Which leads to the final invisible problem which is if you have more than 1 carriage return at the end of a script file. This will invoke the last AutoCAD command that was executed during the script file.


These invisible problems have caught me off guard a time or two so hopefully this is a helpful clarification (or reminder) to be careful about extra spaces and carriage returns in your script files.

1 comment:

  1. Streamlined Design: "Invisible" Problems In Autocad Script Files >>>>> Download Now

    >>>>> Download Full

    Streamlined Design: "Invisible" Problems In Autocad Script Files >>>>> Download LINK

    >>>>> Download Now

    Streamlined Design: "Invisible" Problems In Autocad Script Files >>>>> Download Full

    >>>>> Download LINK F4

    ReplyDelete