Text Size Change ilogic

Text Size Change ilogic

M_Santi
Enthusiast Enthusiast
878 Views
9 Replies
Message 1 of 10

Text Size Change ilogic

M_Santi
Enthusiast
Enthusiast

I am trying to change the text size of a custom Iproperty using Ilogic. Is it possible to use a parameter to change the text size of a custom Iproperty text? I want to create a form using parameters to change the text size of each individual custom iproperty text.

 

 

 

Mikail_Santiaguel_0-1687280882677.png

 

0 Likes
Accepted solutions (1)
879 Views
9 Replies
Replies (9)
Message 2 of 10

A.Acheson
Mentor
Mentor

Hi @M_Santi 

 

Here is a method to access the titleblock formatted text font. Hopefully that will help you. 

Dim doc As DrawingDocument = ThisApplication.ActiveDocument

Dim sht As Sheet = doc.ActiveSheet

Dim tb As TitleBlock = sht.TitleBlock

Dim tbSketch As Sketch

tb.Definition.Edit(tbSketch)

For Each txtBox As Inventor.TextBox In tbSketch.TextBoxes
    If txtBox.FormattedText.Contains("CUST PART#")  Then
        txtBox.Style.FontSize = 0.3
    End If
Next

tb.Definition.ExitEdit(True)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 10

M_Santi
Enthusiast
Enthusiast

It's not working, I'm getting an error.

 

Mikail_Santiaguel_0-1687346342291.png

Mikail_Santiaguel_1-1687346359668.png

 

 

0 Likes
Message 4 of 10

Curtis_Waguespack
Consultant
Consultant

Hi @M_Santi 

 


@M_Santi wrote:

It's not working, I'm getting an error.


That error would suggest that there might not be an instance of the title block placed on the active sheet of the drawing.


Can you confirm that there is a title block on the sheet?

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 5 of 10

M_Santi
Enthusiast
Enthusiast

I got the code to work but did not solve what I wanted the code to do. I want.

iProperties.Value("Custom", "CUST PART#")

to be the only one that changes font size. The other custom properties font size changes with it.

0 Likes
Message 6 of 10

M_Santi
Enthusiast
Enthusiast

I found one that kinda works, but I want to change the fontsize and not WidthScale.


Dim
oTG As TransientGeometry oTG = ThisApplication.TransientGeometry Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = oDoc.ActiveSheet Dim oTB As TitleBlock oTB = oSheet.TitleBlock Dim oDef As TitleBlockDefinition oDef = oTB.Definition 'open sketch in edit mode Dim oSketch As DrawingSketch Call oDef.Edit(oSketch) Dim oTextBoxes As TextBoxes oTextBoxes = oSketch.TextBoxes Dim oBox As TextBox For Each oBox In oTextBoxes If oBox.Text = "<CUST PART#>" Then 'The text parameter you want to change Call oDef.Edit(oSketch) oBox.WidthScale = 0.8 Call oDef.ExitEdit(True) End If Next InventorVb.DocumentUpdate()

 

0 Likes
Message 7 of 10

A.Acheson
Mentor
Mentor

Hi @M_Santi 

If the style change is not acceptable then you can overide the font of the attribute manually then run formatted text code again and send it to the logger.Info(). The overide font should appear in the formatted text. 

 

AAcheson_0-1687484782602.png

Dim doc As DrawingDocument = ThisApplication.ActiveDocument

Dim sht As Sheet = doc.ActiveSheet

Dim tb As TitleBlock = sht.TitleBlock

Dim tbSketch As Sketch

tb.Definition.Edit(tbSketch)

For Each txtBox As Inventor.TextBox In tbSketch.TextBoxes
    If txtBox.FormattedText.Contains("CUST PART#") Then
		Logger.Info(txtBox.Text)
		Logger.Info(txtBox.FormattedText)
		txtBox.FormattedText ="<StyleOverride FontSize='0.61'><Property Document='drawing' PropertySet='User Defined Properties' Property='CUST PART#' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='5'>CUST PART#</Property></StyleOverride>"
    End If
Next

tb.Definition.ExitEdit(True)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 8 of 10

M_Santi
Enthusiast
Enthusiast

It works to a certain extent. Is it Possible to use a parameter to determine the font size? I want to create a form using the parameter to change the font size. 

0 Likes
Message 9 of 10

A.Acheson
Mentor
Mentor
Accepted solution

Hi @M_Santi 

Yes you can concatenate the string found with the parameter. 

Dim fontsize as String = "0.61"
txtBox.FormattedText ="<StyleOverride FontSize='" & fontsize & "'.........write rest of text"
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 10 of 10

M_Santi
Enthusiast
Enthusiast

Thank you, this works perfectly of how I want it.

0 Likes