Oh I like this. Using the part number from the design tracking properties is a pretty good approach. Tried to push this into the code and not getting any errors, but the behavior seems to be a little off. Ultimately I'm trying to access the user defined properties of that occurrence
Just to clarify this is how it works... The refDoc portion is pretty simple -
Loop through all the referenced documents and return the occurrence of refDoc once the PartNumber from the tracking portion matches SearchName and exit the loop.
Next check the occurrences - if it's 'not' nothing then oFoundOcc is set to the first occurrence
After that, the call to oAsmDoc.SelectSet.Select(oFoundOcc)... In this portion is the 'call' just telling Inventor go to oAsmDoc and select oFoundOcc? I've really only used Call to run a subroutine, but it seems like that's what this line is from other SelecSet examples?
Public Sub
// Excel Stuff
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition
Set oAsmDef = oAsmDoc.ComponentDefinition
Dim oOccs As ComponentOccurrencesEnumerator
Dim oFoundOcc As ComponentOccurrence
Dim refDoc As Document
Dim PropDoc As Document
Dim oPropSet As PropertySet
Dim invModPClass As PropertySet
Dim prop As Property
Dim SearchName As String
Dim SNameCell As Integer
Dim FinishCell As Integer
Dim PClassCell As Integer
Dim LTimeCell As Integer
Dim DTypeCell As Integer
Dim RM_QTYCell As Integer
SNameCell = 2
FinishCell = 15
PClassCell = 11
LTimeCell = 12
DTypeCell = 13
RM_QTYCell = 14
' Variables pre-loop
Dim i As Integer
Dim NumRows As Integer
NumRows = excelApp.Range("A1", Range("A1").End(xlDown)).Rows.Count
Debug.Print ("Number of rows: " + NumRows)
' begin loop
For i = 1 To (NumRows - 1)
i = i + 1
' In Excel get part name
SearchName = excelApp.Cells(i, SNameCell)
' In Excel get properties
Finish = excelApp.Cells(i, FinishCell)
PClass = excelApp.Cells(i, PClassCell)
LeadTime = excelApp.Cells(i, LTimeCell)
DType = excelApp.Cells(i, DTypeCell)
RM_QTY = excelApp.Cells(i, RM_QTYCell)
' In Inventor find part
For Each refDoc In oAsmDoc.AllReferencedDocuments
If refDoc.PropertySets("Design Tracking Properties")("PartNumber").Value = SearchName Then
Set oOccs = oAsmDef.Occurrences.AllReferencedOccurrences(refDoc)
Exit For
End If
Next
If oOccs Is Nothing = False Then
Set oFoundOcc = oOccs(1)
Call oAsmDoc.SelectSet.Select(oFoundOcc)
Else
MsgBox (SearchName & " was not found")
End If
Set PropDoc = oFoundOcc.Definition.Document
' In Inventor assign property to part
'Debug.Print (SearchName)
'Debug.Print (" Finish: " & Finish)
'Debug.Print (" PClass: " & PClass)
'Debug.Print (" LeadTime: " & LeadTime)
'Debug.Print (" DType: " & DType)
Set oPropSet = PropDoc.PropertySets.Item("Inventor User Defined Properties")
On Error Resume Next
Set prop = oPropSet.Item("M1_PClass")
prop.Value = PClass
If Err Then
Set invModPClass = oPropSet.Add(PClass, "M1_PClass")
Call oPropSet.Add(PClass, "M1_PClass")
End If
' repeat
Next
End Sub
At the moment it's printing every value from my excel window into the window so I know it's getting the values from Excel. The values (i.e. PClass, M1_Pclass) are not being updated in the parts themselves. Sorry if I didn't give you enough information about this ahead of time, it seemed like it was going to be a little easier. Find occurrence -> get occurrence definition as document -> access property sets -> add values but it's misbehaving