Part file sketch text height problem

Part file sketch text height problem

Anonymous
Not applicable
731 Views
4 Replies
Message 1 of 5

Part file sketch text height problem

Anonymous
Not applicable

Hi all,

 

I've got a really simple problem, I just can't figure it out.

 

I'm trying to change the font size of the text in a text box using the following code.

 

======================

Sub TextHeightTest()

 

Dim odoc As PartDocument
Dim textbox As textbox
Dim fontsize As Double

Set odoc = ThisApplication.ActiveDocument
Set textbox = odoc.ComponentDefinition.Sketches.Item(1).TextBoxes.Item(1)

fontsize = 0.35

 

textbox.Style.fontsize = fontsize

 

End Sub

======================

 

but I keep getting error message saying that "Method 'FontSize' of object 'TextStyle' failed".

 

Has anyone got any suggestions?

 

Thanks and Regards

0 Likes
Accepted solutions (1)
732 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Accepted solution

Figured it out...

 

Textbox.Styles.FontSize is not available for textboxes in parts or assemblies, only for textboxes in drawing documents

 

So... What you have to do is wrap your text in 'styleoverride' modifier...

 

My example ended up like this...

 

======================

Sub TextHeightTest()

 

Dim odoc As PartDocument
Dim textbox As textbox
Dim fontsize As Double

Set odoc = ThisApplication.ActiveDocument
Set textbox = odoc.ComponentDefinition.Sketches.Item(1).TextBoxes.Item(1)


 

textbox.formattedtext = "<StyleOverride FontSize='0.35'>TEST TEXT</StyleOverride>"

 

End Sub

======================

 

I've highlighted in red the bits that need to be added to the text....

0 Likes
Message 3 of 5

Anonymous
Not applicable

What else can you control with the <StyleOverride> tag? Any documentation? I need to control the stretch of the text to squeeze it into a text box.

0 Likes
Message 4 of 5

Anonymous
Not applicable

But text in formatted text is defined.(TEST TEXT)

 

How could we place occurrence names instead???

 

how colud we change font size of automated text in Sketch??

 

ANy suggesstions??

0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi guys,

 

My suggestion is to create a text box (manuall) using what ever formatting, fields etc that you desire. Then use VBA to get that object and view the formatted text object, and that'll give you the infomation you need.

 

I expect that you'll be able to control all the typical format methods (bold, italics, size, font, etc etc) and you'll also be able to add iproperties, and some other properties exposed to the text box tool...

 

Basically, if you can create it with a textbox in the GUI, then you'll be able to replicate it in vba.

 

Hope that helps.

 

Cheers

0 Likes