@Anonymous If you still want this here is some ilogic code and an example excel file..
This will first check if the stock number field is blank then will open the excel file and look for the first row in column A that doesn't have a value and then look at the row before that and create a new stock number thats 1 more than that last number. Then it will put the new stock number into the last open row for next time.. Then it will insert that new value as the stock number in the part file in which the rule was run..
To make it work you just need to setup the following..
1-change the value in the excel file to be one less than the first stock number you want to assign.
2-save the excel file where you save your Inventor files..
3-Edit the first line of this code below with the path to wherever you saved the excel file..
4-Run this rule in whatever part files you want.
TheExcelFile = "C:\StockNumbers.xlsx"
'only run this rule if the stock number is not set
If iProperties.Value("Project", "Stock Number") = "" Then
GoExcel.Open(TheExcelFile, "Sheet1")
'index row 2 through 10000
For RowSN = 1 To 10000
'find first empty cell in column A
If String.IsNullOrEmpty(GoExcel.CellValue("A" & RowSN)) Then
'create a variable for the cell value that is one row less than the empty cell row
lastSN = GoExcel.CellValue("A" & RowSN - 1)
'create a new variable that is one more than the last cell
NewSN = lastSN + 1
MessageBox.Show(NewSN, "New Stock Number..")
'Write the new variable to the open row
GoExcel.CellValue("A" & RowSN) = NewSN
Exit For
End If
Next
GoExcel.Save
'fill in the stock number iprop with the new stock number
iProperties.Value("Project", "Stock Number") = NewSN
Else
MessageBox.Show("Stock Number already set", "Stock Number Inspector")
End If
-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570
Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269