Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Font using VBA

5 REPLIES 5
Reply
Message 1 of 6
DNORDWICK
2860 Views, 5 Replies

Change Font using VBA

When I change the font using the attached code
the font of everything in the drawings changes not just the new text. I would like to change the font of the new text only. Does anyone know what I an doing wrong.
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: DNORDWICK

The attached code changes the font of the currently active text style. This
is the text style that is in use by existing text boxes within the sketch,
hence you notice that all of them change.

In order to control the text style for new text boxes only, you need to
change the 'active text style' defined in the active 'Object Defaults'
style. To do this via the API:

1. You first need to create a new text style (or identify a text style that
contains the font of interest).
2. Get the active ObjectDefaultsStyle from:
DrawingStylesManager.ActiveStandardStyle.ActiveObjectDefaults
3. Set the ObjectDefaultsStyle.SketchTextStyle to the new text style.

This will change the text style used for newly created text boxes.

An alternative is to specify the desired text style during the text box
creation via the API. Input the TextStyle object as the last (third)
argument to the TextBoxes.AddFitted method. This does not change the 'active
text style', but applies the specified text style to the new text box only.

Sanjay-


wrote in message news:5584950@discussion.autodesk.com...
When I change the font using the attached code
the font of everything in the drawings changes not just the new text. I
would like to change the font of the new text only. Does anyone know what I
an doing wrong.
Message 3 of 6

I have coded as bellow, but it's still change font of all textboxes

Dim oTG As TransientGeometry
Dim oSketch As DrawingSketch
Dim oTextBox As TextBox
Dim oDrawDoc As DrawingDocument
Dim oStyle As ObjectDefaultsStyle

oTG = m_inventorApplication.TransientGeometry
oDrawDoc = m_inventorApplication.ActiveDocument
oStyle = oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults
oSketch = oDrawDoc.ActiveSheet.Sketches.Add
oSketch.Edit()
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(1, 0.5), "test line 1", oStyle.SketchTextStyle)
oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
oTextBox.Style.Font = "My font"
oSketch.ExitEdit()

Message 4 of 6

Hi,

 

You missed the part of creating a new text style and the using that for the new text box.

 

Using oStyle.SketchTextStyle to create the text and then doing oTextBox.Style.Font = "My font" is the same as oStyle.SketchTextStyle.Font = "My font", so you'll change the font for everything that is using that specific style.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 6
Michel.Brun
in reply to: adam.nagy

Hi,

 

 

You missed the part of creating a new text style and the using that for the new text box.

 

Using oStyle.SketchTextStyle to create the text and then doing oTextBox.Style.Font = "My font" is the same as oStyle.SketchTextStyle.Font = "My font", so you'll change the font for everything that is using that specific style.

 

I don't really understand what you mean.

Do you have some examples?

 

 

 

Thx in advance

 

Cordially

 

Michel

 

Message 6 of 6
daniel.balogh
in reply to: Michel.Brun

Hi, if you want the font set to this particular Textbox only, you may consider not to manipulate the style, rather edit the FormattedText Property of the Textbox

 

This would be something like

 

oTExtBox.FormattedText= "<StyleOverride Font='Arial'>My text</StyleOverride>"

 

You can append several Overrides. like

 

oTExtBox.FormattedText= "<StyleOverride Font='Arial'>My Arialtext</StyleOverride>, My StyleText, <StyleOverride Italic='True'>My italictext</StyleOverride>"

HTH,

Daniel

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report