Hi Jordan
That's all good, I didn't know any code before I started using Inventor either. I had a look and it will work. The formatted text for a view label that says "ITEM: <Item Number>" looks like this.
<StyleOverride FontSize='0.25'>ITEM: </StyleOverride><StyleOverride FontSize='0.25'><PartsListProperty DrawingBOMIndex='1' DrawingBOMRowIndex='2' PartsListPropertyType='45572' /></StyleOverride>
If you need to change the font size you can change the 0.25, need to change the DrawingBOMRowIndex='2' to pick up the variable that our code pulls from the parts list and becomes DrawingBOMRowIndex='"& rowIndex &" This is the part that defines the parts list row number. Then PartsListPropertyType='45572' means it's pulling the item number property. It was 45575 for the QTY property.
So this is what it looks like in the code to rename all the views with "ITEM: <Item Number>"
Sub Main()
' Get the active drawing document
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
If oDrawDoc Is Nothing Then
MessageBox.Show("This rule must be run from a drawing document", "iLogic")
Return
End If
' Get all drawing views in the document
Dim oViews As DrawingViews = oDrawDoc.ActiveSheet.DrawingViews
' Process each view
For Each oView As DrawingView In oViews
Try
' Skip views that don't have associated models
If oView.ReferencedDocumentDescriptor Is Nothing Then Continue For
' Turn view label visibility on
oView.ShowLabel = True
' Get the parts list for the sheet
Dim oPartsLists As PartsLists = oDrawDoc.ActiveSheet.PartsLists
If oPartsLists.Count = 0 Then Continue For
' Get the first parts list (assuming there's only one)
Dim oPartsList As PartsList = oPartsLists(1)
' Find the row in the parts list that corresponds to this view's model
Dim rowIndex As Integer = 0
i = 0
For Each row As PartsListRow In oPartsList.PartsListRows
i = i +1
For Each dbRow As DrawingBOMRow In Row.ReferencedRows
Dim bomRow As BOMRow = dbRow.BOMRow
For Each compDef As ComponentDefinition In bomRow.ComponentDefinitions
Dim refDoc As Document = TryCast(compDef.Document, Document)
If refDoc.FullDocumentName = oView.ReferencedDocumentDescriptor.FullDocumentName Then
rowIndex = i
Exit For
End If' do something with the document
Next
Next
Next
If rowIndex = 0 Then Continue For ' No matching part found
' Create the formatted text string with the correct row index
Dim sLabel As String = "<StyleOverride FontSize='0.25'>ITEM: </StyleOverride><StyleOverride FontSize='0.25'><PartsListProperty DrawingBOMIndex='1' DrawingBOMRowIndex='"& rowIndex &"' PartsListPropertyType='45572' /></StyleOverride>"
' Get the current label's justification settings
Dim sLabelhjus As HorizontalTextAlignmentEnum = oView.Label.HorizontalJustification
Dim sLabelVjus As VerticalTextAlignmentEnum = oView.Label.VerticalJustification
' Apply the new label
Dim ViewLabel As DrawingViewLabel = oView.Label
ViewLabel.FormattedText = sLabel
ViewLabel.HorizontalJustification = sLabelhjus
ViewLabel.VerticalJustification = sLabelVjus
Catch ex As Exception
' Log any errors but continue with other views
Logger.Error("Error processing view: " & ex.Message)
End Try
Next
MessageBox.Show("View labels updated successfully", "iLogic")
End Sub
If you want to add anything else into the view label like scale or something I would say set it up how you want it to look then use the view label copy paste rule I posted first to copy the formatted text to your clip board then you can paste it into your rule at line 54 where is says Dim sLabel As String = <then formated text> and make sure to swap out the part that defines the row with the " & rowIndex & " Then you should be good to go. When I tested it my parts list wasn't showing the item numbers column but it still worked so you should be able to pull any of the properties from that list it gives you when you insert them manually.