Creating a View Label with Custom Properties

Creating a View Label with Custom Properties

dbrown3J3B6E
Participant Participant
2,584 Views
7 Replies
Message 1 of 8

Creating a View Label with Custom Properties

dbrown3J3B6E
Participant
Participant

I was able to get a code from another forum post and modified it to my needs to include our custom properties. I'm now having two issues I can't find the answer to. I'm attaching the code I'm using as well as the .ipt and .idw files.

 

1. I'm trying to make it so that the label automatically shows up correctly when a view is created. I saved the iLogic rule in the template file and also opened the "Event Triggers" and applied this rule to all of them. It seems to run the rule when I do a save, but ideally I would like it to populate when the view is created. I thought applying the rule to "Drawing View Change" would do this, but it doesn't.

 

2. I want to have two different view labels, one for .ipt files and one for .iam files. How can I modify this code to do that?

'start of ilogic code
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document
oModel = ThisDoc.ModelDocument

Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
	For Each oView In oViews
	oView.ShowLabel = True
		Try
		'get the property ID for these custom iProperties from the model referenced by the view
		o_iPropID_1 = oModel.PropertySets.Item("User Defined Properties").Item("FCE_PartNumber").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("DESCRIPTION_AP").PropId
		o_iPropID_3 = oModel.PropertySets.Item("User Defined Properties").Item("MATERIAL_A").PropId
		o_iPropID_4 = oModel.PropertySets.Item("User Defined Properties").Item("STANDARD_A").PropId
		Catch
		'here you could add a message that one or more of the custom iProperties were not found
		End Try
		
		Try
		'format the custom iproperty string and add the property ID
		oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>FCE_PartNumber</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='DESCRIPTION_AP' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2 & "'>DESCRIPTION_AP</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString3 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='MATERIAL_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_3 & "'>MATERIAL_A</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString4 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='STANDARD_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_4 & "'>STANDARD_A</Property><Br/>"
		oStringScale = "<StyleOverride FontSize='0.3'>SCALE <DrawingViewScale/></StyleOverride>"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = oString1 &  oString2 &  oString3 &  oString4 & oStringScale
		Catch
		'do nothing if error
		End Try
	Next
Next
'end of ilogic code

 

0 Likes
Accepted solutions (1)
2,585 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor
Accepted solution

for point 1 you need to use events.

You can do that easily with an add-in.

for point 2:

'start of ilogic code
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document
oModel = ThisDoc.ModelDocument

Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
	For Each oView In oViews
		oView.ShowLabel = True
		If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Try
		'get the property ID for these custom iProperties from the model referenced by the view
		o_iPropID_1 = oModel.PropertySets.Item("User Defined Properties").Item("FCE_PartNumber").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("DESCRIPTION_AP").PropId
		o_iPropID_3 = oModel.PropertySets.Item("User Defined Properties").Item("MATERIAL_A").PropId
		o_iPropID_4 = oModel.PropertySets.Item("User Defined Properties").Item("STANDARD_A").PropId
		Catch
		'here you could add a message that one or more of the custom iProperties were not found
		End Try
		
		Try
		'format the custom iproperty string and add the property ID
		oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>FCE_PartNumber</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='DESCRIPTION_AP' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2 & "'>DESCRIPTION_AP</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString3 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='MATERIAL_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_3 & "'>MATERIAL_A</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString4 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='STANDARD_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_4 & "'>STANDARD_A</Property><Br/>"
		oStringScale = "<StyleOverride FontSize='0.3'>SCALE <DrawingViewScale/></StyleOverride>"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = oString1 &  oString2 &  oString3 &  oString4 & oStringScale
		Catch
		'do nothing if error
		End Try	
		End If
	
		If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject
		Try
		'get the property ID for these custom iProperties from the model referenced by the view
		o_iPropID_1 = oModel.PropertySets.Item("User Defined Properties").Item("FCE_PartNumber").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("DESCRIPTION_AP").PropId
		o_iPropID_3 = oModel.PropertySets.Item("User Defined Properties").Item("MATERIAL_A").PropId
		o_iPropID_4 = oModel.PropertySets.Item("User Defined Properties").Item("STANDARD_A").PropId
		Catch
		'here you could add a message that one or more of the custom iProperties were not found
		End Try
		
		Try
		'format the custom iproperty string and add the property ID
		oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>FCE_PartNumber</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='DESCRIPTION_AP' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2 & "'>DESCRIPTION_AP</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString3 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='MATERIAL_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_3 & "'>MATERIAL_A</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString4 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='STANDARD_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_4 & "'>STANDARD_A</Property><Br/>"
		oStringScale = "<StyleOverride FontSize='0.3'>SCALE <DrawingViewScale/></StyleOverride>"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = oString1 &  oString2 &  oString3 &  oString4 & oStringScale
		Catch
		'do nothing if error
		End Try	
		End If
	Next
Next

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 8

dbrown3J3B6E
Participant
Participant

Thanks so much for the revised code! As for the event trigger, I can't get it to work on view creation. The only related option I see is "Drawing View Change" and I had already applied that trigger before and it didn't work.

 

dbrown3J3B6E_0-1620042469371.png

 

0 Likes
Message 4 of 8

bradeneuropeArthur
Mentor
Mentor

Why not using "on Save event" ?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 5 of 8

dbrown3J3B6E
Participant
Participant

It works when I save the document, I was just saying it would be nice if it populated on view creation instead.

0 Likes
Message 6 of 8

bradeneuropeArthur
Mentor
Mentor

There is no "On View Create Event" 

bradeneuropeArthur_0-1620047950583.png

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 7 of 8

floccipier
Advocate
Advocate
oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
& "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
& o_iPropID_1 & "'>FCE_PartNumber</Property><Br/>

used this code and it works great. Just wondering if you could add bit notes that what part does what in live above. where do you get the FormatID, so if I am trying to use one of default property in label how do I do that. Not trying to get you do more code as what you have provided in post above is fantastic, just trying to understand so that I could modify it to use my need. Thanks in advance.
0 Likes
Message 8 of 8

mgrenier1
Collaborator
Collaborator

I'm trying to get something similar to work but I keep getting an error message (0x80070057 (E_INVALIDARG))

Here's what I have so far : 

Sub Main()

    '=========================
    ' Fonction XML Safe (affichage seulement!)
    '=========================
    Dim XmlSafe As Func(Of String, String) =
        Function(text As String)
            If text Is Nothing Then Return ""
            Return System.Security.SecurityElement.Escape(text)
        End Function

    '=========================
    ' Sélection vue
    '=========================
    Dim oView As DrawingView

    Try
        oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Sélectionne une vue")
    Catch
        MessageBox.Show("Aucune vue sélectionnée.")
        Return
    End Try

    If oView Is Nothing Then Return

    Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
    If oModel Is Nothing Then Return

    '=========================
    ' PropertySet (robuste multilangue)
    '=========================
    Dim oProps As PropertySet = Nothing

    For Each ps As PropertySet In oModel.PropertySets
        If ps.Name.ToLower.Contains("user") Or ps.Name.ToLower.Contains("utilisateur") Then
            oProps = ps
            Exit For
        End If
    Next

    If oProps Is Nothing Then
        MessageBox.Show("Aucune propriété utilisateur trouvée.")
        Return
    End If

    '=========================
    ' Liste triée
    '=========================
    Dim propNames As New List(Of String)

    For Each p In oProps
        propNames.Add(p.Name)
    Next

    propNames.Sort()

    '=========================
    ' FORMULAIRE
    '=========================
    Dim form As New System.Windows.Forms.Form
    form.Text = "Label Builder - Preview Live"
    form.Width = 520
    form.Height = 600

    Dim checklist As New System.Windows.Forms.CheckedListBox
    checklist.Dock = System.Windows.Forms.DockStyle.Left
    checklist.Width = 220

    For Each name In propNames
        checklist.Items.Add(name)
    Next

    Dim previewBox As New System.Windows.Forms.TextBox
    previewBox.Multiline = True
    previewBox.Dock = System.Windows.Forms.DockStyle.Fill
    previewBox.ReadOnly = True
    previewBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical

    Dim tolButton As New System.Windows.Forms.Button
    tolButton.Text = "Tolérance"
    tolButton.Dock = System.Windows.Forms.DockStyle.Top

    Dim applyButton As New System.Windows.Forms.Button
    applyButton.Text = "Appliquer"
    applyButton.Dock = System.Windows.Forms.DockStyle.Bottom

    form.Controls.Add(previewBox)
    form.Controls.Add(checklist)
    form.Controls.Add(tolButton)
    form.Controls.Add(applyButton)

    Dim tolValue As String = ""

    '=========================
    ' Preview lisible (SAFE)
    '=========================
    Dim UpdatePreview As Action =
        Sub()

            Dim txt As String = ""

            For Each item In checklist.CheckedItems

                Dim propName As String = item.ToString()

                Dim line As String = propName

                If propName.ToUpper.Contains("THICKNESS") And tolValue <> "" Then
                    line &= " (±" & tolValue & " po)"
                End If

                txt &= line & vbCrLf

            Next

            txt &= vbCrLf & "Échelle : (preview)"

            previewBox.Text = txt

        End Sub

    '=========================
    ' EVENTS
    '=========================
    AddHandler checklist.ItemCheck,
        Sub()
            form.BeginInvoke(UpdatePreview)
        End Sub

    AddHandler tolButton.Click,
        Sub()
            Dim val = InputBox("Entrer tolérance", "Tolérance", tolValue)
            If val <> "" Then tolValue = val
            UpdatePreview()
        End Sub

    AddHandler applyButton.Click,
        Sub()

            Dim finalText As String = ""

            For Each item In checklist.CheckedItems

                Dim propName As String = item.ToString()

                ' ✅ IMPORTANT : seul affichage est encodé
                Dim safeDisplay As String = XmlSafe(propName)

                Dim line As String =
                    "<Property Document='model' PropertySet='" & oProps.Name & "' Property='" & propName & "'>" &
                    safeDisplay &
                    "</Property>"

                If propName.ToUpper.Contains("THICKNESS") And tolValue <> "" Then
                    line &= " (+" & tolValue & "/-" & tolValue & " po)"
                End If

                finalText &= line & "<Br/>"

            Next

            If finalText = "" Then
                MessageBox.Show("Aucune sélection.")
                Return
            End If

            ' nettoyer dernier BR
            If finalText.EndsWith("<Br/>") Then
                finalText = finalText.Substring(0, finalText.Length - 5)
            End If

            ' ajout échelle correcte
            finalText &= "<Br/><StyleOverride FontSize='0.3'>Échelle : <DrawingViewScale/></StyleOverride>"

            ' 🔍 DEBUG (optionnel)
            ' MessageBox.Show(finalText)

            Try
                oView.ShowLabel = True
                oView.Label.FormattedText = finalText
            Catch ex As Exception
                MessageBox.Show("Erreur Inventor :" & vbCrLf & ex.Message)
            End Try

            form.Close()

        End Sub

    UpdatePreview()
    form.ShowDialog()

End Sub
0 Likes