09-17-2020
08:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-17-2020
08:13 AM
Yes. It can definitely work with an existing DrawingSketch & existing TextBox.
Here's a modified version of my previous code.
(I edited the code in my last post a couple times, right after I posted it to to a misplaced variable name. That may have been what caused the error.)
See if this will work for you.
Sub Main
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 oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oBorder As Inventor.Border = oSheet.Border
Dim oSketch As DrawingSketch = oSheet.Sketches.Item(1) 'you can supply a name, if it has one
oSketch.Edit
Dim oTextBox As TextBox = oSketch.TextBoxes.Item(1) 'you can supply a name, if it has one
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
oTextBox.Style = GetTStyle(oDDoc)
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
End Sub
Function GetTStyle(ByRef oDoc As Document) As TextStyle
Dim oTStyles As TextStylesEnumerator = oDoc.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)
Return oTStyle
End Function
Wesley Crihfield
(Not an Autodesk Employee)