About Label Expressions:
Commonly, an expression defines a calculated value that will be displayed as a property or used as a component value in a Civil 3D label.
Expressions can be:
- User settings
- Properties
- Variables
- Intermediate values other expressions use.
- Act as flags indicating the result of a conditional test.
Users can make powerful, productive labels by going beyond the common expressions.
Contents
- Introduction
- Expression use
- Types of Expression Use
- Names and Naming Convention
- Example
- Summary
- Call to Action
- Series Roadmap
This post is part of a series. You can reach previous posts via links in the Series Roadmap in Section 8.
1. Introduction
Any sufficiently advanced technology is indistinguishable from magic.
Clarke's Third Law, Arthur C. Clarke
The goal of this post:
- I will share my experience working with Label Expressions.
- This post provides foundational information on working with Label expressions.
There will be more What and Why than How. Future posts will cover How. - Note: Civil 3D Label creation and expression use can be a bit quirky.
- This will not be a beginner's tutorial.
- I think the ideas presented are good practices.
Me:
- A guy who has created a lot of label styles.
I am active in the Civil 3D (C3D) forum and have answered or solved more than a few label-related posts. I mostly do site work. - Note: I work in imperial units exclusively. Any metric content herein may be somewhat scrambled.
Metric readers are welcome to suggest improvements.
You:
- Someone familiar with creating simple label styles. Someone willing to learn more about expressions.
- You should be familiar with creating Civil 3D Labels and basic Label Expression use.
- Note: If you need to brush up on your skills.
I suggest you consult Autodesk Knowledge Network: Label Expressions.
It will not take long to read all nine sections.
Acknowledgment and Thank Yous:
Much, if not all, of the information in this post has been covered elsewhere.
I thank all of the other users that have taught me.
Tench Tilghman from CadPilot.com has been immensely helpful.
Thanks to @m_kingdon and @Matheus-Lima for reviewing a prepublication draft.
This may be a review for some readers. If so, I appreciate your patience.
2. Expression Use
This is based on information from the About Label Expressions section of the Knowledge Base:)
Label styles are composed of property fields that display information about an object.
Expressions are stored in the Settings tree within the label style type folders.
(Each object type has its own expression collection.
Expressions cannot be shared between label or object types.)
You insert expressions directly into label styles using the Text Component Editor when editing a label style component.
You can use the data defined by an expression to determine how a label style is drawn using text, lines, or block components. You can insert expressions into label styles by selecting expressions instead of static values for text, line, and block component modifiers.
Expressions can have uses beyond these typical uses within the label style composer. These will be discussed in the next section.
3. Expression Types
I mentally classify expressions by how they will be used in the label style creation process.
This workflow has worked well for me.
This background information will be difficult to fully comprehend without the detailed use cases that will come in future posts.
Usage in Labels:
[P] Property expression. This is an expression that will be displayed in a label text component.
Example: A Surface Spot Elevation expression representing
a calculated top of curb elevation for a 6" (150mm) curb height:
.Top Curb El: {Surface Elevation} + 6/12 -or- ({Surface Elevation} + 150/1000)
[V] Value expression. This expression will be used as a static value in a label component.
Example: A Surface Slope expression representing 1" (10mm) Arrow Length
.Arrow Len: 1/12 -or- (10/1000 )
[T] Test Expression. This expression acts as a "flag," indicating the result of a conditional test. The flag will typically be used as a static value for a label component or assigned as a property value to control the visibility of a component.
Examples of tests include "cut or fill," "elevation range," etc.
Usage in Expressions:
(U) * User Setting Expression. This is an expression that the user controls by manually editing the expression.
User Setting expressions can be used directly as component values in labels.
They are often indirectly used by other expressions.
An Example would be Text Height: Plans and plats 0.1", but legal descriptions to be recorded require 0.125". This will be explained further in future posts.
(C) * Constant Expression. This expression is a value that other expressions will use. It can be a mathematical constant. It is often a needed object or drawing property not available to expressions.
Example: Model Space to Paper Space factor
#MS to PS factor = 12 for imperial (12" = 1'), 1000 for metric (1000mm = 1m)
(R) * Reference/Readability Expression. This is an expression that other expressions will use. This type of expression can help ensure an expression can be read and understood easily.
* Nested/Orphan/Phantom (NOP) Expressions:
The values of U, C, and R expressions will often be referred to by P, V, and T expressions.
These P, V, and T expressions are used directly in Label Styles.
Thus U, C, and R expressions are only indirectly used in label styles.
There will be a future post about this.
For now, be aware that missing NOP expressions result in imported label styles displaying values of "???."
4. Names and Naming Convention
This is an explanation of my process. You do not have to adopt it.
- Warning: Once created, the name of an expression cannot be edited.
This can be very frustrating. - Plan ahead and triple-check your spelling.
- In any branch of the settings tree, expression names need to be unique.
- Expression names can be reused on a different branch.
i.e., #MS to PS factor (Imperial 12, Metric 1000) is a constant and should be repeated as necessary. - (#) - User setting Expressions (U) should start with a number sign (#).
This forces them to the Top of the expression list, where they will be more evident to the user. - (.) - All other expressions should be started with a period (.).
This will help distinguish expressions from object properties in a combined list. - (|) - I sometimes add a vertical line and some descriptive matter at the end of an expression name in complex situations.
- Use General to Specific order for related expression names to facilitate sorting.
i,e,
".Folder Tab Height PS" and ".Folder Tab Height MS"
as opposed to
".PS Folder Tab Height" and ".MS Folder Tab Height" - Make use of the Description field. It can be helpful in the future or to other users.
Here are a few observations.
- In the settings tree, when you select expressions, the expression list can be sorted by clicking on the Name heading. (See Below, Left)
- As you create new expressions, the Insert Property button will list expressions and object properties. When using the suggested naming convention, the expressions are not intermixed with the properties, making it easier to browse the list. (See Below, Right) I cannot explain the imperfect sorting.
- To display the value of an expression in a label, it must be added to a text component.
Open the Label Style Composer (LSC), and Click [...] to edit the Text Contents,
Click the Properties drop-down and select an expression from the sorted list.
Adjust the formatting and click [ð] to add the expression. (See Below) - The value of an expression can be used as a component modifier.
Open the Label Style Composer (LSC), and select the appropriate component,
Click the drop-down and choose an expression from the sorted list.
5. Examples
Top of Curb Elevation
Background:
- The Expression/Label style that adds a computed Top of Curb Elevation to a Gutter Elevation a C3D spot elevation label style is the equivalent of the classic "Hello World" first program.
- For clarity, here is my local standard:
- Our example will be a 6" vertical curb (H = 6", metric: H = 150mm)
Expressions:
- This expression will appear directly in the label, making it a Property expression. [P]
- Version 1 - Simple.
- Name: .Top of Curb EL MS
Description; Top of Curb elevation in Model Space units
Expression: Imperial: {Surface Elevation} + 0.50
Metric: {Surface Elevation} + 0.150
Note: Mental math was used to convert "H" from inch (mm) to feet (m).
- Name: .Top of Curb EL MS
- .Version 2 - Eliminate Mental Math.
- Name: #Curb Height PS
Description; Curb Height in Paper Space Units
Expression: Imperial: 6
Metric: 150 - Name: .Top of Curb EL MS
Description; Top of Curb elevation in Model Space units
Expression: Imperial: {Surface Elevation} + ({#Curb Height PS} / 12)
Metric: {Surface Elevation} + ({#Curb Height PS} / 1000)
- Name: #Curb Height PS
- Version 3 - Easy to read/maintain.
- Name: #Curb Height PS
Description; Curb Height in Paper Space units
Expression: Imperial: 6
Metric: 150 - Name: #MS to PS factor
Description; Model Space to Paper Space factor, Imperial = 12, metric = 1000.
Expression: Imperial: 12
Metric: 1000 - Name: .Top of Curb EL MS
Description; Top of Curb elevation in Model Space units
Expression: Imperial or Metric: {Surface Elevation} +({#Curb Height PS} / {MS to PS factor})
- Name: #Curb Height PS
Text component:
- This is a 2-line text component. Format as you see fit.
- TC: <[.Top of Curb EL MS]>
G: <[Surface Elevation]>
Block Height Example
Background:
- Assume that you have clients or review agencies with conflicting standards.
- The required height of C3D label style block components differ. You do not want different styles libraries for each client/agency.
- You will use an expression to control block height.
- Civil 3D (C3D) internally stores data as either feet or meters.
- C3D works in real-world scale. Thus, Model Space (MS) is in feet or meters.
- C3D conveniently and correctly does drafting on virtual paper. Thus, Paper space (PS) is in inches or mm.
- When drafting, we think in and use inches or mm, for text height, block size, etc.
- Conveniently, within the Label Style Composer (LSC), vales are input and displayed in inches or mm.
- Apparently, and logically, these values are converted on the fly to feet or meters for internal storage.
- Within the Label Style Composer, static values can be set to the value of an expression.
In this case there is no on-the-fly conversion.
The value from an expression is expected to be in feet or meters.
Shockingly, this does not seem to be documented.
- For this example, use a block height of 0.15 inch (4mm)
Expressions:
- This expression will be used to control the appearance of block components in the label, making it a Value expression. [V]
- Version 1 - Simple.
- Name: .Block Height MS
Description; Block Height in Model Space units
Expression: Imperial: 0.0125
Metric: 0.004
Note: Mental math was used to convert from inch (mm) to feet (m).
- Name: .Block Height MS
- .Version 2 - Eliminate Mental Math.
- Name: #Block Height PS
Description; Block Height in Paper Space Units
Expression: Imperial: .15
Metric: 4 - Name: .Block Height MS
Description; Block Height in Model Space units
Expression: Imperial: {#Block Height PS} / 12
Metric: {#Block Height PS} / 1000
- Name: #Block Height PS
- Version 3 - Easy to read/maintain.
- Name: #Block Height PS
Description; Block Height in Paper Space Units
Expression: Imperial: 6
Metric: 150 - Name: #MS to PS factor
Description; Model Space to Paper Space factor, Imperial = 12, metric = 1000.
Expression: Imperial: 12
Metric: 1000 - Name: .Block Height MS
Description; Block Height in Paper Space units
Expression: Imperial or Metric: {#Block Height PS} / {MS to0 PS factor}
- Name: #Block Height PS
Text component:
- Use ".Block Height MS" for the block components height value.
6. Summary
Expressions are a powerful tool for creating Civil 3D label styles. Creating labels styles using expressions and be complicated. Understanding and mastering the various types and uses of expressions is not trivial. Some planning will make the process easier.
7. Call to Action
Take a while to digest this article.
If you haven't already, consider reading the previous articles in the series.
You might want to review the Autodesk Knowledge Network information: Label Expressions.
8. Series Roadmap
The Series So Far ...
Leveraging Label Legerdemain!
1 ... Not Magic, but a Quest for Some Pretty Good Label Tricks
2 ... "I Can See Clearly Now ..." Better visibility for Text Component Editor Contents window
3 ... When The Chips are Stacked Against You, Finesse the Stacked Formatting (General)
This Post ...
4.... An Expression is An Expression is an Expression NOT!
What's Next? (Subject to change)
.... Let's Start at the Very Beginning ... A Minimal Template and Finally a Label!
... An Expression is an Expression ... Part 2 - The Alway Import style
... Divide and Conquer: Fancy Numeric Formatting
... Ah, Yes, The Old Display Conditionally By Text Height Trick
... Ah, Yes, The Old Display Conditionally By Hide Negative Value Trick
... To Text Height or to Hide Negative Value. That is the Question
... About That Elephant in the Room: Truncation that works
...
...
...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.