ilogic to change field text in a sketched symbol

ilogic to change field text in a sketched symbol

DeepshipEngineering
Enthusiast Enthusiast
1,290 Views
16 Replies
Message 1 of 17

ilogic to change field text in a sketched symbol

DeepshipEngineering
Enthusiast
Enthusiast

I have tried a few things but this seems a bit beyond me, does anyone have some code I could look at to change the value of a prompted entry in a sketched symbol? Inventor 2023

 

Thanks

0 Likes
Accepted solutions (1)
1,291 Views
16 Replies
Replies (16)
Message 2 of 17

A.Acheson
Mentor
Mentor

 

Hi @DeepshipEngineering 

@This question is better suited on the Ilogic forum but here is a start point. See this article here on setting the printed entry of Symbol 1.

This is the ilogic code in that article. 

 

 

 

' Set the value for the first sketched symbol
' on the current sheet
Dim oSS As SketchedSymbol
oSS = ActiveSheet.Sheet.SketchedSymbols(1)

Dim oTB As TextBox
For Each oTB In oSS.Definition.Sketch.TextBoxes
  If oTB.Text = "<MyPrompt>" Then
    Call oSS.SetPromptResultText(oTB, "NewValue")
  End If
Next

 

 

If you want to find a specific symbol then you can directly reference the symbol object by first looping through all symbols and query the name with an if statement. 


' Find the sketch symbol by name by looping through all symbols 
For Each oSS As SketchedSymbol In ActiveSheet.Sheet.SketchedSymbols(1)
  If oSS.Name = "FindMe" Then
    MessageBox.Show(oSS.Name, “Found Symbol”)
    ‘Do something now with oSS object
  End If
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 17

DeepshipEngineering
Enthusiast
Enthusiast

Thanks but I cant seem to get it to work, could you attach a sketched symbol it works on so I can see where I am going wrong?

0 Likes
Message 4 of 17

A.Acheson
Mentor
Mentor

It sounds like your Property Field name is not matching. 

AAcheson_1-1728577573968.png

 

AAcheson_0-1728577546515.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 17

DeepshipEngineering
Enthusiast
Enthusiast

I think they are correct, (the only thing is the brackets <> but I have tried both ways) Tried a new symbol with your inputs but still no joy.

 

Can you send a symbol that its working with?

 

Thanks

0 Likes
Message 6 of 17

A.Acheson
Mentor
Mentor

The brackets are just the automatically applied formatting. if your Property Field name has none type the text string exactly. Can you share the error message your getting? Can you share images of your symbol prompt box when you manually go to fill it in? Can you share the modified code you have tried.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 17

jnowel
Advocate
Advocate

this "(1)" is the likely cause of the error.

jnowel_0-1728606981796.png

 

0 Likes
Message 8 of 17

DeepshipEngineering
Enthusiast
Enthusiast

What does that 1 do?

0 Likes
Message 9 of 17

jnowel
Advocate
Advocate
oSS = ActiveSheet.Sheet.SketchedSymbols(1)

 Sets oSS as the first item in the SketchSymbols collection.

Removing the (1) makes you to loop thru all the symbols.
I believe the previous post has it as a typo and meant it like this

' Find the sketch symbol by name by looping through all symbols 
For Each oSS As SketchedSymbol In ActiveSheet.Sheet.SketchedSymbols
  If oSS.Name = "FindMe" Then
    MessageBox.Show(oSS.Name, “Found Symbol”)
    ‘Do something now with oSS object
  End If
Next

 

Message 10 of 17

DeepshipEngineering
Enthusiast
Enthusiast

That works to find my sketched symbol, how do I then change the prompted entry? thanks

Message 11 of 17

jnowel
Advocate
Advocate
Accepted solution

Combined the posted code earlier.
Should look like this

edit: commented out Exit for 

edit2: should be working now

 

' Find the sketch symbol by name by looping through all symbols 
Dim oSS As SketchedSymbol

For Each oSS In ActiveSheet.Sheet.SketchedSymbols
	
	If oSS.Name = "FindMe" Then
	'    MessageBox.Show(oSS.Name, “Found Symbol”)
	'    Do something Now With oSS Object
	
	'Map you prompted text value as newValue
	Dim newValue As String
	newValue = "map your value here" 'change to suit
	
	'Scan all textbox then change if match
	Dim oTB As Object
	For Each oTB In oSS.Definition.Sketch.TextBoxes
		If oTB.Text = "<MyPrompt>" Then
			Call oSS.SetPromptResultText(oTB, newValue)
		End If
	Next
	End If
Next

 

 

Message 12 of 17

DeepshipEngineering
Enthusiast
Enthusiast

this is the error popping up

 

Error on Line 14 : 'TextBox' is ambiguous, imported from the namespaces or types 'Inventor, System.Windows.Forms'.
Error on Line 15 : 'oSS' is not declared. It may be inaccessible due to its protection level.

Message 13 of 17

jnowel
Advocate
Advocate

oops. check edit2 above

Message 14 of 17

DeepshipEngineering
Enthusiast
Enthusiast

Perfect...  I am going to try and and change the "map your value here" to a pop up message text input box unless you have a snippet you can throw in easily?

 

Im not a programmer but find with a mixture of very welcome help from the forums and a bit of ChatGPT I can muddle through most stuff

Message 15 of 17

jnowel
Advocate
Advocate
newValue = InputBox("Prompt", "Title", "Default Entry")
Message 16 of 17

DeepshipEngineering
Enthusiast
Enthusiast

@jnowel @A.Acheson 

 

Thank you so much for your help, got it doing exactly what I wanted

Message 17 of 17

jnowel
Advocate
Advocate

A different version resulting to a different behavior

'This version asks the newValue once and will be used to all found sketchedsymbol matching the criteria
'Previous version asks everytime the oSS is found, so you can enter a different value (if you just change the newValue inside the for loop

Dim oSS As SketchedSymbol

'Map you prompted text value as newValue
Dim newValue As String
newValue = InputBox("Prompt", "Title", "Default Entry") 'change to suit

For Each oSS In ActiveSheet.Sheet.SketchedSymbols
	
	If oSS.Name = "FindMe" Then
		
		'Scan all textbox then change if match
		Dim oTB As Object
		For Each oTB In oSS.Definition.Sketch.TextBoxes
			If oTB.Text = "<MyPrompt>" Then
				Call oSS.SetPromptResultText(oTB, newValue)
			End If
		Next
	End If

Next