assigning stock number

assigning stock number

Anonymous
Not applicable
2,782 Views
10 Replies
Message 1 of 11

assigning stock number

Anonymous
Not applicable

Is there a way to automatically generate a stock number in Iproperites for a part? I'm using Inventor 2021. Right now I have to manually add the stock number based on a pdf file name.

0 Likes
Accepted solutions (1)
2,783 Views
10 Replies
Replies (10)
Message 2 of 11

CGBenner
Community Manager
Community Manager

@Anonymous 

 

Hello.  Thanks for posting!  Can you tell me what kind of part you are referring to?  is this a part model that you have created yourself, or one that is generated from the Content Center or one of the Design Accelerators?

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!



Chris Benner

Community Manager - NAMER / D&M


Message 3 of 11

Anonymous
Not applicable

It's a part that I created. I'm reverse-engineering some miniature steam engines and I've manually added parts numbers to the pdf drawing files that I downloaded. So far there are over 200 individual part numbers that I have to make sure I don't duplicate from project to project.  Also, if this is possible, can the automatic stock number be incremented by a certain number (ex 26-200 is the first number, then 26-201 etc.)?

0 Likes
Message 4 of 11

johnsonshiue
Community Manager
Community Manager

Hi Sean,

 

I don't think there is an out-of-box solution. Here is an example of a similar idea.

 

https://forums.autodesk.com/t5/inventor-forum/inventor-create-parts-list-gt-automatic-fill-stock-num...

 

I do believe you can use an external iLogic rule to populate the stock number based on something.

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 5 of 11

Anonymous
Not applicable

That would take some programming which I don't know how to do. I guess it would be based on an Excel spreadsheet.

0 Likes
Message 6 of 11

johnsonshiue
Community Manager
Community Manager

Hi Sean,

 

Please share an example of what you are trying to do (an ipt and an Excel spreadsheet). I believe it should be doable via an external iLogic rule. We have quite a few iLogic experts here to help.

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 7 of 11

Anonymous
Not applicable

To be honest about it, I haven't given this topic much thought because I forgot about it. It's not that important to me, so I'll just keep on assigning stock numbers to parts the way that I've been doing.

0 Likes
Message 8 of 11

mcgyvr
Consultant
Consultant

@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
Message 9 of 11

mcgyvr
Consultant
Consultant
Accepted solution

But Inventor does not have an out of the box way to assign a stock number in the manner you are asking.

You need to use some custom programming like the ilogic example I posted..



-------------------------------------------------------------------------------------------
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
0 Likes
Message 10 of 11

Anonymous
Not applicable

Hi!

This rule works good. But how to do add stock numbers for all components in assembly?

0 Likes
Message 11 of 11

mcgyvr
Consultant
Consultant

@Anonymous wrote:

Hi!

This rule works good. But how to do add stock numbers for all components in assembly?


@Anonymous  Try this..

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all Of the occurrences
Dim oOcc As ComponentOccurrence

For Each oOcc In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 
	

''''''''''
TheExcelFile = "C:\StockNumbers.xlsx"

'only run this rule if the stock number is not set
If iProperties.Value(oOcc.Name, "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(oOcc.Name, "Project", "Stock Number") = NewSN
Else
	MessageBox.Show("Stock Number already set", "Stock Number Inspector")
End If
''''''''''

Next


-------------------------------------------------------------------------------------------
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