Link part's view label to drawing sheet's Parts List Properties Qty

Link part's view label to drawing sheet's Parts List Properties Qty

MikeOG
Contributor Contributor
667 Views
19 Replies
Message 1 of 20

Link part's view label to drawing sheet's Parts List Properties Qty

MikeOG
Contributor
Contributor

Hi guys, im after some code, can someone please help? Im trying to create a rule that will rename each individual part view label on a drawing. I first place a View of my assembly on the sheet, then a parts list for this assembly. I then place all the profiles on the sheet. I want a snippet to rename each part's view label to have the following iProperties:

<PART NUMBER> - <DESCRIPTION>
MATERIAL: <MATERIAL>
<STOCK NUMBER>
QTY: <QTY> REQ'D
SCALE (<SCALE>) DWG (1: 1)

The <QTY> must come from: Type -> Parts List Properties, Source -> First view place (the assembly view), Select Parts list Item -> The current view label's part number, Property -> Qty

 

Thanks in advance!

 

MikeOG_0-1746652900738.png

MikeOG_1-1746652915623.png

MikeOG_2-1746652942553.png

MikeOG_3-1746652962027.png

MikeOG_4-1746652975676.png

 

0 Likes
Accepted solutions (1)
668 Views
19 Replies
Replies (19)
Message 2 of 20

StuOG
Contributor
Contributor

Upvoted & following.

Message 3 of 20

Terry_N
Contributor
Contributor
Accepted solution

Great idea, It would be helpful if you could set a parts list property in the styles for view labels but you can't so I have a away to do it.

First is a rule I use to copy and paste formatting of view labels. As part of that it copies the formatting to your clipboard. You will need you set up the view label as you want it then run the copy rule to get your formatted text. Then set up the following rule to rename all the view labels. You will have to replace the number in DrawinBOMRowIndex='1' with & rowIndex &

Word of warning, it relies on one parts list in the drawing and I haven't tested on parts with modelstates so not sure how reliable it will be. Also If you have a structured BOM all levels expanded parts list it will likely give the wrong number soo I would stick to a parts only parts list when using this.

View label copy paste rule (this will copy a view label from one view and paste to any you select but if the view label has a quantity from a partslist in it will paste that property that into each view and the quantities will be wrong. Hit esc to end pasting.)

Imports System.Windows.Forms


Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view to copy label format from")


If oView IsNot Nothing Then
    'turn view label visibility on
    oView.ShowLabel = True
    'capture the current view label
    ViewLabel = oView.Label
    'get label as string
    sLabel = oView.Label.FormattedText
	sLabelhjus = oView.Label.HorizontalJustification
	sLabelVjus = oView.Label.VerticalJustification

Clipboard.SetText(sLabel)

here:

Dim oView2 As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view to paste label format to, hit ESC to exit")


If oView2 IsNot Nothing Then
	
	View2Label = oView2.Label
	View2Label.FormattedText = sLabel
	View2Label.HorizontalJustification = sLabelhjus
	View2Label.VerticalJustification = sLabelVjus
	GoTo here
End If


Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If


renaming rule

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,
'REPLACE THIS WITH YOUR FORAMTTED TEXT
            Dim sLabel As String = "<StyleOverride FontSize='0.35'>P/N: </StyleOverride>" & _
                                  "<StyleOverride FontSize='0.35'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>" & _
                                  "<Br/><StyleOverride FontSize='0.25'>DES: </StyleOverride>" & _
                                  "<StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride>" & _
                                  "<Br/><StyleOverride FontSize='0.25'>MATERIAL:  </StyleOverride>" & _
                                  "<StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Material' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='20'>MATERIAL</Property></StyleOverride>" & _
                                  "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>" & _
                                  "<Br/><StyleOverride FontSize='0.25'>QTY:  </StyleOverride>" & _
                                  "<StyleOverride FontSize='0.25'><PartsListProperty DrawingBOMIndex='1' DrawingBOMRowIndex='" & rowIndex & "' PartsListPropertyType='45578' /></StyleOverride>" & _
                                  "<StyleOverride FontSize='0.25'>  REQ&apos;D </StyleOverride>" & _
                                  "<Br/><StyleOverride FontSize='0.25'>SCALE (</StyleOverride>" & _
                                  "<StyleOverride FontSize='0.25'><DrawingViewScale/></StyleOverride>" & _
                                  "<StyleOverride FontSize='0.25'> @ A3) DXF (1: 1)</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 unsuccessfully", "iLogic")
End Sub

 

0 Likes
Message 4 of 20

MikeOG
Contributor
Contributor

@Terry_N - Thanks for your input! We use multiple parts lists per drawing document, so would need a rule that would target the the parts list on the current sheet. Do you think that is possible?

0 Likes
Message 5 of 20

Terry_N
Contributor
Contributor
Hi Mike,

This rule is run on the current active sheet. I just tested it on a multisheet drawings and it only ran on the active sheet. If you have more than one partslist on the active sheet it will use the first one it finds to compare against the views.
0 Likes
Message 6 of 20

Jordan_Kuzma
Contributor
Contributor

@Terry_N 
came here looking for this same code except I am only using the code to populate each part view with the Parts List Property for "ITEM" 
so, the view label would look like this: ITEM[A]
I cannot figure out how to manipulate the code to achieve this. (I am not a programmer, just a designer trying to speed up large assembly drawings) Thanks in advance!

0 Likes
Message 7 of 20

Terry_N
Contributor
Contributor

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.

0 Likes
Message 8 of 20

vishnuteja_srikanti
Participant
Participant

i am getting the formated text in place of qty even when i run this code am i missing something here 

 

vishnuteja_srikanti_0-1748414251079.png

vishnuteja_srikanti_1-1748414271826.png

 

 

0 Likes
Message 9 of 20

Terry_N
Contributor
Contributor

Hi @vishnuteja_srikanti 

 

That happens when there is something in the formatted text that is spelt wrong or outside of the functions of formatted text. Without seeing your edited version I think it might be the part where the row number goes. Yours is coming out DrawingBOMColumnIndex='4'. I think that should be changed to DrawingBOMRowIndex=

 

Let me know how you get on 

0 Likes
Message 10 of 20

vishnuteja_srikanti
Participant
Participant

i have changed it to rowindex and tried still it is same 

 

vishnuteja_srikanti_0-1748421560623.png

 

Dim sLabel As String = "<StyleOverride FontSize='0.25'>QTY:</StyleOverride><StyleOverride FontSize='0.25'><PartsListProperty DrawingBOMIndex='1' DrawingBOMRowIndex='2' PartsListPropertyType='45572' /></StyleOverride>"

 

this what i am using 

 

 

0 Likes
Message 11 of 20

Jordan_Kuzma
Contributor
Contributor

I appreciate all of your help! This is going to be such a time saver.
A few things, so if I am understanding correctly, I am to set up the first view the way that I want it, and then run the copy properties rule to set the same format for all views and then run the rename rule so that it changes the item number? I am not able to get all of my views to rename to the right letter, some work and others don't, the views were placed in order 

0 Likes
Message 12 of 20

Terry_N
Contributor
Contributor

Hi, 

This is showing the correct label for me to have it  QTY: <QTY from parts list>

            Dim sLabel As String = "<StyleOverride FontSize='0.25'>QTY:</StyleOverride><StyleOverride FontSize='0.25'><PartsListProperty DrawingBOMIndex='1' DrawingBOMRowIndex='" & rowIndex & "' PartsListPropertyType='45575' /></StyleOverride>"
            

Just want to check are you running INV 2025? It won't work with older versions. I have 2025.3 

0 Likes
Message 13 of 20

Terry_N
Contributor
Contributor

Yeah you only need to us that first rule that copies the properties in order to get the formatted text. Once you have the rule set up to change all the views to how you want then on you next drawings you should be able to place your views then just run the rule to rewrite them all to your standard way linking them to the parts list item numbers.

I'm not sure why it would only do some of them tho. What is your process to allocate the letters? Are you over writing the generated item number with a letter?

0 Likes
Message 14 of 20

Jordan_Kuzma
Contributor
Contributor

yes, for our BOM's we use letters instead of numbers, so in the parts list on the DWG I reassign the numbers to letters and then click the button to keep them letters so it is no longer highlighted blue

I was using another code to generate all individual part views for an assembly in the order they are in the parts list. and the first few letters with the rename code were correct and then they just are all over, nothing is consistent, they aren't in any order either. I am wondering if they are generating with the code in the order they first appear when you place a BOM on a drawing when labeled 1,2,3...ect but I put them in the order I want them in when I Letter them and then sort the parts list by Ascending Item A,B,C...ect. I didn't have the opportunity to mess around with it too much today as I needed to get the drawing done for work and just had to do it by hand like always lol. I may need to start the process over with a clean build on the next project and possibly try some other ways. I will do some more trialing tomorrow when I am back in the office. Appreciate you helping me out!

0 Likes
Message 15 of 20

Terry_N
Contributor
Contributor

It might be getting mixed up from using the item number for that. You can have a different item number between parts only and structured BOMs and then if the part is in two different assemblies you would have a different item number there to. So you would have to be using the top level assembly for the parts list to have consistent item numbers. I use the part number as the identifier on parts and don't really use the item numbers at all because the part number will stay the same.

0 Likes
Message 16 of 20

vishnuteja_srikanti
Participant
Participant

oh ok i am using 2022 version may this could be the issue.

 

so you mean in 2025 version we have listed type of partlist properties am i right 

 

0 Likes
Message 17 of 20

Terry_N
Contributor
Contributor

Yeah I think it was 2025 that it came in. I can't find a link to it at the moment but it gives you this in the view label or just a text box. you have to manually pick which part you want to link it to

tnicholls_0-1748491669730.png

 

0 Likes
Message 18 of 20

MikeOG
Contributor
Contributor

MikeOG_0-1748491896039.png

MikeOG_1-1748491961943.png

 



@Terry_N here you go.. Yes this function was only introduced in 2025

 

Message 19 of 20

Terry_N
Contributor
Contributor

Hi, @MikeOG @vishnuteja_srikanti @Jordan_Kuzma @StuOG 

 

We have a problem with this. If the parts list it's getting the row number from is sorted by anything other than part number it when it applies the view label it will tick the box for the wrong part to apply qty for. So you need to have a parts only parts list sorted by part number for it to reference for it to work which isn't ideal if you want to use a structured list and only have the number that part that are added at that assembly level. structured parts list seem to sometimes be sorted differently (possibly by item number).

so If anyone at autodesk could weigh in and let us know if there is a way to access the parts list properties other than what I have come up with that would be great.

 

Like instead of getting the row number from the partslist and applying that number to the "DrawingBOMRowIndex=' in the formated text you could do something to find the DrawingBOMRowIndex number relating to the refernced part in the parts list and using that in the formated text. I can't find a way to do that with ilogic.

0 Likes
Message 20 of 20

Jordan_Kuzma
Contributor
Contributor

I found that placing the parts list on the sheet, then generating the views, renaming them with your iLogic code, THEN relabeling them with letters is how it works for me. They all update without issues and I can place them in the order I want with the letters and can still sort them in the BOM without it affecting the label. 🙂

0 Likes