Provide multiple fonts in single ModelLeaderNoteDefinition

Provide multiple fonts in single ModelLeaderNoteDefinition

ramasamy_thangaperumal
Participant Participant
620 Views
10 Replies
Message 1 of 11

Provide multiple fonts in single ModelLeaderNoteDefinition

ramasamy_thangaperumal
Participant
Participant

I want to provide different font size in one Model Leader note definition like attached image. Is there any possible way to do this?

0 Likes
Accepted solutions (1)
621 Views
10 Replies
Replies (10)
Message 2 of 11

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi @ramasamy_thangaperumal,

 

You could use the Formatted Text property as folowing :

Dim o As Inventor.ModelLeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "")
o.Definition.Text.FormattedText = "<StyleOverride FontSize='0,6'>4</StyleOverride>(4x)"

 

What you can do to get the  actual string on line 2 is format the text, copy it co clip board (ctrl + c) & paste it in the code afterwards :

Dim o As Inventor.ModelLeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "")
My.Computer.Clipboard.SetText(o.Definition.Text.FormattedText.ToString) 

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 11

gerrardhickson
Collaborator
Collaborator

@FINET_Laurent is right - use the FormattedText property.

Whenever I want to set formatting for drawing views (or other objects) I manually set the object as an example, use VBA to extract the formatted text string, then paste it back to my code like @FINET_Laurent suggested, but you'll want to build your own string by replacing the text you manually typed with the text generated by your code.

Message 4 of 11

ramasamy_thangaperumal
Participant
Participant

Thanks for the quick reply. It is working for me. Like this can we able to change the color?

0 Likes
Message 5 of 11

gerrardhickson
Collaborator
Collaborator

Yes - its the same process... Manually create a text box and change the colour, then have a look at the FormattedText property in VBA, and adjust it to suit your needs.

0 Likes
Message 6 of 11

ramasamy_thangaperumal
Participant
Participant

Can you share me sample code? FormattedText = <styleoverride color="Here what should i need to provide(RGB / color name)">.

0 Likes
Message 7 of 11

gerrardhickson
Collaborator
Collaborator

My apologies - you set the text colour using the color property - sample code below.

 

The TransientObjects.CreateColour() method uses 3 inputs as RGB values between 0 and 255.

 

Sub GetFormattedText()

Dim oSS As SelectSet
Set oSS = ThisApplication.ActiveDocument.SelectSet

Dim oObj As Object
Dim oTB As GeneralNote

Dim oCol As Color
Set oCol = ThisApplication.TransientObjects.CreateColor(255, 0, 0)

For Each oObj In oSS
    If oObj.Type = kGeneralNoteObject Then
        oTB.Color = oCol
    End If
Next oObj

End Sub

 

 Unfortunately it appears that you can't change SOME of your text - you must change the colour of the whole text box only.

 

I hope that helps.

0 Likes
Message 8 of 11

ramasamy_thangaperumal
Participant
Participant

@gerrardhickson Thanks for your support. Actually, I want to change multiple color like how I am trying to change multiple font size. 

o.Definition.Text.FormattedText = "<StyleOverride FontSize='0,6'>4</StyleOverride>(4x)"

Here for text "4" I am setting one font size. like same way I want to change color only for text"4x". 

text = 4(4x)

0 Likes
Message 9 of 11

gerrardhickson
Collaborator
Collaborator

Hi, I understand what you hope to do, but I don't believe it is possible.

0 Likes
Message 10 of 11

ramasamy_thangaperumal
Participant
Participant

Thanks @gerrardhickson . @FINET_Laurent Can you support me on this color change code?

0 Likes
Message 11 of 11

FINET_Laurent
Advisor
Advisor

Hi @ramasamy_thangaperumal 

 

Indeed you can only have one color for the whole text note.

To get the color of an existing one (already formatted), here is the code :

Dim o As Inventor.ModelLeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "")
Dim rgb As String = o.Definition.Text.Color.Red & " - " & o.Definition.Text.Color.Green & " - " & o.Definition.Text.Color.Blue
MsgBox(rgb)

 

To create a new color and set it to the selected note, here is the code :

Dim o As Inventor.ModelLeaderNote = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "")
Dim c As Inventor.Color = ThisApplication.TransientObjects.CreateColor(100, 150, 200)
o.Definition.Text.Color = c

About colors : https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=TransientObjects_CreateColor


Note you can mark multiples replies as solution in the same post.


Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes