<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: assigning stock number in Inventor Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9593140#M140638</link>
    <description>&lt;P&gt;@Anonymous&amp;nbsp; If you still want this here is some ilogic code and an example excel file..&lt;/P&gt;
&lt;P&gt;This will first check if the stock number field is blank then&amp;nbsp;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..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make it work you just need to setup the following..&lt;/P&gt;
&lt;P&gt;1-change the value in the excel file to be one less than the first stock number you want to assign.&lt;/P&gt;
&lt;P&gt;2-save the excel file where you save your Inventor files..&lt;/P&gt;
&lt;P&gt;3-Edit the first line of this code below with the path to wherever you saved the excel file..&lt;/P&gt;
&lt;P&gt;4-Run this rule in whatever part files you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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" &amp;amp; RowSN)) Then
'create a variable for the cell value that is one row less than the empty cell row
    lastSN = GoExcel.CellValue("A" &amp;amp; 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" &amp;amp; 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&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jun 2020 12:12:13 GMT</pubDate>
    <dc:creator>mcgyvr</dc:creator>
    <dc:date>2020-06-22T12:12:13Z</dc:date>
    <item>
      <title>assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9580888#M140631</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 18:41:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9580888#M140631</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-15T18:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9580905#M140632</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello.&amp;nbsp; Thanks for posting!&amp;nbsp; Can you tell me what kind of part you are referring to?&amp;nbsp; 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?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 18:49:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9580905#M140632</guid>
      <dc:creator>CGBenner</dc:creator>
      <dc:date>2020-06-15T18:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9580945#M140633</link>
      <description>&lt;P&gt;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.&amp;nbsp; 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.)?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 19:04:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9580945#M140633</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-15T19:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9581040#M140634</link>
      <description>&lt;P&gt;Hi Sean,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think there is an out-of-box solution. Here is an example of a similar idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-forum/inventor-create-parts-list-gt-automatic-fill-stock-number-by/td-p/7379235" target="_blank"&gt;https://forums.autodesk.com/t5/inventor-forum/inventor-create-parts-list-gt-automatic-fill-stock-number-by/td-p/7379235&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do believe you can use an external iLogic rule to populate the stock number based on something.&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 19:54:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9581040#M140634</guid>
      <dc:creator>johnsonshiue</dc:creator>
      <dc:date>2020-06-15T19:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9581085#M140635</link>
      <description>&lt;P&gt;That would take some programming which I don't know how to do. I guess it would be based on an Excel spreadsheet.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 20:23:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9581085#M140635</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-15T20:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9583732#M140636</link>
      <description>&lt;P&gt;Hi Sean,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2020 21:20:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9583732#M140636</guid>
      <dc:creator>johnsonshiue</dc:creator>
      <dc:date>2020-06-16T21:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9591985#M140637</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jun 2020 16:09:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9591985#M140637</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-21T16:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9593140#M140638</link>
      <description>&lt;P&gt;@Anonymous&amp;nbsp; If you still want this here is some ilogic code and an example excel file..&lt;/P&gt;
&lt;P&gt;This will first check if the stock number field is blank then&amp;nbsp;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..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make it work you just need to setup the following..&lt;/P&gt;
&lt;P&gt;1-change the value in the excel file to be one less than the first stock number you want to assign.&lt;/P&gt;
&lt;P&gt;2-save the excel file where you save your Inventor files..&lt;/P&gt;
&lt;P&gt;3-Edit the first line of this code below with the path to wherever you saved the excel file..&lt;/P&gt;
&lt;P&gt;4-Run this rule in whatever part files you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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" &amp;amp; RowSN)) Then
'create a variable for the cell value that is one row less than the empty cell row
    lastSN = GoExcel.CellValue("A" &amp;amp; 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" &amp;amp; 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&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2020 12:12:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9593140#M140638</guid>
      <dc:creator>mcgyvr</dc:creator>
      <dc:date>2020-06-22T12:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9593144#M140639</link>
      <description>&lt;P&gt;But Inventor does not have an out of the box way to assign a stock number in the manner you are asking.&lt;/P&gt;
&lt;P&gt;You need to use some custom programming like the ilogic example I posted..&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2020 12:13:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/9593144#M140639</guid>
      <dc:creator>mcgyvr</dc:creator>
      <dc:date>2020-06-22T12:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/10619355#M140640</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;This rule works good. But how to do add stock numbers for all components in assembly?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 18:17:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/10619355#M140640</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-13T18:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: assigning stock number</title>
      <link>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/10619478#M140641</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;This rule works good. But how to do add stock numbers for all components in assembly?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;@Anonymous&amp;nbsp; Try this..&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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" &amp;amp; RowSN)) Then
'create a variable for the cell value that is one row less than the empty cell row
    lastSN = GoExcel.CellValue("A" &amp;amp; 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" &amp;amp; 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&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 19:14:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-forum/assigning-stock-number/m-p/10619478#M140641</guid>
      <dc:creator>mcgyvr</dc:creator>
      <dc:date>2021-09-13T19:14:06Z</dc:date>
    </item>
  </channel>
</rss>

