- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I want to change the width of a textbox used in a Sketched Symbol.
I know there is the Width property inside the TextBox Object. The syntax is given as TextBox.Width() As Double from the Inventor 2022 API Help. The value is given as read/write property.
My question: Has anyone managed to write back the value? And if so, how did you do it?
My code should be used at drawings. Check all Sketched Symbols. If a Sketched Symbole with special name is existing, check the value of textbox <Number>. Get the length of the value and calculate the needed space for it. The textbox <Number> is created as Type Prompted Entry to make it changeable by user.
Finding and reading are working, but write back the value into TextBox.Width is not possible for me.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
Dim oSketchedSymbol As SketchedSymbol
Dim oSketchDef As Sketch
Dim oTextBoxes As TextBoxes
Dim iTextBox As Inventor.TextBox
For Each oSketchedSymbol In oSheet.SketchedSymbols
If oSketchedSymbol.Name = "NameOfSketchedSymbol" Then
oSketchDef = oSketchedSymbol.Definition.Sketch
oTextBoxes = oSketchDef.TextBoxes
Dim jEintrag As String
For j = 1 To oTextBoxes.Count
iTextBox = oTextBoxes.Item(j)
If iTextBox.Text = "<Number>" Then
jEintrag = oSketchedSymbol.GetResultText(iTextBox)
Dim iLengthOfValue As Integer
iLengthOfValue = Strings.Len(jEintrag)
Dim dLengthValue, dFittedLengthValue, dValue As Double
'Calculate needed width
dLengthValue = iLengthOfValue * 1.5
'Set value of TextBox.Width
' iTextBox.Width = dLengthValue 'that is what I want
' iTextBox.Width = iTextBox.Width * 0.1 'try 1
' iTextBox.Width = 30.5623 'try 2
'Check value of Textbox.Width
dValue = iTextBox.Width
MessageBox.Show("Length of string " & iLengthOfValue & vbNewLine & "Calculated width of Textbox " & dLengthValue & vbNewLine & "Width value of Textbox " & dValue)
End If
Next
End If
Next
The messagebox is only for debugging used.
Line 34 runs into an error with this message.
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.TextBox.set_Width(Double )
at ThisRule.Main() in rule: Forum, in document SketchedSymbolTest.idw:line 34
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Line 35: writing a value direct at the property runs in an error, too.
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.TextBox.set_Width(Double )
at ThisRule.Main() in rule: Forum, in document SketchedSymbolTest.idw:line 35
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Any help is appreciated. Thanks.
Greetings,
Jana
Solved! Go to Solution.