append text to label

append text to label

Yonas89
Collaborator Collaborator
1,308 Views
14 Replies
Message 1 of 15

append text to label

Yonas89
Collaborator
Collaborator

Hello,

 

I am trying to append text to my profile view label, which has  been just created. I have found text override example on the internet which also works in my case, however I don't want to override my label text completely, I just want to append additional text before  by label value. What should I do different? Thanks!

 

Here is a clip from my code:                      

 

ProfileViewDepthLabel.Create(PV.ObjectId, IdLabelStyle, pt1, pt2)
                    Dim lastEntity As ObjectId = Autodesk.AutoCAD.Internal.Utils.EntLast()
                    Dim DPLabel As ProfileViewDepthLabel = tr.GetObject(lastEntity, OpenMode.ForWrite)
                    DPLabel.SetTextComponentOverride(DPLabel.GetTextComponentIds(0), "Override", Autodesk.Civil.TextJustificationType.Left)
0 Likes
Accepted solutions (1)
1,309 Views
14 Replies
Replies (14)
Message 2 of 15

Jeff_M
Consultant
Consultant
Use the GetTextComponentOverride() method and add your text to the result.

Also, no need to use the EntLast method. Just do this:
Dim lastEntity As ObjectId = ProfileViewDepthLabel.Create(PV.ObjectId, IdLabelStyle, pt1, pt2)
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 15

Yonas89
Collaborator
Collaborator

Thanks for your reply Jeff!

 

However I am still struggling...

 

should i delete SetTextComponentOverride()?

 

 

 

 

0 Likes
Message 4 of 15

Jeff_M
Consultant
Consultant
Accepted solution

 

No, get the current override, add your text to that, use the SetTextComponentOverride to add the combined text back to the label. Something like this...I don't normally use VB so this may not be exactly correct.

 


Dim str as String = DPLabel.GetTextComponentOverride(DPLabel.GetTextComponentIds(0)) DPLabel.SetTextComponentOverride(DPLabel.GetTextComponentIds(0), "Override:" + str)

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 15

Yonas89
Collaborator
Collaborator

Thanks a lot!

0 Likes
Message 6 of 15

Yonas89
Collaborator
Collaborator

Also, I face some further problem, as an "override" text appears in different text style. How to match these text styles?

Thank you very much in advance!

0 Likes
Message 7 of 15

Jeff_M
Consultant
Consultant
A more specific description, along with a drawing and your code, would sure help in this. As I'm not quite sure what you are asking...
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 8 of 15

Yonas89
Collaborator
Collaborator
Well now I got this which works just fine.       
 
                    Dim MDepthLb As ObjectId = ProfileViewDepthLabel.Create(PV.ObjectId, IdLabelStyle, pt1, pt2)
 
                    Dim DPLabel As ProfileViewDepthLabel = tr.GetObject(MDepthLb, OpenMode.ForWrite)
 
                    Dim DPLabelstr As String = DPLabel.GetTextComponentOverride(DPLabel.GetTextComponentIds(0))
 
                    DPLabel.SetTextComponentOverride(DPLabel.GetTextComponentIds(0), "override" + DPLabelstr)
 
But the text font and height of DPLabestr and "override" are different. Seems that the "override" string is using standart text style and default height.
 
I need to get text style of DPLabel text component somehow but cannot achieve this.
0 Likes
Message 9 of 15

Jeff_M
Consultant
Consultant
Have you changed the style/font used for the textcomponent to be different than what the Style's General settings specify? Check the value returned by the GetTextComponentOverride. If it has font/textstyle information included then you will have to do additional string parsing.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 10 of 15

Yonas89
Collaborator
Collaborator

Thanks for the tip, however no luck yet. I am not able to extract font/textstyle from GetTextComponentOverride.

0 Likes
Message 11 of 15

Jeff_M
Consultant
Consultant
Can you post a drawing that you've edited with the code above?
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 12 of 15

Yonas89
Collaborator
Collaborator

My code basically puts depth labels along profile. You can see it in the drawing. I override  depth labels with  "-" sign where design profile is lower than compared profile.

0 Likes
Message 13 of 15

Jeff_M
Consultant
Consultant
OK, I see what you mean. I'm swamped today, will try to find a resolution as soon as I get a break.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 14 of 15

Yonas89
Collaborator
Collaborator

Thanks, Jeff

0 Likes
Message 15 of 15

Yonas89
Collaborator
Collaborator

Jeff, I have found the problem why my appended text was  in the different font. My label text style under general tab was left as Standart. This was a problem. I have changed this font now the minus sign appears in correct font. Thanks a lot for your help!