Message 1 of 7
iLogic to add custom iproperties to assembly components from Excel table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have written some iLogic code to update custom iproperties in an .ipt file that works fine. See below.
'Open the Excel file doc = ThisDoc.Document GoExcel.Open("W:\Initiatives_2019\Inventor_Workflow\iLogic_Tests\Test_Properties.xlsx", "Sheet1") 'Look at the first 1000 rows of the Excel file 'Start at row 2, since row 1 contains headings For rowCheck = 2 To 1000 'Get the filename without extension oFileName = ThisDoc.FileName(False) 'Set your delimiter Delimiter = InStr (oFileName, "-") Description = Left(oFileName, Delimiter -1) 'Compare the part name to the value in column A If GoExcel.CellValue("A" & rowCheck) = Description Then 'Get the value from column E iProperties.Value(doc, "Custom", "Die Number") = GoExcel.CellValue("E" & rowCheck) 'Get the value from column B iProperties.Value(doc, "Custom", "Finish") = GoExcel.CellValue("B" & rowCheck) 'Get the value from column C iProperties.Value(doc, "Project", "Description") = GoExcel.CellValue("C" & rowCheck) 'Get the value From Column D iProperties.Value(doc, "Custom", "Alloy-Temper") = GoExcel.CellValue("D" & rowCheck) End If Next
I am trying to adapt the same code to run in an assembly file and update all of the parts in the assembly from the same Excel table and always get the following error: "Argument 'Length' must be greater or equal to zero."
'Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument 'Get all of the referenced documents. Dim asmDoc As AssemblyDocument asmDoc = ThisApplication.ActiveDocument 'Iterate through the list of documents. Dim doc As Document For Each doc In asmDoc.AllReferencedDocuments 'Check for part documents. If doc.DocumentType = kPartDocumentObject Then 'Open the Excel file GoExcel.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\iLogic_Tests\Unit_Assembly\Part_iProperties.xlsx", "Aluminum Parts") 'Look at the first 1000 rows of the Excel file 'Start at row 2, since row 1 contains headings For rowCheck = 2 To 1000 'Get the filename without extension oFileName = ThisDoc.FileName(False) 'Set your delimiter Delimiter = InStr(oFileName, "-") Description = Left(oFileName, Delimiter -1) 'Compare the part name to the value in column A If GoExcel.CellValue("A" & rowCheck) = Description Then 'Get the value from column B iProperties.Value(doc, "Custom", "Finish") = GoExcel.CellValue("B" & rowCheck) 'Get the value from column C iProperties.Value(doc, "Project", "Description") = GoExcel.CellValue("C" & rowCheck) 'Get the value From Column D iProperties.Value(doc, "Custom", "Alloy-Temper") = GoExcel.CellValue("D" & rowCheck) 'Get the value from column E iProperties.Value(doc, "Custom", "Die Number") = GoExcel.CellValue("E" & rowCheck) 'Get the value from column F iProperties.Value(doc, "Custom", "Material") = GoExcel.CellValue("F" & rowCheck) End If Next End If Next
Any help is appreciated.