Inventor 2025 -Extracting parameters from Field Text drawing to Custom - iProperties

Inventor 2025 -Extracting parameters from Field Text drawing to Custom - iProperties

elena_dragomirDX7D9
Explorer Explorer
170 Views
5 Replies
Message 1 of 6

Inventor 2025 -Extracting parameters from Field Text drawing to Custom - iProperties

elena_dragomirDX7D9
Explorer
Explorer

Hi,

I need your help to write something in ILogic that extracts the drawing parameters Field Text to Custom - IProperties.
I don't know if it's possible, but if it is, thank you in advance.


 

 
 
0 Likes
Accepted solutions (2)
171 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @elena_dragomirDX7D9.  Thanks for including the edited pictures for more information to go by this time.  There are multiple types of things in drawings that can have what you are calling 'field text', such as Borders, TitleBlocks, SketchedSymbols, and other stuff.  We would also normally need to know the 'prompts' for each field you are looking for, because they can be pretty difficult to find otherwise, since we literally have to search through individual TextBox objects within the definition sketch of something to find them.  But in this case, since you just want them all, and do not seem to care what order they are processed in, it is not as much of a challenge.  I have developed multiple code processes specifically for identifying and interacting which what are known as 'Prompted Entries' from those types of drawing entities.  Below is an example of some code you can copy & paste into an empty iLogic rule, and run it while one of those types of drawings is the 'active' document in Inventor.  It will first make sure the current document is a drawing, then get that...but if it is a part or assembly, it will not do anything.  Next it tries to get the TitleBlock from the 'active' Sheet in the drawing.  If there is not one, which is possible, then it will not do anything.  Next, it looks within the definition sketch of that TitleBlock and gets its collection of TextBoxes, then starts iterating through them, looking for specific formatting which indicates they are for a 'Prompted Entry', not any thing else.  When it finds one, it gets both its 'Prompt' text, and the value of that prompt, if any, and writes those into Dictionary entries (collection of two factor pairs of data).  If something was found & returned from that process, another process then attempts to either update, or create custom iProperties, with the prompt text as the name of the Property, and the prompt value as the Property's value.  I did not include any 'comments' or 'feedback' in the code for now, but could if needed.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oTBlock As Inventor.TitleBlock = oSheet.TitleBlock
	If oTBlock Is Nothing Then Return
	Dim oPromptedEntriesDict As Dictionary(Of String, String) = GetPromptedEntries(oTBlock)
	DictionaryToCustomProperties(oDDoc, oPromptedEntriesDict)
End Sub

'works for Borders, TitleBlocks, & SketchedSymbols 
Function GetPromptedEntries(oObj As Object) As Dictionary(Of String, String)
	If oObj Is Nothing Then Return Nothing
	Dim oTBoxes As Inventor.TextBoxes = Nothing
	Try : oTBoxes = oObj.Definition.Sketch.TextBoxes : Catch : End Try
	If (oTBoxes Is Nothing) OrElse (oTBoxes.Count = 0) Then Return Nothing
	Dim oDict As Dictionary(Of String, String) = New Dictionary(Of String, String)
	For i As Integer = 1 To oTBoxes.Count
		Dim oTBox As Inventor.TextBox = oTBoxes.Item(i)
		If oTBox.FormattedText.Contains("</Prompt>") Then
			Dim sPrompt As String = oTBox.Text.Trim("<", ">")
			Dim sPromptResult As String = oObj.GetResultText(oTBox)
			If Not oDict.ContainsKey(sPrompt) Then oDict.Add(sPrompt, sPromptResult)
			'Logger.Info(vbCrLf & "Prompt = " & sPrompt & vbCrLf & "Value = " & sPromptResult & vbCrLf)
		End If
	Next 'oTBox
	Return oDict
End Function

Sub DictionaryToCustomProperties(doc As Inventor.Document, _
	dict As Dictionary(Of String, String))
	
	If (dict Is Nothing) OrElse (dict.Count = 0) Then Return
	Dim oCProps As Inventor.PropertySet = doc.PropertySets.Item(4)
	For Each oEntry As KeyValuePair(Of String, String) In dict
		Dim oCProp As Inventor.Property = Nothing
		Try : oCProp = oCProps.Item(oEntry.Key) : Catch : End Try
		If oCProp IsNot Nothing Then
			Try : oCProp.Value = oEntry.Value : Catch : End Try
			Continue For
		End If
		Try : oCProp = oCProps.Add(oEntry.Value, oEntry.Key) : Catch : End Try
	Next 'oEntry
End Sub

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 3 of 6

elena_dragomirDX7D9
Explorer
Explorer

Thank you very very much!!! It worked! 🙂 

0 Likes
Message 4 of 6

elena_dragomirDX7D9
Explorer
Explorer

Please could you add to this rule, so that it runs every time you save the drawing?
Thank you!

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @elena_dragomirDX7D9.  That is not something that can be added to this rule itself.  But fortunately, that is definitely possible to make happen another way.  In Inventor, while you have that drawing open on your screen for editing, go to Inventor's Manage tab, and click on its 'Event Triggers' button within the iLogic panel.  If your iLogic ribbon panel is not visible, then you might have to right-click somewhere in the ribbon, hover over the 'Show Panels', slice over and click on the 'iLogic' one.  In that Event Triggers dialog, click on the 'This Document' tab to make that the active one.  On the left side of this dialog, you should be able to find your iLogic rule listed somewhere.  Drag and drop that rule just under the 'Before Save Document' event name in the list on the right.  That will cause this rule to:...when you click save, it will run that rule just before it actually saves.  If you put it under the 'after save', then it would have already saved the document, then ran your rule on it afterwards, which is almost always not what folks really want to do.  Next, click the [OK] button on that dialog, and save that drawing file again.  The settings you set on the 'This Document' tab in that dialog, are saved in that Inventor document/file...but the settings on the other tabs of that dialog, which effect all documents of certain types, are stored in an external XML file, instead of within the individual Inventor files.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

elena_dragomirDX7D9
Explorer
Explorer

You are so intelligent! Not only do you know what to do, but the way you explain things is impressive too!

Thank you very much!!!

0 Likes