Creating the AutoCAD scripts
Hi Everyone,
Wish you all a very happy and safe Diwali.
As I promise you in my first post of this series, today I am presenting you with an example of an AutoCAD Script.
For the friends who have just joined the series here is the link for previous post :
Part - 1
In this example, we are going to make an script to create a layer named "Circle" with linetype "continuous", color "red" and lineweight "0.25".
First Step is to go through the steps to create above said layer once,
This is what we go through with our command line to accomplish the task.
We have completed our first step. Now, copy this from the command line and paste it into a text file create by notepad. This is what we get :
I have added row numbers to make the discussion easier, these are not the part of actual script.
Noticed that “-“ before the command? This is to suppress the dialog boxes, that appear when we issue “layer” command. This is very important as script files can not access dialog boxes.
OK, So let us remove clutter from our script now. The only thing we need in our script are, the instruction or information we provide to AutoCAD while going through the process. So, we deleted all the command prompts from the scrip. and this is what we get:
You can compare the difference between the two, Second one seems much clearer. In the next step we are going to remove all the blank lines and add some some comments to make the script understandable.
Now the script should look like this:
Save this with .scr extension.
This guys, is your final script file. Now, fire AutoCAD & run the script as described in the Tutorial : Automation with scripts (Part 1).
This is a very simple script, but the concept of scripts is very powerful. Using this you can create a set of layers, set your system variables and do so on (I will keep coming back with more useful scripts for you).
Exercise for you : Use script to draw an object, that you use frequently in your drawings. This can be a steel beam cross-section, a foundation plan or a section of a foundation anything and come back with any problem you face. I would love to hear and solve them.
If you wish you can download the command line dump and final script here.
Note : This script was written for AutoCAD 2011, this may not work correctly for other versions.
In the next part of this series I will share another script with you and we will see how to run these scripts on multiple drawings.
Thanking You,
Abhay
Hi Everyone,
Wish you all a very happy and safe Diwali.
As I promise you in my first post of this series, today I am presenting you with an example of an AutoCAD Script.
For the friends who have just joined the series here is the link for previous post :
Part - 1
In this example, we are going to make an script to create a layer named "Circle" with linetype "continuous", color "red" and lineweight "0.25".
First Step is to go through the steps to create above said layer once,
This is what we go through with our command line to accomplish the task.
We have completed our first step. Now, copy this from the command line and paste it into a text file create by notepad. This is what we get :
I have added row numbers to make the discussion easier, these are not the part of actual script.
Noticed that “-“ before the command? This is to suppress the dialog boxes, that appear when we issue “layer” command. This is very important as script files can not access dialog boxes.
OK, So let us remove clutter from our script now. The only thing we need in our script are, the instruction or information we provide to AutoCAD while going through the process. So, we deleted all the command prompts from the scrip. and this is what we get:
You can compare the difference between the two, Second one seems much clearer. In the next step we are going to remove all the blank lines and add some some comments to make the script understandable.
Now the script should look like this:
Save this with .scr extension.
This guys, is your final script file. Now, fire AutoCAD & run the script as described in the Tutorial : Automation with scripts (Part 1).
This is a very simple script, but the concept of scripts is very powerful. Using this you can create a set of layers, set your system variables and do so on (I will keep coming back with more useful scripts for you).
Exercise for you : Use script to draw an object, that you use frequently in your drawings. This can be a steel beam cross-section, a foundation plan or a section of a foundation anything and come back with any problem you face. I would love to hear and solve them.
If you wish you can download the command line dump and final script here.
Note : This script was written for AutoCAD 2011, this may not work correctly for other versions.
In the next part of this series I will share another script with you and we will see how to run these scripts on multiple drawings.
Thanking You,
Abhay
It may be a good idea to include which version of AutoCAD the script was written for as certain commands can change from version to version.
ReplyDeleteOne example of this is the SPLINE command which was changed in AutoCAD 2011.
The command now has an extra method to draw a spline which is called....CV (control vertices).
Tony,
ReplyDeleteThanks a lot for your feedback. I am revising the post. incorporating the AutoCAD version.
Another subscriber noticed that the link for the download did not work. I have now fixed the same. Any of you who has any problem downloading the files please let me know.
ReplyDeletevery usefull for CADians
ReplyDelete