Community
Civil 3D Forum
Welcome to Autodesk’s Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Line Label Style Expression

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
jkwilliams
1466 Views, 15 Replies

Line Label Style Expression

Hi,

I am looking for a Line Label Style Expression which will perform a rounding function on distance labels that display my "General Segment Length" value.

 

What I need is to be able to remove "Trailing Zeros" from my distance values, so that if precision is set to say 0.01 and my distance value is measured as 45.5, I do not get 45.50 but 45.5.

 

I need this to round for:

1 decimal place

2 decimal places and

3 decimal places

 

Can anyone assist here?

 

Best Regards,

 

Jim Williams

15 REPLIES 15
Message 2 of 16
troma
in reply to: jkwilliams

Are you talking about one expression for all three instances?  I'm not sure about that.

Otherwise, I think it is pretty simple.  You need to multiply by 10, or 100, or 1000, then truncate, then divide again.

 

So, for three decimals:

(TRUNC(1000*{General Segment Length}))/1000


Mark Green

Working on Civil 3D in Canada

Message 3 of 16
troma
in reply to: troma

The all-in-one version could probably be done with multiple IF statements


Mark Green

Working on Civil 3D in Canada

Message 4 of 16
Cre9engr
in reply to: jkwilliams

Why can't you just create a label style that sets rounding to truncate?  See the attached image.  I would create three general line segment styles with the following settings for my label:

 

General Line Segement Tenths:

Precision = 0.1

Rounding = truncate

 

General Line Segement Hundreths:

Precision = 0.01

Rounding = truncate

 

General Line Segement Thousandths:

Precision = 0.001

Rounding = truncate

 

Fred

-Civil 3D 2012

Fred
-Civil 3D 2016 sp2
-Windows 7 64-bit
-Intel Xeon with 3.5 GHz
-16 GB of RAM
-Nvidia Quadro K2200
-Civil 3D user since 2007
Message 5 of 16
jkwilliams
in reply to: jkwilliams

Hi,

Thanks for that expression, it makes basic sense, but I'm not a mathematical boffin.

I really do need to do this for the 3 cases of 2, 1 and 0 decimal places.

Any idead how I woudl form the "if" and "then" statements aroudn this for a complete solution?

Regards, Jim

Message 6 of 16
jkwilliams
in reply to: Cre9engr

I don't want to have 3 line label styles, as that so much additional work for multiple draftspeople doign this 8 hrs per day. I need 1 x label style that evaluates this and automatically does the rounding.

Message 7 of 16
troma
in reply to: jkwilliams

IF(test,valueiftrue,valueiffalse)

 

now, to apply that, something like....

(where g = {General Segment Length}

 

IF(g-TRUNCg=0,g,(IF(10g-TRUNC(10g)=0,(TRUNC10g)/10,(IF(100g-TRUNC(100g)=0,(TRUNC100g)/100,(IF(1000g-TRUNC(1000g)=0,(TRUNC1000g)/1000,g))))))

 

Don't know if I've got enough closing brackets at the end there.  I've never tried muliple if statements inside each other, but you should get the idea.  If the first test is true, return the number, if not go to the second test etc.


Mark Green

Working on Civil 3D in Canada

Message 8 of 16
jkwilliams
in reply to: troma

Your equation looks good.

How do I actually now put all this together in the contents of the "Text Components Editor"?

 

 

 

Message 9 of 16
troma
in reply to: jkwilliams

first of all, couple of questions.

 

If the length is 14.9999, how should it display?

15

15.000

14.9999

 

 

If the length is 15.0001, how should it display?

15

15.000

15.0001


Mark Green

Working on Civil 3D in Canada

Message 10 of 16
troma
in reply to: jkwilliams

Line expressions.PNG

Right-click, > New.

 

new expression.PNG

The format is important, but I'm not sure what they all mean.  Distance in one option that would probably work too.


Mark Green

Working on Civil 3D in Canada

Message 11 of 16
troma
in reply to: jkwilliams

FMOD is probably a better way to go than g-TRUNCg.  It messed up on me once though, didn't want to work in an alignment label referencing the profile.  But it should work.


Mark Green

Working on Civil 3D in Canada

Message 12 of 16
jefflambert9091
in reply to: troma

Why not just create 1 style with 3 components. Distance 1(0.0), Distance 2 (0.00) and Distance 3(0.000)? Each component can have the desired precision and rounding.

Jeff
Civil 3D 2024
Message 13 of 16
troma
in reply to: jefflambert9091

Or why not use a dimension with the option to Suppress Trailing Zeros?


Mark Green

Working on Civil 3D in Canada

Message 14 of 16
jkwilliams
in reply to: troma

Hi, and thanks for the added question here.

I have been away from my email for a week, so I apologise for the delay in responding.

I may need to describe the problem a little better.

In Australia it is a requirement to display line lengths to two or three decimal places for Cadastral Plan submission to our State Authorities.

However it is a requirement to suppress the trailing zeros, for example.

 

If the line length is 45.678  we need the line label to display 45.68 (precision 2 places)

 

If the line length is 17.200 we need the line label to display 17.2 (precision 1 place)


If the line length is 32.000 we need the line label to display 32 (precision 0 places)

 

The functionality we require is the same as what a standard AutoCAD dimension style can achieve with the suppress trailing zeros check box.


We know we can construct 3 different civil 3d line label styles with the required precision setting, but this means we need 3 styles for every label we have and need to manually change the style to suit the line length.

 

Do you know of a way to achive this result using "Expressions"?

Message 15 of 16
BrianHailey
in reply to: jkwilliams

I figured writing out my solution here would be way too much so I wrote it up on my blog. You can read it HERE. You can't accomplish this with one component in your label because there is no way to control the precision. My solution is basically to test if the value rounded to the ones place is the same as if it were rounded to the thousandths place. If it is, return the value, if not return -1. In the component, use this expression and hide negative values. Repeat for the tenths, hundredths, thousandths, ten thousandths, etc. as far out as you need to go.

 

As an FYI, this solution will only work if your values will never be less then zero. If you are trying to do this for something like cut and fill labels or slopes, it won't work.

Brian J. Hailey, P.E.



GEI Consultants
My Civil 3D Blog

Message 16 of 16
jkwilliams
in reply to: BrianHailey

Brian,

I have now worked through all of the expressions you provided on your blog site for this issue, and it works a treat!

I used slightly different names for my expressions that will be more meaningful to my users, and this works extremely well for me.

Thanks very much for your input here, it is highly valued.

Best Regards,

Jim Williams

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report