Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a rule that adds custom iProperties to parts in an assembly from an Excel file. The rule runs as expected the first time it is run, however if I make a change to the Excel file and run the rule again to update the iProperties, I get an error. The rule is below. I am not advanced enough yet (but learning lots) to determine why it runs the first time but not again after changes. Thank you for any help.
oDocFile = ThisDoc.Document Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOcc As ComponentOccurrence Dim oDocFileName As String Dim oFileNamePos As Long For Each oOcc In oAsmCompDef.Occurrences If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then oDocFile = oOcc.Definition.Document 'Find position in full filename path string where component filename begins oFileNamePos = InStrRev(oDocFile.FullFileName, "\", - 1) 'Strip off filename path string and set oDocFileName to just the component's file name oDocFileName = Mid(oDocFile.FullFileName, oFileNamePos + 1, Len(oDocFile.FullFileName) - oFileNamePos) 'Set your delimiter Delimiter = InStr(oDocFileName, "-") Description = Left(oDocFileName, Delimiter - 1) 'Open the Excel file GoExcel.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\iLogic\Unit_Drawing_Tests\Part_iProperties.xlsx", "Parts") 'Look at the first 15 rows of the Excel file 'Start at row 2, since row 1 contains headings For rowCheck = 2 To 15 'Compare the part name to the value in column A If GoExcel.CellValue("A" & rowCheck) = Description Then iProperties.Value(oDocFileName, "Custom", "Extrusion") = GoExcel.CellValue("B" & rowCheck) iProperties.Value(oDocFileName, "Custom", "Alloy-Temper") = GoExcel.CellValue("C" & rowCheck) iProperties.Value(oDocFileName, "Custom", "Material") = GoExcel.CellValue("D" & rowCheck) iProperties.Value(oDocFileName, "Custom", "Finish") = GoExcel.CellValue("E" & rowCheck) iProperties.Value(oDocFileName, "Custom", "Color") = GoExcel.CellValue("F" & rowCheck) iProperties.Value(oDocFileName, "Custom", "Hydro Code") = GoExcel.CellValue("G" & rowCheck) iProperties.Value(oDocFileName, "Custom", "Routing") = GoExcel.CellValue("H" & rowCheck) iProperties.Value(oDocFileName, "Project", "Description") = GoExcel.CellValue("I" & rowCheck) End If Next 'Open the Excel file GoExcel.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\iLogic\Unit_Drawing_Tests\Part_iProperties.xlsx", "Infills") 'Look at the first 15 rows of the Excel file 'Start at row 2, since row 1 contains headings For rowCheck = 2 To 15 'Compare the part name to the value in column A If GoExcel.CellValue("A" & rowCheck) = Description Then iProperties.Value(oDocFileName, "Custom", "Routing") = GoExcel.CellValue("B" & rowCheck) iProperties.Value(oDocFileName, "Project", "Description") = GoExcel.CellValue("C" & rowCheck) iProperties.Value(oDocFileName, "Custom", "Make-up") = GoExcel.CellValue("D" & rowCheck) End If Next End If Next oOcc
Solved! Go to Solution.