How to control text size of Embossed text from parameters or iLogic

How to control text size of Embossed text from parameters or iLogic

chris
Advisor Advisor
410 Views
5 Replies
Message 1 of 6

How to control text size of Embossed text from parameters or iLogic

chris
Advisor
Advisor

Has anyone had luck with figuring out a way to access the text size so I can control it with parameters or iLogic, and have it change based on the size of the object.

Parameters gives me access to the emboss cut or raise distance, but nothing for the "text" size.

0 Likes
411 Views
5 Replies
Replies (5)
Message 2 of 6

BDCollett
Advisor
Advisor

You can use iLogic to change the text override.

 

Here is the iLogic I found to create and edit text with iLogic so just tie that into the parameters.

 

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document
Dim oCd As ComponentDefinition
oCd = oPartDoc.ComponentDefinition
Dim oTextbox As TextBox
Dim oSketch As PlanarSketch

For Each oSketch In oCd.Sketches
    For Each oTextbox In oSketch.TextBoxes
		oText = "Hello World"	
		oFontSize = 10
		oTextbox.FormattedText = "<StyleOverride FontSize = '" & oFontSize & "'>" & oText & "</StyleOverride>"
    Next
Next

iLogicVb.UpdateWhenDone = True
0 Likes
Message 3 of 6

chris
Advisor
Advisor

@BDCollett Thanks for the snippet, when I run it, it changed all existing "text" to "Hello World". When I commented out the oText =, in the hopes that my existing text(s) would stay but only change size, they all disappeared after running the rule?

0 Likes
Message 4 of 6

BDCollett
Advisor
Advisor

I don't think so, but I would ask on Inventor Programming forum to see.

 

As it's doing an override, it is creating the text and then setting the size.

Can you not just add the text you want into the script, then change the font size based on a parameter for the changing size of the object in this case?

Something like this:

Dim oPartDoc As PartDocument
oPartDoc = ThisDoc.Document
Dim oCd As ComponentDefinition
oCd = oPartDoc.ComponentDefinition
Dim oTextbox As TextBox
Dim oSketch As PlanarSketch

If OBJECT = 5

For Each oSketch In oCd.Sketches
    For Each oTextbox In oSketch.TextBoxes
		oText = "TEXT GOES HERE"	
		oFontSize = 5
		oTextbox.FormattedText = "<StyleOverride FontSize = '" & oFontSize & "'>" & oText & "</StyleOverride>"
    Next
Next
End If

If OBJECT = 10
For Each oSketch In oCd.Sketches
    For Each oTextbox In oSketch.TextBoxes
		oText = "TEXT GOES HERE"	
		oFontSize = 10
		oTextbox.FormattedText = "<StyleOverride FontSize = '" & oFontSize & "'>" & oText & "</StyleOverride>"
    Next
Next

End If
iLogicVb.UpdateWhenDone = True
Message 5 of 6

chris
Advisor
Advisor

@BDCollett Basically, I have a series of "embossed" texts that I need their sizes to be a ratio of the features they are embossed. For example, if I add text to a W-Beam that has a Flange width of 6" then I need the text height for that "single" embossed text to be that 6" parameter-20%.

 

I tried that with your sample code, where I made a 1" OD tag, and then added a single text letter to it to and for the ofontSize to equal "d0", but it's only a fraction of the size? (part is in 2025)

0 Likes
Message 6 of 6

BDCollett
Advisor
Advisor

It seems the font is always metric, so you need to convert it you want 1in = 1in font. 

Write some code and link parameters to do what you want.

 

Here I created parameters for FONT and FONT_ROUND. This allows to take a parameter, round it and convert.

Then make FONT = d0*.25 or whatever you need it to be in relation to the driving parameter.

 

'Round Font parameter to nearest 0.1 inch
FONT_ROUND
= Round(FONT * 1ul / 0.1 in) * 0.1 in
Dim oPartDoc As PartDocument oPartDoc = ThisDoc.Document Dim oCd As ComponentDefinition oCd = oPartDoc.ComponentDefinition Dim oTextbox As TextBox Dim oSketch As PlanarSketch For Each oSketch In oCd.Sketches For Each oTextbox In oSketch.TextBoxes oText = "B" oFontSize = FONT_ROUND oTextbox.FormattedText = "<StyleOverride FontSize = '" & oFontSize & "'>" & oText & "</StyleOverride>" Next Next iLogicVb.UpdateWhenDone = True