Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: Chris.Truelove

Sorry I didn't get back with you sooner on this matter in the last post.  I got caught away at work.

Here's what I was working on yesterday for you.

There are several lines commented out, just to show some optional possibilities.

I was actually thinking specifying the font and its size by specifying the TextStyle you wanted to use, instead of the more difficult route of specifying the individual Font Name, and Font Size, etc.

Then putting a block of code to check the resulting text size compared to the text box size, then offering some options to help correct any issues, in a few different ways like in the following code.

This code I am testing with an A-Size sheet (8.5 in x 11 in), and have a simple rectangle border that is .25 in from all sides of the sheet.  And the rectangle for my text box is being translated to Inches by multiplying by 2.54.

It places the TextBox in the lower left corner of this border (just as an example).

 

 

 

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oBorder As Inventor.Border = oSheet.Border

Dim oTStyles As TextStylesEnumerator = oDDoc.StylesManager.TextStyles
Dim oTStyle As TextStyle
Dim oTStylesNames As New List(Of String)
For Each oTStyle In oTStyles
	oTStylesNames.Add(oTStyle.Name)
Next
Dim oTStyleName As String = InputListBox("Select a TextStyle for this TextBox.",oTStylesNames," ","Available TextStyles")
oTStyle = oTStyles.Item(oTStyleName)

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPoint1 As Point2d = oBorder.RangeBox.MinPoint
Dim oPoint2 As Point2d = oTG.CreatePoint2d(oPoint1.X + (3*2.54), oPoint1.Y + (.75*2.54))

Dim oSketch As DrawingSketch = oSheet.Sketches.Add
oSketch.Edit

Dim oText As String = InputBox("Enter new Title Text", " ")

'Dim oFText As String = "<StyleOverride Font='Simplex' FontSize='18' Bold-'True' Italic='False' Underline='False'>" & oText & "</StyleOverride>"
'Dim oTextBox As Inventor.TextBox = oSketch.TextBoxes.AddByRectangle(oPoint1, oPoint2, oFText)
Dim oTextBox As Inventor.TextBox = oSketch.TextBoxes.AddByRectangle(oPoint1, oPoint2, oText, oTStyle)
'oTextBox.ShowBoundaries = True
'iLogicVb.DocumentUpdate
'MsgBox("There are " & oTextBox.BoundaryGeometry.Count & " entities within oTextBox.BoundaryGeometry.")
'For Each oSE As SketchEntity In oTextBox.BoundaryGeometry
'	oSE.SketchOnly = False
'	oSE.Construction = False
'	oSketch.GeometricConstraints.AddGround(oSE)
'Next
'oTextBox.ShowBoundaries = True
FitCheck :
If oTextBox.FittedTextWidth > oTextBox.Width Then
	oAns = MsgBox("The text is wider than the text box." & vbCrLf & _
	"Do you want to:  Reduce Font Size [Yes], Edit the contents [No], or Leave it that way [Cancel]?", vbYesNoCancel + vbQuestion, " ")
	If oAns = vbYes Then
		oNewTStyleName = InputListBox("Select a TextStyle for this TextBox.",oTStylesNames," ","Available TextStyles")
		oTextBox.Style = oTStyles.Item(oNewTStyleName )
		'Then GoTo FitCheck (the beginning Of this Size Check Process)
		GoTo FitCheck
	ElseIf oAns = vbNo Then
		oTextBox.Text = InputBox("Edit contents.", " ", oTextBox.Text)
		GoTo FitCheck
	End If  'Don't really need to deal with what happens when they choose Cancel.
End If
oSketch.ExitEdit

 

 

 

Let me know how this works for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)