parameter driven text size for text field in sketch

parameter driven text size for text field in sketch

jerome.darbellay
Participant Participant
1,042 Views
5 Replies
Message 1 of 6

parameter driven text size for text field in sketch

jerome.darbellay
Participant
Participant

Good day

I am looking for a solution to have the size (height) of various text fields in my sketch (which is a logo) automatically adjusted with a scale factor of my overall logo size.

 

Example: my logo is 100mm long (variable “Length”, I would like to have the size of text field 1 to be 0.2*Length, size of text field 2 to be 0.35*Length, size of text field 3 to be 0.15*Length and so on…

 

I’ve searched the Inventor forum on this topic and reviewed the information in the topic “Having text size based on another parameter”. I’ve tested the iLogic script proposed by @Lewis.Young in message 3. When I test this script, it will change the text value to “False” instead of changing the size (see screen capture). I have included my test file as an example.

 

Please note that I’ve no experience with iLogic nor VBA programming…

Thanks in advance for your help!

0 Likes
Accepted solutions (3)
1,043 Views
5 Replies
Replies (5)
Message 2 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

Avoid to construct too long lines with several assignments and conditions.

Here is modified version of your code

 

Dim odoc As PartDocument

odoc = ThisApplication.ActiveDocument
 
Dim osketch As Sketch

'The used sketch name in the extrusion is Text

osketch =odoc.ComponentDefinition.Sketches.Item("Sketch2")

Dim textSize = Longueur * 0.15 / 10 ' mm -> cm (internal units)
Dim originalText = osketch.TextBoxes(1).Text

Dim formattedText = String.Format("<StyleOverride FontSize='{0}'>{1}</StyleOverride>", textSize, originalText)
osketch.TextBoxes.Item(1).FormattedText = formattedText
 
odoc.Update

 

0 Likes
Message 3 of 6

jerome.darbellay
Participant
Participant

Hi @Michael.Navara 

Thank you very much for your answer!
This script works for the text size update, but also changes the text font (to Arial in my case), which is not desirable since I have specific font to use for my logo. How to retain the text font?

Another question: how do I know which index number (TextBoxes(1), TextBoxes.Item(1) / TextBoxes(2), TextBoxes.Item(2), so on) corresponds to which text field since I have more than 10 text fields to update? Is there a way to determine this without having to do iterative modification until I find the right index number of each text field?

0 Likes
Message 4 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

How to specify the font describes this article

To the second question. You can browse the object tree using different tools. I use this VBA Object Browser for Inventor. Using this tool, you can easily select for example the sketch and look what is inside. Then you can get the indices of individual TextBoxes and use them in your code. Another approaches, such as parsing the text field's "Text" property or labeling the text field with attributes, seem too complex for this purpose.

0 Likes
Message 5 of 6

jerome.darbellay
Participant
Participant
Accepted solution

Thanks @Michael.Navara  ! Great support !!

It took me a few trials to get this working to my liking…

I used the tool VBA Object Browser for Inventor you mentioned. But without any knowledge of VBA, I needed some time to understand all the steps. Worked perfectly for my needs. Thanks for sharing!

For the record, below a snippet of the code I ended using.

Dim odoc As PartDocument

odoc = ThisApplication.ActiveDocument
 
Dim osketch As Sketch

'The used sketch name in the extrusion is Text

osketch =odoc.ComponentDefinition.Sketches.Item("Sketch2")

'TextBoxes(1) is for text "e"
Dim textSize1 = Longueur * 0.125 / 10 ' mm -> cm (internal units)
Dim originalText1 = osketch.TextBoxes(1).Text

Dim formattedText1 = String.Format("<StyleOverride Font='Formata' FontSize='{0}'>{1}</StyleOverride>", textSize1, originalText1)
osketch.TextBoxes.Item(1).FormattedText = formattedText1

'TextBoxes(2) is for text "so"
Dim textSize2 = Longueur * 0.127 / 10 ' mm -> cm (internal units)
Dim originalText2 = osketch.TextBoxes(2).Text

Dim formattedText2 = String.Format("<StyleOverride Font='Formata Regular' FontSize='{0}'>{1}</StyleOverride>", textSize2, originalText2)
osketch.TextBoxes.Item(2).FormattedText = formattedText2

'and so on...

odoc.Update

 

0 Likes
Message 6 of 6

engineer_climeco
Explorer
Explorer

I like the idea of changing the fontsize of textboxes with a parameter. The only thing I miss is to do this on sketch or document base for all textboxes per sketch or document. I think per sketch is the easiest way, but the 1st Ilogic rule of @Michael.Navara only changed 1 textbox and not the other 200+ ones or more...  (it's a huge building site with that number of axis and there are drawings with manymore labels I want to do change fontsizes with parameters).

 

Can somebody help with in this 1st Ilogic rule with something If fontsize <> "Font_size_parameter1"; Change fontsize to "Font_size_parameter1" EndIf

 

Thnx in avance

0 Likes