Reading "Prompted Strings" from a Sketched Symbol

Reading "Prompted Strings" from a Sketched Symbol

cdepaoloAFYZ3
Explorer Explorer
578 Views
4 Replies
Message 1 of 5

Reading "Prompted Strings" from a Sketched Symbol

cdepaoloAFYZ3
Explorer
Explorer

I am looking for a method to use an iLogic script to read out the value of a prompted string.

 

I am using this logic to answer all of the prompted strings in a sketched symbol.

Dim oPromptStrings As String() = {sPromptStrings(0),sPromptStrings(1),sPromptStrings(2),sPromptStrings(3),sPromptStrings(4),sPromptStrings(5),sPromptStrings(6)}
Dim oSketchedSymbol As SketchedSymbol _
       = oSheet.SketchedSymbols.Add( _
             oSketchedSymbolDef, _
             oInsertionPoint, _
             0, 1, oPromptStrings)

In another ilogic rule I want to update some of these values but not all of them. Is there a way to read the oPrompedStrings into an array?
0 Likes
579 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

Hi @cdepaoloAFYZ3 

From this example once you supply the symbol definition object you can use these lines.

Dim i 
    For i = 1 To symbol.Definition.Sketch.TextBoxes.Count
          oEachText = symbol.Definition.Sketch.TextBoxes(i)
        If (oEachText.Text = "MY_PROMPT") Then
            ' found the prompt text we want to copy
              oPromptText = oEachText
            Exit For
        End If
    Next i
    
    'get the result string of the prompt text
    Dim oPromptEntry  
    oPromptEntry = oTB1.GetResultText(oPromptText)

 

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

WCrihfield
Mentor
Mentor

Hi guys.  Just posting another similar code solution I came up with for getting/reading PromtedEntries from something like a TitleBlock or SketchedSymbol.  It contains a custom Function that you can supply the TitleBlock or SketchedSymbol to, and if it contains any PromtedEntries then it will should return a Dictionary(Of String, String) type value.  A Dictionary is a type of collection which can contain entries which each hold a 'Key' and a 'Value', similar to the Inventor.NameValueMap type object.  Perfect for returning both the 'Prompt' text, and the current value of each prompt.  Then it shows you how to iterate the entries in that Dictionary, and how to get Array type objects from the Dictionary.  It is currently set-up to write the Prompt & Value pairs out to the iLogic Log window, and also show you the Array of Prompt strings, and the Array of Values in simple dialogs, just to confirm their functionality.

Sub Main
	'allow user to manually select a SketchedSymbol that has been placed on a sheet somewhere
	Dim oSS As SketchedSymbol = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingSketchedSymbolFilter, "Select a SketchedSymbol.")
	If oSS Is Nothing Then Return
	'run our custom Function to extract Prompts & Prompt Values from it as a Dictionary
	Dim oDict As Dictionary(Of String, String) = GetPromptedEntries(oSS)
	If oDict Is Nothing OrElse oDict.Count = 0 Then Return
	'just showing how to iterate the Dictionary entries, and 'Log' the results to the iLogic Log window
	For Each oEntry As KeyValuePair(Of String, String) In oDict
		Logger.Info(vbCrLf & "Prompt = " & oEntry.Key & vbCrLf & "Value = " & oEntry.Value & vbCrLf)
	Next 'oEntry
	'just an example of how to get an Array from the Dictionary
	Dim sPrompts() As String = oDict.Keys.ToArray
	'and just showing the resulting list in a simple dialog
	a = InputListBox("", sPrompts, "", "Prompts")
	Dim sValues() As String = oDict.Values.ToArray
	b = InputListBox("", sValues, "", "Values")
End Sub

Function GetPromptedEntries(oObj As Object) As Dictionary(Of String, String)
	If oObj Is Nothing Then Return Nothing
	Dim oTBs As Inventor.TextBoxes = Nothing
	Try : oTBs = oObj.Definition.Sketch.TextBoxes : Catch : End Try
	If oTBs Is Nothing OrElse oTBs.Count = 0 Then Return Nothing
	Dim oDict As New Dictionary(Of String, String)
	For Each oTB As Inventor.TextBox In oTBs
		If oTB.FormattedText.Contains("</Prompt>") Then
			Dim sPrompt As String = oTB.Text.Replace("<", "").Replace(">", "")
			Dim sPromptResult As String = oObj.GetResultText(oTB)
			If Not oDict.ContainsKey(sPrompt) Then oDict.Add(sPrompt, sPromptResult)
			'Logger.Info(vbCrLf & "Prompt = " & sPrompt & vbCrLf & "Value = " & sPromptResult & vbCrLf)
		End If
	Next 'oTB
	Return oDict
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

And here is essentially the same thing again, but using the Inventor.NameValueMap type object, instead of the Dictionary(Of String, String) type object for the collection.  One possible negative aspect of using the Dictionary(Of String, String) type collection would be if you had more than one PromtedEntry with the same 'Prompt' text, because a Dictionary type collection will not allow two 'Keys' to be the same.  (The 'Key' is the first element in each (Key, Value) entry.  The NameValueMap is very basic, so it does not have that limitation.

Sub Main
	'allow user to manually select a SketchedSymbol that has been placed on a sheet somewhere
	Dim oSS As SketchedSymbol = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingSketchedSymbolFilter, "Select a SketchedSymbol.")
	If oSS Is Nothing Then Return
	'run our custom Function to extract Prompts & Prompt Values from it as a Dictionary
	Dim oMap As Inventor.NameValueMap = GetPromptedEntries(oSS)
	If oMap Is Nothing OrElse oMap.Count = 0 Then Return
	'how to iterate the entries, 'Log' the results to the iLogic Log window, and get Arrays
	Dim sPrompts(oMap.Count - 1) As String
	Dim sValues(oMap.Count - 1) As String
	For i As Integer = 1 To oMap.Count
		Dim sPrompt As String = oMap.Name(i)
		Dim sValue As String = oMap.Value(sPrompt)
		sPrompts(i - 1) = sPrompt
		sValues(i - 1) = sValue
		Logger.Info(vbCrLf & "Prompt = " & sPrompt & vbCrLf & "Value = " & sValue & vbCrLf)
	Next 'oEntry
	a = InputListBox("", sPrompts, "", "Prompts")
	b = InputListBox("", sValues, "", "Values")
End Sub

Function GetPromptedEntries(oObj As Object) As Inventor.NameValueMap
	If oObj Is Nothing Then Return Nothing
	Dim oTBs As Inventor.TextBoxes = Nothing
	Try : oTBs = oObj.Definition.Sketch.TextBoxes : Catch : End Try
	If oTBs Is Nothing OrElse oTBs.Count = 0 Then Return Nothing
	Dim oMap As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	For Each oTB As Inventor.TextBox In oTBs
		If oTB.FormattedText.Contains("</Prompt>") Then
			Dim sPrompt As String = oTB.Text.Replace("<", "").Replace(">", "")
			Dim sPromptResult As String = oObj.GetResultText(oTB)
			oMap.Add(sPrompt, sPromptResult)
			'Logger.Info(vbCrLf & "Prompt = " & sPrompt & vbCrLf & "Value = " & sPromptResult & vbCrLf)
		End If
	Next 'oTB
	Return oMap
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

cdepaoloAFYZ3
Explorer
Explorer

Thank you both for these solutions.

0 Likes