Textbox string change

Textbox string change

kacper_sikorskiD42JA
Contributor Contributor
297 Views
2 Replies
Message 1 of 3

Textbox string change

kacper_sikorskiD42JA
Contributor
Contributor

Hello, i've encountered a problem with TextBoxes

I wrote a code that should just change the 26th TextBox in titleblock if it's a "part drawing".

I can read from this textbox just fine but when i try to change it's value i get an error

 

Does anyone know how to fix it?

kacper_sikorskiD42JA_0-1727790892975.png

 

Dim document As Document = ThisApplication.ActiveDocument
Dim drw As DrawingDocument = document

Dim titleBlock As TitleBlock = drw.ActiveSheet.TitleBlock
Dim resultText As String = titleBlock.GetResultText(titleBlock.Definition.Sketch.TextBoxes(10))

Dim Iteration As Integer
Iteration=1
While (Iteration < 100)
	resultText = titleBlock.GetResultText(titleBlock.Definition.Sketch.TextBoxes(Iteration))
	Logger.Info(Iteration)
	Logger.Info(resultText)
	Iteration = Iteration + 1
	If (resultText = "-GA drawing-" Or resultText = "part drawing" Or resultText = "-Assy drawing-")
		Exit While
	End If
End While

If (resultText = "-GA drawing-") Then
	resultText = titleBlock.GetResultText(titleBlock.Definition.Sketch.TextBoxes(18))
End If

If (resultText = "-Assy drawing-") Then
	resultText = titleBlock.GetResultText(titleBlock.Definition.Sketch.TextBoxes(10))
End If

If (resultText = "part drawing") Then
	Dim First As TextBox
	Dim Second As TextBox
	Dim Third As TextBox
	
	First = titleBlock.Definition.Sketch.TextBoxes(26)
	titleBlock.SetPromptResultText(First, "Text Needed")
End If

 

Thanks in advance for all the answers 😄

0 Likes
298 Views
2 Replies
Replies (2)
Message 2 of 3

J_Pfeifer_
Advocate
Advocate

This reference might be of some help to you :

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-915B75BA-4696-4fc7-A2C6-54B2BACDE7E1#Prom...

 

Interacting with textboxes can differ depending on the environment and situation of the item you're attempting to change. Most of my sketched symbols and title blocks contain prompted entries. Meaning I have no other way to input strings to those unless I pass them using the .setpromptresulttext.

 

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Hi @kacper_sikorskiD42JA.  One of the first things I would suggest is that when you 'declare' a variable for a TextBox, declare its Type as 'Inventor.TextBox', not just 'TextBox', because that Type name commonly gets confused with the System.Windows.Forms.TextBox Type.  I would also set the TitleBlock.Definition.Sketch.TextBoxes collection to a variable as early in that code as possible, then use that variable for all further actions which use that collection throughout the rest of your code.  Also, does this code get triggered to run automatically by any events?  If so, then it would be wise to switch from using 'ThisApplication.ActiveDocument' code phrase, to using the 'ThisDoc.Document' code phrase, because that will help ensure it is targeting the correct document in those types of situations.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes