I'm still not sure if the custom iProperty already exists in all the referenced documents within the main assembly, or not. Or if you are expecting a solution that will create this custom iProperty within all those referenced documents. If you want that custom property created, then in order to supply a value to it, we will have to incorporate a search routine into the solution that searches down through the step file directories for one that has contains something in its file name. In this solution, I'm assuming this custom property already exists and already contains the needed path of the exported step files. Let me know if this is not the case.
I've created an iLogic rule you can try.
This rule is designed to be ran while the main assembly file is open and active
- It immediately tries to open the assembly's drawing
- It assumes the drawing has the same path & file name (with the ".dwg") file extension
- It then tries to get the PartsList
- It assumes this to be the first one found within the drawing.
- It then finds which column in that parts list is the one with "Step File" as its title, and captures the columns index number for use later.
- The this label appears different in the two images you attached.
- In the image appearing to be of the PartsList within the drawing, the column title looks like "Step File" (with a space between the two words).
- While the other image, which I assumed was from the CSV file, the column title looks like "StepFile" (with no space between the two words).
- So I am specifying the searching the PartsList for the title "Step File", then later in the code, I'm searching for the custom iProperty with the name "StepFile", assuming the CSV file may be using the custom property's name as the column title.
- The code then starts to loop through each row of the parts list, and each row is supplied as input, along with the oCol integer found earlier, to the sub which finishes the job of setting the value to the cell of that row, at that columns intersection.
- Then within the sub
- It attempts to gets the first document being represented by that parts list row
- It's showing some commented out code that attempts to get the value of the Stock Number property from that document (even though we're not using it in this scenario)
- It then attempts to get the custom property called "StepFile" (see naming issues above)
- If the property is found, it gets its value
- Then puts that value into the supplied parts list row, at the column number supplied.
Here's the code:
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("This rule was designed to run while an Assembly Document is active.",vbOKOnly, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document
'open the drawing for this assembly - assuming it has same path and file name as model file (with different file extension)
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Open(oADoc.FullFileName.Replace(".iam", ".dwg"))
'Get the PartsList - assuming it is the first PartsList found within the drawing document
Dim oPList As PartsList
For Each oSheet As Inventor.Sheet In oDDoc.Sheets
If oSheet.PartsLists.Count > 0 Then
oPList = oSheet.PartsLists.Item(1)
End If
Next
Dim oCol As Integer
For oCol = 1 To oPList.PartsListColumns.Count
If oPList.PartsListColumns.Item(oCol).Title = "Step File" Then ' <<<< CHECK THIS NAME >>>>
Exit For
End If
Next
Dim oRow As PartsListRow
For Each oRow In oPList.PartsListRows
SetStepFilePath(oRow, oCol)
Next
End Sub
Sub SetStepFilePath(ByRef oPLRow As PartsListRow, ByRef oPLCol As Integer)
'Dim oPartsList As PartsList = oPLRow.Parent
Dim oDrawingBOMRow As DrawingBOMRow = oPLRow.ReferencedRows.Item(1)
Dim oBOMRow As BOMRow = oDrawingBOMRow.BOMRow
Dim oRowDoc As Document = oBOMRow.ComponentDefinitions.Item(1).Document
Dim oPropSets As PropertySets = oRowDoc.PropertySets
'Dim oStockNum As String = oPropSets.Item("Design Tracking Properties").Item("Stock Number").Value
' If oStockNum = vbNullString Then
' MsgBox("The 'Stock Number' property was empty in the following document:" & vbCrLf & _
' oRowDoc.FullFileName, vbOKOnly, "Sock Number Missing")
' End If
'Check for the custom 'StepFile' property
Dim oStepFileProp As Inventor.Property
Try ' <<<<<< MAKE SURE THE PROPERTY NAME IS SPELLED CORRECTLY >>>>>>>
oStepFileProp = oPropSets.Item("Inventor User Defined Properties").Item("StepFile")
'oStepFileProp = oPropSets.Item("Inventor User Defined Properties").Item("Step File")
Catch
MsgBox("The custom property named could not be found in the following document:" & vbCrLf & _
oRowDoc.FullFileName, vbOKOnly, "Custom Property Not Found")
Exit Sub
End Try
Dim oStepFile As String = oStepFileProp.Value
oPLRow.Item(oPLCol).Value = oStepFile
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS
Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)