Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor - Adding Item number from parts list to view label property

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
marcelnel
5373 Views, 18 Replies

Inventor - Adding Item number from parts list to view label property

I know this has been asked before but I can't find whether it was added to Inventor 2015 or not.

 

I work in the Structural and sheet metal industry and using inventor for a few years now to do concept/design and detailing on my projects.

 

My problem is that when I create a new drawing and it requires me to detail a specific part in an assembly I have to manually fill in the view label to match the Item number in my parts list. This is a lot of work and also is a recipe for human error.

 

Basically I cant assign the Item number in my parts list (BOM) as a property I can choose in a view label of a specific part I want to detail on a drawing.

 

If anyone uses the same method and knows of an easier solution to this fundemental inventor problem please share.

 

Kind regards,

GOS 

18 REPLIES 18
Message 2 of 19
Anonymous
in reply to: marcelnel

The 2 ways I have approached this

1. View reps of only that specific part, total PITA if you want to detail a lot of your parts. Plus Inventors habit of contaminating view reps if you create mirror parts or patterns after locking the view rep.

 

2. I have some I logic code I run on my very top assembly, it writes the Item and qty property to either custom properties of my choosing or to properties that already exist but I do not use. I put my top assembly into an idw sheet and create a BOM, I then organise the BOM the way I want and renumber. Then when the top assembly is saved the item and qty get written to the desired property of each part and is readily available even in another idw file.

Subassemblies can also have their own BOM, substitute your property of choice for item.

Message 3 of 19
mcgyvr
in reply to: marcelnel


@marcelnel wrote:

 

If anyone uses the same method and knows of an easier solution to this fundemental inventor problem please share.

 

Kind regards,

GOS 


How I would do it..

All my drawings simply pull the part number of the base view on each drawing into the title block.

So I would simply create a new sheet and place the base view of just the part I needed detailed. This would "automagically" put the part number into the title block.

And I'm done.. No need for a view label as the drawing contains the part number of that part. 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 4 of 19
marcelnel
in reply to: mcgyvr

Hey mcgyvr,

 

Thanks for the reply, 

 

With your example you are using the "part number" as an Item number and view label. I cant rename those part numbers as more than one company works on these models and we require that part number to never change.

 

This is why I have to use the "Item number" from parts BOM as view label for the detailed parts on the drawings. It just seems impossible to link the BOM Item numbers to the parts view label. 

 

For example with drawings I would have a,

 

*Main assembly Drawing - Would be featured on my General arrangement drawing including bolting. (3 BOMs featured here - Sub assemblies, parts and Bolts)

*Sub assemblies Drawings - Would be featured on my welded assembly detail drawings (This includes welding and bubbles for each welded assembly. Each welded assembly is a level of detail from the main assy).

*Parts Drawing - Would all be featured on one drawing following the Item numbers in my BOM list on the main GA. (All parts fit on one drawing usually)

Message 5 of 19
marcelnel
in reply to: Anonymous

Thanks for the reply Mario,

 

1. I understand the view reps and also considered this option but like you said Inventors habit of contaminating view reps, and also making 200+ view reps is way to much work for what it is worth.

 

2. The logic code seems like the best option, would you be so kind as to share the I logic code? Also with regards to this option I suppose you would be able to use the custom or unused property as a selectable option in your view label?

 

Thanks for the help!

 

 

 

 

Message 6 of 19
Anonymous
in reply to: marcelnel


@marcelnel wrote:

Thanks for the reply Mario,

 

1. I understand the view reps and also considered this option but like you said Inventors habit of contaminating view reps, and also making 200+ view reps is way to much work for what it is worth.

 

2. The logic code seems like the best option, would you be so kind as to share the I logic code? Also with regards to this option I suppose you would be able to use the custom or unused property as a selectable option in your view label?

 

Thanks for the help!

 

 

 

 


Yes Marcel most of the standard properties are available in a view label, I was actually surprised to see that Item was not. Any custom property is certainly available.

 

The code, I am sure you can work your way thru it and change the properties you use. This code is in our IAM template but gets turned so to speak only on the very top assy and is set to run before saving. There is some issues with mirror parts if you use them, may require manual changes to the BOM in the IAM file.

 

doc = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM

Dim oParams As Parameters = oAssyDef.Parameters

Dim oUserParams As UserParameters = oParams.UserParameters

Dim ParameterChecker As Parameter

Try

ParameterChecker = oParams("NUM_OF_ASSYS")

Catch

ParameterChecker = oUserParams.AddByValue("NUM_OF_ASSYS", 1, "ul")

End Try

Dim num_assys As Integer

num_assys = Parameter("NUM_OF_ASSYS")


oBOM.PartsOnlyViewEnabled = True

Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only")

Dim oBOMRow As BOMRow

For Each oBOMRow In oBOMView.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow.ComponentDefinitions.Item(1)
    
    Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.lastindexof("\")
    
    CompFileNameOnly = CompFullDocumentName.substring(index+1)
    
    Dim Itm As String
    Itm = oBOMRow.ItemNumber ()
        If iProperties.Value(CompFileNameOnly, "Project", "Engineer") <> Itm Then
        
        iProperties.Value(CompFileNameOnly, "Project", "Engineer") = Itm
        End If
   
    Dim Qty As String
    Qty = oBOMRow.TotalQuantity
    
        If iProperties.Value(CompFileNameOnly, "Project", "Authority") = "" Then
        
        iProperties.Value(CompFileNameOnly, "Project", "Authority") = num_assys*Qty
        End If
    
        If iProperties.Value(CompFileNameOnly, "Project", "Authority") <> num_assys*Qty Then
        
        iProperties.Value(CompFileNameOnly, "Project", "Authority") = num_assys*Qty
        End If

Next

 

Message 7 of 19
marcelnel
in reply to: Anonymous

Thank you Mario! Really appreciate it! I am away from my work PC today so ill try and implement this tomorrow!

Thanks again!
Message 8 of 19
marcelnel
in reply to: Anonymous

Hey Mario!

 

Thanks for the help, its greatly appreciated.

 

I am able to run ilogic rules and so forth but that is about my limit with regards to programing or writing code. I usually just search for ilogic code on the net and use it in my models.

 

If I should want to learn the basic coding required for writing ilogic codes, could you point me in the direction of what I need to learn to be able to write my own codes?

 

I have some code you might be interested in, when using your Level of Details. If your models and drawings are finished and you need to insert new parts it usually adds that part to every LOD. This code allows you to suppress the new parts in all but the active LOD. Saves me a bunch of time.

 

There is also a "explode" code that I usually use to explode patterned components.

 

If you want the code Ill be more than happy to post it.

Message 9 of 19
dan_inv09
in reply to: Anonymous

I really need to start working on figuring out this whole iLogic thing, it took me way to long to figure out what that code does - and I'm still not sure: it gets the part number from the assembly's BOM and puts it in the part?

 

I've been using the view rep method - I got this code from somewhere (I think you could maybe put a comment line with your [screen?]name in the code or something, I feel bad that I have no idea where this came from)

 

'create a design view representation for each unique part in the assembly 

'define current document
Dim openDoc As Document
openDoc = ThisDoc.Document

'set a reference to the assembly component definintion.
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition

'define the first level components collection
Dim oCompOcc As Inventor.ComponentOccurrence 

'define view rep 
Dim oViewRep As DesignViewRepresentation

'define an arraylist to hold the list of  view rep names
Dim NameList As New ArrayList()

'Look at the view reps in the assembly
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
'set the list of names to the array list
NameList.add(oViewRep.Name)
Next

'check for a Default view rep and create it if not found
If Not NameList.Contains("Default") Then
	'create Default view rep 
	oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Default") 
	oViewRep.ShowAll
	oViewRep.Activate
End If

'zoom all
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute

'look at all of the unique parts in the assembly
For Each docFile In openDoc.AllReferencedDocuments
	If docFile.DocumentType = 12290 Then '12290 is the part document enumurator
	'locate the last backslash position in the full file name
	Dim FNamePos As Long
	FNamePos = InStrRev(docFile.FullFileName, "\", -1) 
	'remove path from part file name 	
	Dim docFName As String
	docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)         
	'remove extension from part file name 
	ShortName = Left(docFName,  Len(docFName) - 4)   
		'check to see if the arraylist contains the desired view rep
		If Not NameList.Contains(ShortName) Then
		'create new View Rep 
		oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(ShortName)
		oViewRep.Activate
		oViewRep.Locked = False	
		Else If NameList.Contains(ShortName) Then
		'reference existing View Rep 
		oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(ShortName) 
		oViewRep.Activate
		oViewRep.Locked = False
		End If
		'look at all of the occurences
		For Each oCompOcc in oCompDef.Occurrences
		'locate the colon position in the occurence name
		oCompOccPos = InStrRev(oCompOcc.Name, ":") 
		'set occurence name to everything left of the colon
		oOccName = Left(oCompOcc.Name, oCompOccPos -1) 
			'set visible if name matches first occurence
	      	If oCompOcc.Name = ShortName & ":1"  Then
			oCompOcc.Visible = True
			ThisApplication.ActiveView.Update()
			Else
			oCompOcc.Visible = False
			ThisApplication.ActiveView.Update()
			End If
		Next
	End If
	'lock view rep
	oViewRep.Locked = True	
Next

'set Default View Rep active
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate

The only problem I have with it is that I usually have sub-assemblies: I'm making a weldment with a top half and a bottom half but I detail them together. This code will create a view rep for each part in the assembly it's run in but only gets the visibility right it the part is in that level: it will make a view in the "Housing" assembly for the "End wall, Top" that is in the "Top half" sub assembly but the visibility is off for everything - if I ran it in the "Top half" assembly it would give me a view rep with just "End wall, Top" showing.

I just can't tell what I'm looking at - how does it know that a part exists in the sub assembly so it makes a view named after it but it can't set the visibility for it?

(And then I have to got through each and set the visibility manually - I guess it looks like just the line or two between that End If and Next near the end, if I could just remember to change/delete that it would save me so many clicks.)

Message 10 of 19
Anonymous
in reply to: dan_inv09


@dan_inv09 wrote:

I really need to start working on figuring out this whole iLogic thing, it took me way to long to figure out what that code does - and I'm still not sure: it gets the part number from the assembly's BOM and puts it in the part?

 



My code (not my code, one of my co-workers firgured it out) takes the item # then writes it to the engineer property, then takes the qty and writes it to the authority property. Now those numbers are properties of that part and can be used in multiple BOM's and IDW files.

We do not use part numbers except for file named purposes.

Message 11 of 19
dan_inv09
in reply to: Anonymous

Item number, that's what I meant. Sorry.

 

I'm having a hard time getting my head around using the same item number in multiple BOMs. I'm guessing they're not just 1, 2, 3, 4, etc..

(Sharing quantities REALLY has me confused though.)

Message 12 of 19
Anonymous
in reply to: dan_inv09


@dan_inv09 wrote:

Item number, that's what I meant. Sorry.

 

I'm having a hard time getting my head around using the same item number in multiple BOMs. I'm guessing they're not just 1, 2, 3, 4, etc..

(Sharing quantities REALLY has me confused though.)


Grab an assembly with some subassemblies and put some individual parts in.

see what happens, you will like it. The quantities in the sub-assy BOMs will be right. Just change the item # column to be Engineer.

Message 13 of 19
dan_inv09
in reply to: Anonymous

But what if I have a left hand and a right hand each? The left hand housing is item 1 in the left hand assembly and the right hand housing is number 1 in the right hand assembly - now I've got two number 1s.

And if they each use six 1/2-13 x 2" lg. hex bolts, are there two item 15s of 6 bolts each, or does the BOM combine them but use the quantity from one? (Does "Sum of Values" for Merged Rows work for the Engineer column? But that's just for Parts Lists - or are we using the terms interchangeably?)

Message 14 of 19
Anonymous
in reply to: dan_inv09

The I-Logic is only applied to your very top assembly, if you have separate left & right hand parts they will get separate "engineer" properties. If you use the same file for all the bolts then yes they will be common and all have the same "engineer" property.

 

Message 15 of 19
dan_inv09
in reply to: Anonymous

It seemed to me like you were saying to use already established sub-assemblies.

 

So you can't reuse anything?

 

And the bolts have the same item number in everything you make? It's still confusing me. Or would you never need to open an old BOM so the fasteners only need to reflect the quantities and drawing of the assembly that is currently being worked on?

Message 16 of 19
Anonymous
in reply to: dan_inv09

Hello Dan

 

My code does have some limitations and yes no parts can be reused. If you do top assemblies from a library of parts then no it will not work for you.

We do custom machinery, mostly conveyors so relatively easy make every part in an assembly a new one.

The OP seemed to be working the same way as I do.

Message 17 of 19
sguan1212
in reply to: Anonymous

Hi Mario428,

this code doesn't do the content center parts which shows length in mm in the QTY column, how do I work around this?

 

Please see attached image showing the prompted ERROR 

 

Message 18 of 19
cameron.houston
in reply to: marcelnel

I searched everywhere to try and get this done and ultimately I ended up having to code a button to do this so I thought I would share so other people can use. The button goes through all drawing views in a drawing and compares them back to the BOM to find what ITEM number the part is. It then adds that item number to the drawing view label.  See below.

code1.png 

 

I used Brian Ekins nifftyinventoraddin template to do so. I have attached a compressed zip folder with the entire Visual Studio SLN as well as everything else needed to just drag and drop into the inventor add in location on the local drive.

 

 

Here is what the source code looks like.

 

' TODO: This module exists as a convenient location for the code that does the real
'       work when a command is executed.  If you're converting VBA macros into add-in
'       commands you can copy the macros here, make changes to make them VB.NET compatible,
'       and change any references to "ThisApplication" to "g_inventorApplication".  The example
'       command in StandardAddInServer.vb demonstrates running the "SampleCommandFunction" below.
Imports Inventor

Public Module CommandFunctions
    ' Example function that's called when the sample command is executed.
    Public Sub SampleCommandFunction()
        'define active document as the current drawing doc. Will produce an error if its not a drawing doc
        Dim oDrawDoc As DrawingDocument
        oDrawDoc = g_inventorApplication.ActiveDocument
        'Set sheet to be active sheet in window
        Dim oSheet As Sheet
        oSheet = oDrawDoc.ActiveSheet
        'Get the Primary Parts List via user mouse click
        Dim oActPartList As PartsList
        oActPartList = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter, "Select the parts list to begin")
        'Get the drawing number by extracting it from the referenced assemblies display name
        Dim oRefAssembly As String
        oRefAssembly = oActPartList.ReferencedFile.DisplayName
        Dim oRefAssemblyCount As Integer
        oRefAssemblyCount = Len(oRefAssembly)
        'This removes the eight characters at the end of all referenced assemblies .000.iam
        Dim RMV As Integer
        RMV = 8
        'Get Drawing Number
        Dim LengthReq As Integer
        LengthReq = (oRefAssemblyCount - RMV)
        'Debug.Print "The length to the right of the dot is" & LengthReq
        'MsgBox ("The Length to the right of the dot is" + CStr(LengthReq))
        Dim oDWGNum As String
        oDWGNum = Left(oRefAssembly, LengthReq)
        'MsgBox ("The Drawing Number is" + oDWGNum)
        'Manually Get Drawing Number
        'Dim oDWG As Variant
        'oDWG = InputBox("What is the number for this Drawing?")
        'Loop through MPN numbers and compare MPN value to value of drawing, if they match get item number, if not skip
        For i = 1 To oActPartList.PartsListRows.Count
            Dim oMPNCheck As String
            oMPNCheck = oActPartList.PartsListRows.Item(i).Item(2).Value
            Dim oMPNCheckLeft As String
            oMPNCheckLeft = Left(oMPNCheck, LengthReq)
            If oMPNCheckLeft = oDWGNum Then
                Dim oTest As String
                oTest = Right(oMPNCheck, 3)
                oActPartList.PartsListRows.Item(i).Item(1).Value = oTest
            Else
            End If
        Next
    End Sub

End Module
 
 
FYI some specific quirks I added was not having the item number appear for the main assembly (because obviously its not referenced in the BOM) and not having the item number appear for section or detail views.
Message 19 of 19

oops my mistake I copied the code for one of my other buttons.  Here is the right code. For reference the other button changes the item number to the last 3 digits of the part number. This is a company specific request.

 

 

Here is the right code:

 

Public Sub SampleCommandFunction()
'Get the active document which must be a drawing or else it will error
Dim oDrawDoc As DrawingDocument
oDrawDoc = g_inventorApplication.ActiveDocument

'Create an object to store all the sheets called "oSheets"
Dim oSheets As Sheets
oSheets = oDrawDoc.Sheets

'Create an object to store an individual sheet
Dim oSheet As Sheet

'For every sheet in drawing doc
For Each oSheet In oSheets

'Create an object to store all the drawing views
Dim oViews As DrawingViews
oViews = oSheet.DrawingViews

'Create an object to store an individual view
Dim oView As DrawingView

'For ever drawing view on the sheet
For Each oView In oViews

Dim c As Integer
c = 0
'Get the part number associated with the drawing view
Dim oPartNumber As String
oPartNumber = oView.ReferencedDocumentDescriptor.ReferencedDocument.PropertySets.Item(3).Item(2).Value

'Testing Message Box
'MsgBox ("Drawing View " + oPartNumber)

'Create an object to store all the boms
Dim oBoms As DrawingBOMs
oBoms = oDrawDoc.DrawingBOMs

'Create an object to store an individual bom
Dim oBom As DrawingBOM

'For every bom in the drawing
For Each oBom In oBoms


'Locate where the MPN & Item Columns Are
'Loop through all the BOM headers to find the columns and then save the column number they are in
Dim oMPNCol As Integer

For i = 1 To oBom.DrawingBOMColumns.Count

Dim oFindMPN As String
oFindMPN = oBom.DrawingBOMColumns.Item(i).Title

If oFindMPN = "MPN" Then
oMPNCol = i
End If
Next

Dim oFindItemNumCol As Integer

For i = 1 To oBom.DrawingBOMColumns.Count
Dim oFindItemNum As String
oFindItemNum = oBom.DrawingBOMColumns.Item(i).Title

If oFindItemNum = "ITEM" Then

oFindItemNumCol = i
End If
Next

 

'Store Bom reference assembly
Dim RefAssemblyLong As String
RefAssemblyLong = oBom.ReferencedDocumentDescriptor.DisplayName

'Count how many characters in RefAssembly
Dim oLengthAssembly As Integer
oLengthAssembly = Len(RefAssemblyLong)

'Assembly name without .iam (4 characters)

Dim RefAssembly As String
RefAssembly = Left(RefAssemblyLong, oLengthAssembly - 4)

'For every row in the BOM
For i = 1 To oBom.DrawingBOMRows.Count

'Get the MPN number for the Bom Item
Dim oMPN As String

oMPN = oBom.DrawingBOMRows.Item(i).Item(oMPNCol).Value

Dim oItem As String
oItem = oBom.DrawingBOMRows.Item(i).Item(oFindItemNumCol).Value

If oView.ViewType <> DrawingViewTypeEnum.kDetailDrawingViewType And oPartNumber = oMPN Then
oView.Label.FormattedText = ("DETAIL ITEM " & oItem & vbCrLf & "MPN NUMBER " & oPartNumber)
End If

Next

Next

Next
Next

MsgBox("Detail Views Have Been Updated With Item Number")
End Sub

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report