So a little while ago, someone in the discussion group asked how to go about dropping the zeros at the end of a label. For example, if a value was 100.1111, they wanted to see 100.111. If the value was 100.0001, they wanted to see 100. Apply this to the entire range and you get an idea of what was wanted;

One Label Style, Different Precisions

One Label Style, Different Precisions

In the image above, you can see the total length of the line in the component on the bottom and the component on the top is displaying with different precision based on the value of the label.

NOTE: The method I came up for solving this issue only works if the values can never be negative. If the values you are labeling can be negative (such as a surface elevation) this technique won’t work

Setting Up the Style

What you’ll need: 1 component for each precision you’ll want in the label and one expression for each of those. I’ll start this off by creating the component if the label rounds to the nearest ones place.

The expression basically does this: It checks to see if the number is the same when rounded to the nearest one and when it’s rounded to the nearest one thousandth. If they are the same, return the value. If they are different, return -1 (negative one). The expression will look like this (for a line label):
IF(ROUND({General Segment Length})=ROUND({General Segment Length}*1000)/1000,{General Segment Length},-1)

Expression for Display to the Ones Place

Expression for Display to the Ones Place

I called this expression “ones”.

Now use this expression within a label component. Instead of using the length of the line in the label, use this expression. The trick here is to change the precision to the ones place and then set the “Sign” value to “hide negative value”. That’s what the -1 is used for. If the test in the expression is false, then don’t display anything, if it’s true, display the value at a precision of 1.

Label Component Used to Display the Ones Place

Label Component Used to Display the Ones Place

Repeat the expression/component process for the rest of the precisions you want to use in the label (tip: just copy the “ones” component for the rest of them). For the tenths place, add an additional IF statement to the expression. If the “ones” expression is greater then or equal to zero, then return -1, otherwise, test for the next precision. This expression looks like this:
IF(ones>=0,-1,IF(ROUND({General Segment Length}*10)/10=ROUND({General Segment Length}*1000)/1000,{General Segment Length},-1))

Expression for Display to the Tens Place

Expression for Display to the Tens Place

The expression for the hundredths place is very similar but with an extra IF statement to check both the “ones” and “tenths” expressions.

Finally, you’ll need one last expression for everything else. This one is really simple, basically, if “ones” is greater then 0 or if “tens” is greater then 0 or if “hundreds” is greater then 0 then return -1. Otherwise, return the value.

IF(ones>=0,-1,IF(tens>=0,-1,IF(hundreds>=0,-1,{General Segment Length})))

Expression for Display to the Thousands Place

Expression for Display to the Thousands Place

Wrap Up

Once you have the expressions created and added to your label, it works like a charm. HERE is a quick little video I made showing the expression at work. I took a line and labeled it and then changed the length of the line using the dynamic input.

Additionally, if you would like a copy of the file that I showed in the video, you can download it HERE.

Have fun playing with your new label knowledge!

Checking comments on my blog this morning I ran into this question:

Thank you very much for nice post. I have one more query. I want to display elavations of contours for each contour line at some fixed interval. I don’t want to draw lable lines. Is there any way to do that. If u know it please help me

Most likely they want an automatic contour labeling routine but it got me thinking, what about labeling every third contour? Or every seventh? Or every whatever the heck you want contour! It’s pretty simple, you just need an expression that will check the interval and then control it’s display. Here’s how to do it.

For this example I am going to label every third contour line. First, create an expression. This expression will see if the contour is at the interval. If it is, then return the contour elevation. If it’s not, return a negative one. To create the expression, expand out Surface on the Settings tab of the prospector, then Label Styles, and finally Contour. Right click on Expressions and select New…

New Expression

In the new expression dialog box give the expression a name and a description. Have a little forethought on this as you can’t go back and rename or change the description of the expression. The actual expression itself will look something like this (remember I’m doing this for every third contour):

Expression Settings

So, what does this expression do? The test in the IF statement is “{Surface Elevation}/3=TRUNC({Surface Elevation}/3)”. This tests to see if the contour is the third contour or not. If this test is true (the contour IS divisible evenly by three) then it returns the contour elevation, if it’s not, it returns -1. This -1 is key to how this expression works in the label style.

And make sure to format it as an elevation.

Now that the expression is created use it in your label style. You can create a new style or copy an existing style. In the style composer, edit the style. On the Layout tab, edit the contents of the text component. Remove the current text from the right hand side and insert your new expression into the label. When you do this, the important part is to set the “Sign” value to “hide negative values”. This way if the expression returns -1 it will, basically, not display anything at all.

Applying the Expression

Once you have done this to all label styles involved in your labeling process (i.e. major, minor, user, etc.) your drawing will look something like this:

Expression Used in Labels

You want to change the interval? Modify the expression or create a new one for that interval. Want to adjust the base of the calculation? Simply add a number in the surface expression to adjust it. For example, I want to label contours 1, 4, 7, and 10. The expression would look like this: IF(({Surface Elevation}+1)/3=TRUNC(({Surface Elevation}+1)/3),{Surface Elevation},-1) – Notice that I added 1 to the first two {Surface Elevation} values to adjust the test (don’t add 1 to the last one!).

So you have some short pipes and you have some long pipes. Labeling the long pipes is just fine but when you label the short pipes, the text is longer than the pipe so you have to manually edit the label and put those line breaks in or you have to change the style the label is using for one that stacks the different pieces of data. Well NO MORE! Come on now! This is CIVIL 3D we’re talking about!

As long as you have Civil 3D 2012 that is…

Anyways, in Civil 3D 2012 there is a new option in the label style to set a maximum length to a text component. We can use this to specify how long we want the label to be. Now, the trick here is to use an expression for the maximum label length. We have to do this because the length of the label is measured in plotted units, not absolute model units.

The expression will look like this:

Expression used to limit label length

To create the expression, on the settings tab in Civil 3D, expand out Pipe, Label Styles, Plan Profile. Right click on Expressions and choose “New”. Give it a name (this will appear in the label style later), a description (this is optional), and the expression itself.

Now that the expression is created, you can add this to your label style. In your pipe label style, simply add this expression to the Maximum Width of the label text component.

Applying the expression

Your expression will now show up as an option for the Maximum width of your label. Once you have applied this, your label will automatically adjust for you.

Labels Automatically Shortened

As you can see in this example, there are some limitations. If any single word is longer than the pipe length, it will not be wrapped. Additionally, if you want a buffer around the ends of the pipe, you can simply modify the expression and subtract off half the twice the distance you want at each end (1/2″ buffer at each end means subtracting 1″ from the expression).

Hope this helps someone with their labeling issues and thanks to Brooke for coming up with the great idea!

Expressions have got to be one of the coolest things in all of Civil 3D. I was teaching a styles class a couple weeks ago and when we got to expressions, one of my students asked if we could use expressions to label the length of a vertical curve, but just the length of the part of the curve that was within the profile view. I got to thinking about it and this post will show you the results of what we did.

First of all, a little bit of information is needed. There are a couple properties of vertical curves that we will be using for this label, specifically the start and end station value of the curve. What we need to do is check to see if the beginning of the curve (and likewise the end of the curve) lies within the profile view. To do this, we create an expression that will check this. If the beginning of the curve lies within the view, then the expression will return a value of 0. If it doesn’t, it will return a value of the distance from the start of the curve to the start of the profile view. Likewise, we will check the end of the curve to see if it’s in the profile view. If it is, return a value of 0, if not, return the distance from the end of the curve to the end of the profile view.

Expression checking the start of the curve

We then create a third expression that will take the total curve length and subtract off these two values. If both ends of the curve are within the profile view, then we simply get the length of the curve. This expression is the one that will be placed in the curve label instead of the total length of the curve.

Expression for the Curve Lenght in View

Now that we have the expression created, simply add it to your label.

Place the expression in the label

Once you have added the expression to your label, here’s an example of what it can do. As you can see, the “LVC” is the overall length of the curve and the “LVC in view” is the length of the curve within just the view.

Expression used in the label

If anyone would like to see this label in use, you can download a drawing HERE with the expression being used. Leave a comment here, I would love to hear what you think about this.

So, I was reading The Swamp and came across a post about getting an alignment station/offset label to draw a line over to the alignment. There were a few options  but I came up with my own solution and I would like to share it here with all of you.

So, This is what the user wants the labels to look like (I drew this up myself so if you think it looks sloppy, the blame lies solely on me):

You can do this with a station label and just have it add the line and then the text but, what if you need to adjust the labels so they are farther from the alignment? Or on the other side? Well, this is what you get:

(select the image to see the animation)

So, what did I do? To start off with, I used a station/offset label with a line component. In this post, I’m going to focus on the line itself and not necessarily the text. Create a new label style, delete everything (I like to start out fresh) and add in a line component. The line will attach middle center of the feature as there is nothing else to attach to at this point. The end of the line will be calculated so don’t specify an ending point.

Now, to control the length and the rotation of the line, we have to create a couple expressions. The length of the line is determined by the offset value of the label location but, the length of the line is also dependent on the drawing scale. If the scale changes, the length of the line changes. I’m going to use a technique I wrote about in an earlier blog post HERE to avoid the length of the line changing when the drawing scale changes. Basically, I’m going to take the offset value and divide it by the drawing scale factor:

We also need to create an expression for the rotation of the line. I used the Instantaneous Direction of the line. The problem with that is  if I just use that for the rotation, it rotates the line the wrong direction. To overcome this, simply multiple the direction by a negative 1. Also, the line is going the wrong direction so we need to add a rotation of 180 degrees to the line so add in pi to the direction (remember it’s in radians).

Now, use these two expressions in the label style for the length of the line and it’s rotation:

Add some text components, some more line components, and perhaps a reference text component and you are good to go! Hope this helps everyone!

Recently on one of the discussion groups, someone asked if they could put a box around a structure label in a profile view. The problem with this is that you can’t simply toggle on the display of the border because the label is composed of several components and would look something like this:

Labels with frames turned on

As you can see, it’s not quite what I would like to see. The problem with this is that you can’t create the entire label within one text component. Since the inflow and outflow labels are displayed in a “Text for Each” component. What I would much rather see is something like this:

Labels the way they should be

Now, the primary problem with this is that there’s nothing to simply create a box around. So, what I did was to create the four lines manually. The first line (#1) attaches from the top right of the structure name to the bottom right of the invert out text. Lines #2 and #3 attach to the beginning and end of line #1 respectively and line #4 attach to the ends of lines #2 and #3. The trick here is, how long do lines 2 and 3 need to be? I can’t simply attach them to another point on the labels because the text they attach to are different lengths. Here is what I did, I created a very simple expression the determines the length of the lines. What is in the express? That’s what makes it so simple, it’s just the plotted length of the line. If I need to stretch the frame a bit, I just change the value of the expression and then do a regen.

Here’s the label style showing the lines as well as the expression. Again, to change length of the box around the label, simply change the value in the expression.

Label Style and Expression

One of the limitations of this technique is that all of the boxes in the labels are all the same length. If you need to have the boxes to have different lengths, then you would have to create new expressions and new label styles.

It’s not the best workaround I’ve ever come up with but it does work. Hopefully someone who reads this will offer up a better solution.

So, Friday I was teaching a class on creating styles in Civil 3D. I was showing off how to set up profile vertical curve labels so that when they run off the profile view, they still display correctly. My student asked if it’s possible to have a double arrow when the start or end of the curve is off the profile view. Well, I wasn’t sure how to go about this but, I figured it out. Read on to find out how to do this. (more…)

Follow

Get every new post delivered to your Inbox.

Join 807 other followers