I created a Do until loop that will run through and make all my parts for me, while reading the parameters for each part from excel. I have the user input the values in the attached pictures before running the rule. My problem is that even though it correctly reads in the parameters from excel, and i've put in message boxes to show me that the parameters are correct throughout the rule, when the part gets to the save as, it only saves out the template. So even though throughout the creation of part 1, the width shows up as 20, when I open the part afterwards, the width is back to being 50.
Before I had it set up so that instead of having a do until loop it would bring up the save as dialog with the next name on the list and all I had to do was hold down the enter key until all the parts were made. That worked, but I was really hoping to automate it so that I could be working on other things while this ran.
This is the excel it is reading from:
SyntaxEditor Code Snippet
Sub Main() Dim row As Integer = 3 'the 2nd row in excel is the template information Dim CellVal As String = "Part" GoExcel.Open(ExcelFile, SheetName) Dim path As String = ThisDoc.Path & "\" Do Until CellVal = "" Dim columnLetter As String = "A" CellVal = GoExcel.CellValue(columnLetter & row) If CellVal = "" Then Exit Do ReadExcel(CellVal) 'read the excel value InventorVb.DocumentUpdate() 'update part to show new values SaveAsNew(CellVal) 'save as part with new name row=row+1 Loop End Sub Function ReadExcel(CellVal)
'this function reads in the values from excel
i = GoExcel.FindRow(ExcelFile, SheetName, "Part", "=", CellVal) 'find the row with the part name
'get values corresponding to that part name Width = GoExcel.CurrentRowValue("Width") Left_Angle = GoExcel.CurrentRowValue("Left Angle") Right_Angle = GoExcel.CurrentRowValue("Right Angle") iLogicVb.UpdateWhenDone = True
ThisDoc.Save End Function Function SaveAsNew(CellVal) Dim newname As String newname = NewPath & CellVal InventorVb.DocumentUpdate() ThisDoc.Save ThisDoc.Document.SaveAs(newname & ".ipt", True) End Function
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Try something like this instead:
Sub Main() Dim row As Integer = 3 'the 2nd row in excel is the template information Dim CellVal As String = "Part" GoExcel.Open(ExcelFile, SheetName) oActiveDoc = ThisDoc.Document Dim path As String = oActiveDoc.Path & "\" Dim columnLetter As String = "A" CellVal = GoExcel.CellValue(columnLetter & row) Do Until CellVal = "" GeneratenewFile(CellVal) 'read the excel value row=row+1 CellVal = GoExcel.CellValue(columnLetter & row) Loop End Sub Dim oActiveDoc As Document Sub GenerateNewFile(CellVal) 'this function reads in the values from excel i = GoExcel.FindRow(ExcelFile, SheetName, "Part", "=", CellVal) 'find the row with the part name 'get values corresponding to that part name oActiveDoc.ComponentDefinition.Paramters("Width").Expression = GoExcel.CurrentRowValue("Width") oActiveDoc.ComponentDefinition.Paramters("Left_Angle").Expression = GoExcel.CurrentRowValue("Left Angle") oActiveDoc.ComponentDefinition.Paramters("Right_Angle").Expression = GoExcel.CurrentRowValue("Right Angle") iLogicVb.UpdateWhenDone = True InventorVb.DocumentUpdate() oActiveDoc.SaveAs(NewPath & CellVal & ".ipt", True) End Sub
Thank you! Your code worked for the first one but then not for the rest. I used some of the code you had written to modify mine though and now it works. The code ended up being this:
SyntaxEditor Code Snippet
Sub Main() Dim row As Integer = 3 Dim CellVal As String = "Part" GoExcel.Open(ExcelFile, SheetName) Dim path As String = ThisDoc.Path & "\" Do Until CellVal = "" Dim columnLetter As String = "A" CellVal = GoExcel.CellValue(columnLetter & row) If CellVal = "" Then Exit Do ReadExcel(CellVal) iLogicVb.UpdateWhenDone = True SaveAsNew(CellVal) row=row+1 Loop End Sub Function ReadExcel(CellVal) i = GoExcel.FindRow(ExcelFile, SheetName, "Part", "=", CellVal) ThisDoc.Document.ComponentDefinition.Parameters("Width").Expression = GoExcel.CurrentRowValue("Width") ThisDoc.Document.ComponentDefinition.Parameters("Left_Angle").Expression = GoExcel.CurrentRowValue("Left Angle") ThisDoc.Document.ComponentDefinition.Parameters("Right_Angle").Expression = GoExcel.CurrentRowValue("Right Angle") iLogicVb.UpdateWhenDone = True InventorVb.DocumentUpdate() ThisDoc.Save End Function Function SaveAsNew(CellVal) Dim newname As String newname = NewPath & CellVal InventorVb.DocumentUpdate() ThisDoc.Save ThisDoc.Document.SaveAs(newname & ".ipt", True) End Function