Quick Field
Function Syntax | (LM:quickfield <prop> <format> <mode>) |
Current Version | 1.3 |
Download | QuickFieldV1-3.lsp |
View HTML Version | QuickFieldV1-3.html |
Donate |
Program Description
This function is designed to enable the user to quickly and easily create custom programs for inserting multiple fields into a drawing.
This could be for use in situations in which the user is required to create many fields in a drawing, with each field referencing the same object property, and continued use of the Field Command Dialog can become tedious.
Custom programs can be created by calling the 'LM:quickfield' function with a string describing the object property to be referenced by the field; a string describing the field formatting; and an integer to determine how the field will be created.
For example, say I need to create several MText fields referencing the length of Lines in my drawing, furthermore displaying the length of each line in Decimal Units to a Precision of 3 decimal places.
Usually, I would need to open the Field Command Dialog, ensure all the settings are correct for the field I wish to create, and insert the field into the drawing; then repeat this procedure for every field I need to create.
However, using QuickField I can quickly create a custom field program to avoid the need to set up the field everytime:
(defun c:test ( ) (LM:QuickField "Length" "%lu2%pr3" 3))
In fact, using the above custom command, I can bypass the Field Command Dialog completely.
Now to explain what the parameters mean.
QuickField Function Parameters
Arguments | ||
---|---|---|
Symbol | Type | Description |
prop | String | Object Property to link to field (e.g. "Area") |
format | String | Field formatting string (use "" for none) |
mode | Integer | Integer to determine how the field is created (available modes shown below) |
Returns | ||
- None - |
When creating the custom field programs, the user is advised to first use the Field Command dialog with all settings set to create the desired field, then make note of the Field Expression displayed at the bottom of the dialog. The required QuickField parameters may then be read directly from this Field Expression.
'Prop' parameter
Type: String
This parameter is a string describing the object property to be referenced by the field.
Example
Field Expression displayed in Field Command Dialog:
%<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%
For the above expression, the object property is "Area"
'Format' parameter
Type: String
This parameter is a string describing the field formatting for the object property that is to be displayed.
If no formatting is to be used, 'format' should be an empty string ("").
Example
Field Expression displayed in Field Command Dialog:
%<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%
For the above expression, the object property is "%lu6%qf1". This formatting string indicates that the "Area" property of the object will be displayed using the current units and precision in the drawing.
'Mode' parameter
Type: Integer
This integer parameter determines how the field should be created in the drawing.
Mode | Description |
---|---|
1 | Replace Existing Text / MText / Attribute string This mode will prompt the user to select an existing object to contain the field. |
2 | Create Text Object The user will be prompted to pick a point at which a Text Object containing the field will be created. |
3 | Create MText Object This user will be prompted to pick a point at which an MText Object containing the field will be created. |
Example Custom Field Programs
Example Program #1
(defun c:test1 ( ) (LM:QuickField "Area" "%lu6%qf1" 2))
Here,
prop = "Area" format = "%lu6%qf1" mode = 2
This program will hence prompt the user to select an object with the "Area" property, then prompt for a point at which to create a Text Object (mode=2) containing the field.
The displayed Area will be formatted using the current settings for Units and Precision ("%lu6%qf1")
Example Program #2
(defun c:test2 ( ) (LM:QuickField "Length" "%lu2%pr3%ps[Length:,]%ct8[0.1]" 3))
Here,
prop = "Length" format = "%lu2%pr3%ps[Length:,]%ct8[0.1]" mode = 3
This program will prompt the user to select an object with the "Length" property (Lines / LWPolylines / Polylines), then prompt for a point at which to create an MText Object (mode=3) containing the field.
The Length value will be formatted...
- in Decimal Units (%lu2)
- to a Precision of 3 d.p. (%pr3)
- with a Prefix of "Length:" (%ps[Length:,])
- with a Conversion Factor of 0.1 (%ct8[0.1])
Example Program #3
(defun c:test3 ( ) (LM:QuickField "StyleName" "%tc1" 1))
Here,
prop = "StyleName" format = "%tc1" mode = 1
This program will prompt the user to select an object with the "StyleName" property (Text / MText / ...anything with a Style), then prompt for an existing object (mode=1) to house the field.
The referenced StyleName property will be displayed in uppercase (%tc1).