Here's another method I sometimes use when I need to insert iProperty references (not just static text values) into a FormattedText String. I first get the target PropertySet object(s) and the Property object(s). Then as I'm assembling the needed sub-string for the iProperty reference, I insert the 'PropertySet.InternalName' in place of the FormatID value, and insert the 'Property.PropId' in place of the PropertyID value. Pay close attention, because the 'value' is enclosed by one apostrophe (') on each side...one right after the = sign, and one right after the value. You will also notice that the end of my string ends with a space, then "/>". That last couple of characters will be automatically replaced with , for example ">PART NUMBER</Property>" by Inventor, because it already know what you want. You can confirm by un-commenting the two InputBox lines temporarily, as a test.
Here's the code:
'to select the drawing view after you run the rule
'Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter,"Select a drawing view.")
Dim oSSet As SelectSet = ThisDrawing.Document.SelectSet
If oSSet.Count = 0 Then
MsgBox("You need to pre-select a drawing view before running this rule. Exiting.", , "")
Exit Sub
End If
oView = oSSet.Item(1)
If oView Is Nothing Then Exit Sub
'get the view's model document
Dim oMDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
'Part Number preparations - get the property set object, get property object
Dim oDTProps As Inventor.PropertySet = oMDoc.PropertySets.Item("Design Tracking Properties")
Dim oPNProp As Inventor.Property = oDTProps.Item("Part Number")
'use above objects to fill-in the FormattedText line for Part Number iProperty reference
Dim oPN As String = "<Property Document='model' FormatID='" & oDTProps.InternalName & "' PropertyID='" & oPNProp.PropId & "' />"
'custom properties preparations - get property set object, and property objects
Dim oCProps As Inventor.PropertySet = oMDoc.PropertySets.Item("Inventor User Defined Properties")
Dim oMbrProp As Inventor.Property = oCProps.Item("Member")
Dim oTtlQtyProp As Inventor.Property = oCProps.Item("TotalQty")
'use those objects to fill-in the FormattedText line for those iProperty references
Dim oMbr As String = "<Property Document='model' FormatID='" & oCProps.InternalName & "' PropertyID='" & oMbrProp.PropId & "' />"
Dim oTtlQty As String = "<Property Document='model' FormatID='" & oCProps.InternalName & "' PropertyID='" & oTtlQtyProp.PropId & "' />"
'to preview the (selectable) FormattedText 'Before' you change it.
'a = InputBox("","Before Changes:", oView.Label.FormattedText)
'assemble them using <Br/> to go to the next line
oView.Label.FormattedText = oPN & "<Br/>" & oMbr & "<Br/>" & oTtlQty
'to preview the (selectable) FormattedText 'After' you change it.
'b = InputBox("","After Changes:", oView.Label.FormattedText)
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)