Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

C# .net How do I access a custom expression within line label style and curve label style

jeff.wangD95HG
Advocate

C# .net How do I access a custom expression within line label style and curve label style

jeff.wangD95HG
Advocate
Advocate

so in toolspace view it will be located here

jeffwangD95HG_0-1734108165441.pngjeffwangD95HG_1-1734108235737.png

and inside expression there will be CSF expression that is just 1. I want to be able to write a function that will modify that 1 into any other number for example 0.9996851. and the same thing will occur for curve label style. 

I will then see if I can also do the same for parcels but I am not sure if that is only for civil 3d

0 Likes
Reply
Accepted solutions (1)
119 Views
2 Replies
Replies (2)

norman.yuan
Mentor
Mentor
Accepted solution

So, you want to an expression's value, depending on the need of the business/drawing content (in your case, it is custom scale factor with value being 1.0, and depending on the job location the drawing content presented, you want to be able to use code to set the expression "CSF"'s value to 0.999xxxx, am I right?).

 

Yes, you can do it by going to CivilDocument.Styles.LabelStyles.XXXXXXLabelStyles.Expressions. With the target ExpressionCollection available, you can then identify the target expression by its name (in your case, the name is "CSF"), then you update Expression.ExpressionString property (replacing "1", or "1.0" with "0.999xxxx")

 

Say, if you want to update the expression of GeneralLineLabelStyle, the pseudocode would be like:

 

foreach (var exp in CivilApplication.ActiveDocument.Styles.LabelStyles.GeneralLineLabelStyles.Expressions)

{

   if (exp.Name == "CSF")

   {

      // parse the ExpressString property (a string value) to correctly replace the value in the string

   }

}

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes

jeff.wangD95HG
Advocate
Advocate

ok thanks it works

i didn't realize its a "string" which got me all confused. Because that is obviously used for calculation and can't be a string

0 Likes