## AutoCAD Civil 3D Tip: It’s All in the Expression

Published on December 5, 2014

Our corridor is designed and we’re ready to cut cross sections. We have a Code Set Style assigned to generate the labels we wish to display, but we have a problem. The labels in the left ditch appear as desired, but the labels in the right ditch are overlapping and hard to read.

We certainly don’t want to edit dozens (or hundreds!) of cross section labels manually. We could make a global edit to our Code Set Style or Label Styles, but that would change the entire section. We like the left side the way it is. Can we just change the right side without changing the left? If Civil 3D only allows one Label Style to be assigned to each Link Code, is it even possible to display the same Link Labels in a different way on each side?

One way of approaching this problem is by using Expressions.

Civil 3D Expressions are mathematical expressions that can be used in place of static values in Label Styles. We will use Expressions to modify the data in the standard label style components. Expressions are stored in the Settings tab of the Toolspace, within the Label Style folders. In this example, we will be using Expressions to control the size of our label text for the specific condition of controlling their display in the right ditch of our section.

Currently, our Link Label Styles consists of a text component with a static value for Text Height. We are going to replace that value with an expression.

To create our Expression we’ll navigate the Settings tab of the Toolspace.

General > Label Styles > Link > Expressions

Right-click on “Expressions” and select “New…”

The New Expression dialog box will appear.

Our first expression we create will control the text height of the Slope Ratio label on our sideslopes. Since our right ditch labels are overlapping because of the smaller size of the ditch, we will use the size value of the slope link to determine the size of our label text.

1 The expression we will use is: IF({Link Length}<2.5,.05/12,.06/12)

Which means: If the length of the sideslope link is less than 2.5 feet, then the value of the text height should be .05 inches (divide by 12 is added to convert feet to inches), if it is not less than 2.5 feet then the value of the text height should be .06 inches.

We’ll name this expression “Sideslope Text” and click “OK” to create our expression.

Now we need to add our new expression to our Label Style.

If we open our Label Style Composer for our Slope Ratio label and click on the Text Height value, we will now see our expression available in a drop down menu. We’ll set our Text Height value to the new “Sideslope Text” expression and click “OK” to finish.

(We can create a similar expression for the Slope Percent label on the flat bottom of our ditch and apply it in the same manner.)

Now if we take a look at our sections, we’ll find that the text in the right ditch has automatically resized and is no longer overlapping.

This sure beats having to edit dozens (or hundreds!) of cross section labels manually. Next time we’re faced with a similar problem, just remember, it’s all in the expression.

1 In this example, we used the Link Length property and the IF function to create our expression. Other properties and functions available for an expression can be found using the two buttons on the right side of the dialog.

Last Month’s Tips:

Don’t want to miss out on other great information? Subscribe to this blog or our monthly eNewsletter now!

Tags: , , ,

### 5 Responses to “AutoCAD Civil 3D Tip: It’s All in the Expression”

1. Kirk Says:

February 19th, 2016 at 8:03 am

Great trick with the expression. I have been working with just this type of setup for sometime, but have always dealt with a dragged leader justification issue when the dragged state display component is set to as composed. Have you or any of your client come across a solution?

2. Rodrigo Says:

April 28th, 2016 at 4:11 pm

Hi it is possible aply expressions in the profile data band?

3. Bryan Says:

May 2nd, 2016 at 12:42 pm

Hi Rodrigo,

Expressions are not available in Profile View Band Styles.

4. Owen Says:

October 7th, 2016 at 10:42 am

Can expressions produce strings (i.e. text)?

e.g. if the area of a parcel is less than or equal to 10,000sq-ft
then expression equals “A”

5. Bryan Sullivan Says:

October 7th, 2016 at 2:04 pm

Hi Owen,

Right now expressions can only return values. There is not a way to store text strings. Text strings are asked for by many, perhaps if we are lucky in a future release.

This may not be exactly what you are looking for, but if you want the output to display or not display based on the value, you can create an expression that sets the text height to 0 when a certain condition is or met.

IF({Parcel Area}>10000,0,.06/12)

If the parcel area is greater than 10,000 then the text height is 0 (invisible). If the area is less than or equal to 10,000 then the text height is .06 (visible).