Sunday, September 30, 2007

System Variables I Cannot Live Without - The Top Ten List

System variables have been one of the most important aspects of AutoCAD throughout its history.I wonder how complicated the life would have been without these tiny little masters. Here goes a few of them I cannot live without.
  1. FILEDIA - Suppresses display of the file dialog boxes. This is the culprit behind one of the most commonly asked questions by the newcomers about missing file dialog box.
  2. MIRRTEXT - Controls how the MIRROR command reflects text.Ignorance of this system variable may double your work at times.
  3. PICKFIRST - Controls whether you select objects before (noun-verb selection) or after you issue a command.For the beginners, I would suggest to keep the noun-verb selection off until they become familiar with the normal selection methods.
  4. LTSCALE - Sets the global linetype scale factor.It's required to be setup as per the drawing scale with each new drawing to get proper linetype display.
  5. DIMSCALE - Sets the overall scale factor applied to dimensioning variables that specify sizes, distances, or offsets.As in the case of LTSCALE variable, this is also required to be setup properly at the beginning of each new drawing to get proper dimension display.
  6. SNAPANG - Sets the snap and grid rotation angle for the current viewport relative to the current UCS.I often use this variable to draw something at a certain angle.
  7. EDGEMODE - Controls how the TRIM and EXTEND commands determine cutting and boundary edges.A must know variable for neat TRIM and EXTEND operations.
  8. ATTREQ - Determines whether the INSERT command uses default attribute settings during insertion of blocks.Setting it to 0 will avoid attribute prompts at the time of block insertion.
  9. MODEMACRO - Displays a text string on the status line, such as the name of the current drawing, time/date stamp, or special modes.Very interesting and powerful when DIESEL expressions are used inside.
  10. USERIx/Rx/Sx - Used for storage and retrieval of user-defined integer/real/string values. Very handy variables to store values for macro operations.
As you can see, it was really tough to select only ten out of hundreds of useful ones.Anyway, top ten is always top ten.Your top ten may vary depending upon the way and field of your work (For example 3D guys will have another story to tell you).If you feel that I have left out any inevitable ones, feel free to point it out here.Finally, here is a list of some system variables which could not make it to the top ten list, but still worthy enough to make your life a lot easier.
  • SDI
  • CTAB

Wednesday, September 26, 2007

Perform Loop Operations in AutoCAD LT using DIESEL

It's well known fact that you can not perform loop operations using DIESEL as you do in AutoLISP or other powerful programming languages. Isn't it really frustrating to have given up so many interesting tasks due to the absence of loop structures inside DIESEL? Let's give a try to stretch the LT limits a little bit and see how to mimic the loop operations using DIESEL.

The following macro illustrates how to use DIESEL to perfrom a loop operation. This macro calculates the factorial of a given number by iterating a required number of times. You can use the same logic to create various loop structures as per your requirement.

*^C^C$M=$(if,$(<=,$(getvar,USERI2),$(getvar,USERI1)),setvar;USERI3;$M=$(if,$(=,$(getvar,USERI2),1),1,$(*,$(getvar,USERI2),$(getvar,USERI3)));setvar;USERI2;$(+,$(getvar,USERI2),1),_modemacro;"The factorial of "$(getvar,USERI1)" is "$(getvar,USERI3);^C)

Before using the above macro, you need to run a simple macro to set up the user variables and the status bar. You need to supply the required number at the USERI1 prompt.


Isn't it quite simple to do an iteration using DIESEL? Basically a loop macro has the following componetns.

  • *^C^C in the beginning to have continuous operations
  • A conditional statement using a counter variable to continuously check against the loop upper limit.
  • If the condition is not met, do the required operations and continue.
  • If the condition is met, then terminate the macro using ^C at the end.
Since I have used USERIx system variables, you can not calculate factorials for numbers greater than 7 using the above macro (due to integer limit). If you need to have silent mathematical operations, you could better try with SETENV and GETENV instead of SETVAR and GETVAR. Try to experiment with this and come up with new interesting macros. Best of luck for your efforts...!!

Thursday, September 20, 2007

Total Area and Perimeter Calculation Macro

As a continuation to my previous post Total Length Calculation Macro for AutoCAD LT, here is another one to calculate total area and perimeter of selected objects. This macro has a few limitations.

1. You need to end the macro with a cancel (Esc) action.
2. The macro will be terminated upon picking up an object which doesn't have area.
3. Calculates area only by object method. Area calculation by continous picking of points are not supported.

Even after all these limitations, if you are interested, here goes the macro.

*^C^C_Area;O;\setvar;USERR1;$M=$(+,$(getvar,USERR1),$(getvar,AREA));setvar;USERR2;$M=$(+,$(getvar,USERR2),$(getvar,PERIMETER));_modemacro;"Total Area :"$(+,$(getvar,USERR1),$(getvar,AREA))", Total Perimeter :"$(+,$(getvar,USERR2),$(getvar,PERIMETER));

As in the case of length calculation macro, you need to use another macro for clearing the status bar and system variables.


Wednesday, September 19, 2007

Toggle AutoCAD Application Visibility

We can do a lot AutoCAD related programming outside AutoCAD using Windows Script Host. Some of the areas where windows scripting is useful are network management, windows registry manipulation, file or folder acces etc. Here is a sample VBScript code to toggle AutoCAD application visibility state.

On Error Resume Next
Set ObjACAD = GetObject(, "AutoCAD.Application")
If Err.Number <> 0 Then Err.Clear
MsgBox "AutoCAD is not currently running...!!", vbExclamation
If ObjACAD.Visible = True Then
ObjACAD.Visible = False
ObjACAD.Visible = True
End If
End If
Set ObjACAD = Nothing

Just copy the code and paste it inside notepad and save it with a vbs extension. Run the the file while AutoCAD is open. It will toggle the application display everytime you run it. Now you can leave your PC with peace of mind that nobody would interfere with your opened drawings.

Thursday, September 13, 2007

Quick Tip - Move Text Inside Text Edit Dialog

Before moving

Now I drag YOU and drop in front of CAN ;-)

Saturday, September 8, 2007

Total Length Calculation Macro for AutoCAD LT

Before using the macro provided in this post, please note that this macro has not yet been tested in AutoCAD LT. I move forward based on the assumption that all the macro elements are acceptable in AutoCAD LT. Since I don't have LT with me, the testing part is left with the readers. This macro prompts the user to pick a first point and and second point repeatedly, and then displays the total distance in the AutoCAD status bar (Without using LISP). You have to use another simple macro to reset the settings before start using length calculation macro each time. Try the following macro and let me know whether it's useful.

*^C^C_dist;\\setvar;USERR1;$M=$(+,$(getvar,USERR1),$(getvar,DISTANCE));_modemacro;"Total Distance :"$(+,$(getvar,USERR1),$(getvar,DISTANCE));

Use the following macro to reset the status bar and system variable.


Now, you don't have to worry about drawing polylines to measure the the total distance. Most importantly, you can add distances from different locations, ie the pick points need not be continuous.

Saturday, September 1, 2007

Unleash the Double Click Power...

  1. The best thing I like in AutoCAD is the power of customization it offers for the end user. By doing so many customizations, you can convert your AutoCAD to a custom product most suitable for your industry. Moreover, the process of customization gets simpler with each new release of the product. Here is a sample tutorial to create a custom double click action which converts a Line to a PolyLine. Please have a look at the image attached below.

    The picture itself speaks well about the process. Doesn't it? In case you are unable to make out the process, here goes the steps in detail.

  2. Open CUI dialog by typing CUI in the command prompt (or Tools -->Customize -->Interface...).

  3. In the 'Command List' category, click on 'New' button to create a custom command (See the image section 1).

  4. Type in a name in the 'Name' property field (image section 2) and assign your macro to the 'Macro' property field (image section 3).

  5. Now the costom command is ready for use. The next thing is to apply this command to the double click action of an entity. For that, expand the 'Double Click Actions' category to locate the target entity (Here we are going to apply it to a 'Line').

  6. Drag the command using left mouse button and drop it right under the 'Line' category listed under the 'Double Click Actions' (image section 4). Before doing this, take a note of the existing command under the 'Line' category, in case you want to go back to the default command later.

  7. Now finish the process by clicking apply. Draw a line and double click on it to see how the new settings work. If the settings were done properly, the list command should list the object type as 'LWPOLYLINE'.

The double click macro for converting line to polyline is given below


The following are some macros I use to make my drafting life easier.

Macro : ^C^C_xopen;
Category : XRef

Description : Opens the external reference source file.

Macro : ^C^C_dimedit;home;cmddia;0;_dimedit;new;<>;previous;;
Category : Dimension
Description : Regains its original dimension value, text position and text orientation

Macro: ^C^C$M=$(if,$(=,$(getvar,peditaccept),1),_pedit;decurve;,_pedit;;decurve;)
Category : Arc
Description : Converts an arc to a straight polyline

Macro: ^C^C$M=$(if,$(=,$(getvar,peditaccept),1),_pedit;close;,_pedit;;close;)
Category : Arc
Description : Converts an arc to a circular polyline

Macro: ^C^C_transparency;on;
Category : Image
Description : Makes an image transparent.

Macro: ^C^C'_.zoom;_o
Category : Applicable to all
Description : Zooms to the double clicked object

Macro: ^C^C_-view;_swiso;'_.zoom;_o;previous;;
Category : 3DSolid
Description : Switches to isometric view of the double clicked 3D object.

I have a few more useful double click actions. But I skip those for the reason that it contains LISP expressions which is not supported in AutoCAD LT. Please note that you can not directly do these things in AutoCAD 2005 or earlier versions. Hope you enjoyed the double click customizations. If you have got any double click actions with you, please feel free share it with me.