Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Different textstyles in one sketch (Drawing)

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jonas.lannoo
657 Views, 2 Replies

Different textstyles in one sketch (Drawing)

Hi everyone,

 

I'm a student and a beginner in VBA. I'm writing a macro to automatically draw text and lines in a drawing and it goes pretty well. But now I have encountered a problem. When I add text like this:

 

Dim FreqBox As TextBox
Set FreqBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(1.9, 1.95), GegevensForm.FrequentieVak.Value)

 

This is like I want it, but not the right font or size, so I add this:

 

FreqBox.Style.Font = "Arial"
FreqBox.Style.FontSize = 0.2

 

This goes well too, but then I want to add another TextBox, in another style, like this:

 

Dim VermogenBox As TextBox
Set VermogenBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(3.7, 3.2), GegevensForm.VermogenVak.Value)
VermogenBox.Style.Font = "Arial"
VermogenBox.Style.FontSize = 0.5
VermogenBox.HorizontalJustification = kAlignTextRight
VermogenBox.Style.Bold = True

 

And suddenly when I run this, the other text is changing to these settings... (exept for the alignment)

What am I doing wrong, or how should I do this?

Is it possible to do this without the FormattedText option? Because I am not good at that (if someone could explain maybe)

 

Thanks in advance.

 

Jonas

2 REPLIES 2
Message 2 of 3
t_hutns
in reply to: jonas.lannoo

Hi Jonas,

 

VermogenBox.Style.Font = "Arial" call modifies style so this change will affect all the texts using this style. One solution is to create copy of style, modify it and use this new style for new text, other solution is to use style overrides in FormattedText property. See the sample below for style copy and overrides:

 

Public Sub SketchTextAdd()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' Create a new sketch on the active sheet.
Dim oSketch As DrawingSketch
Set oSketch = oDrawDoc.ActiveSheet.Sketches.Add

' Open the sketch for edit so the text boxes can be created.
' This is only required for drawing sketches, not part.
oSketch.Edit

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

' Create text with simple string as input. Since this doesn't use
' any text overrides, it will default to the active text style.
Dim sText As String
sText = "Drawing Notes"
Dim oTextBox As TextBox
Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(3, 18), sText)

Dim oStyle As TextStyle
Set oStyle = oTextBox.Style

' Create style copy
Dim oStyleCopy As TextStyle
Set oStyleCopy = oStyle.Copy("MyStyle")

' Change copied style properties
oStyleCopy.Font = "Arial"
oStyleCopy.FontSize = 0.5
oStyleCopy.HorizontalJustification = kAlignTextRight
oStyleCopy.Bold = True

' Create text using copied style
sText = "Drawing Notes - Using custom style"
Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(3, 16), sText, oStyleCopy)

' Create text using active text style with overrides
sText = "<StyleOverride Font='Arial' FontSize='0.5' Bold='True'>Drawing Notes</StyleOverride> - Using overrides"
Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(3, 10), sText)
oTextBox.HorizontalJustification = kAlignTextRight

' Exit the sketch from the edit environment.
oSketch.ExitEdit
End Sub

 

 

Hope this helps

 

Stanislav Hutnan

Inventor Development

Autodesk

Message 3 of 3
asor71
in reply to: t_hutns

Sorry for my english it is not good

I choose a text formatting in the RichTextBox1 and want this  as sketches geometry

Can someone help me

 

XAxis = Sketch2.AddByProjectingEntity(partDef.WorkAxes.Item(1))

YAxis = Sketch2.AddByProjectingEntity(partDef.WorkAxes.Item(2))

Dim oTG As TransientGeometry

oTG = oInventorApp.TransientGeometry

Dim Text As String

Text = RichTextBox1.Text

Dim TextBox As TextBox

TextBox = Sketch2.TextBoxes.AddFitted(oTG.CreatePoint2d(0, 0), Text)

TextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle

TextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

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

Post to forums  

Autodesk Design & Make Report