<< Click to Display Table of Contents >> Calculate simple Example |
In this simple example we calculate the property "MesasuringType" by using the first character from the property "Type". In this example Type shows PI ao the MeasuringType will be "P".
To create a new calculation we click on the "Edit Calculations" button.
In the following dialog we click on "New...".
In the next dialog we define the class, the property which should be calculated and the calculation expression itself.
We select "General Instrument Symbols" class and the "MeasuringType" property.
Next we click on the "Edit" button.
The blank "Expression Editor" will be opened. In the top part you will see the calculation expression which can also be manually typed in or edited.
For details on the Calculation function and the Expression Editor have a look here.
First we need the function to subtract the first character of a string. We click on "String" under "Functions" and then we scroll down to "Substring". There are two different types and we use the first one. On the right side you see the details of the selected function.
You can also type in parts of the function which filters the available functions.
If you double-click on substring it will land in the expression window at the position of the cursor. We see the general error message "Syntax error.".
We remove the two ' characters, click on "Columns" and then double-click on "Type".
The project and drawing properties are available also.
The property will also land in the expression window in [ ].
The next two parameters are 0 and 1. 0 is the start position (the counting starts at 0 for the first position). And 1 is the length of the string. We need only 1 character from the start.
After clicking on OK we see the expression in the calculation setup dialog.
If we click on OK again, we see that the calculation is defined without any error and it is active. If needed, calculations can be Disabled.
After closing the dialog and saving the drawing we see an update info in the command line. If there are any issues during the update, we would see it here.
In the Properties Palette we see the calculated value.
Next Chapter: Calculate AutoCAD Properties