<?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: iLogic to select stock number from excel file in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-select-stock-number-from-excel-file/m-p/11488275#M143981</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10839875"&gt;@KWarrenCA&lt;/a&gt;.&amp;nbsp; As for how to set this rule up so that it will only run on a sheet metal part, I think the following bit of code should do that for you, if put right at the very start of your rule.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;If ThisDoc.Document.SubType &amp;lt;&amp;gt; "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	MsgBox("This is not a Sheet Metal Part.  Exiting rule.", vbCritical, "iLogic")
	Exit Sub 'or Return
End If&lt;/LI-CODE&gt;
&lt;P&gt;I will revue the other request(s) and the Excel file next, if time/opportunity permits.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2022 16:15:49 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2022-10-17T16:15:49Z</dc:date>
    <item>
      <title>iLogic to select stock number from excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-select-stock-number-from-excel-file/m-p/11488210#M143979</link>
      <description>&lt;P&gt;I'm working on an iLogic to look at the sheet metal flat pattern dimensions and select the correct part number. Right now I have it working correctly if the size is in between 2 numbers. The issue I'm running into is if say a 48 x 120 sheet is not in stock or unavailable but a 60 x 120 is in stock to select the larger sheet stock number.&lt;/P&gt;&lt;P&gt;I attached the excel file and the code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also only want this to run on a sheet metal part. How would I go about doing that.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;''Sheet Metal Stock Number
'Pulls flat pattern extents
	Dim oLength As Double
	Dim oWidth As Double

	ex_Length = SheetMetal.FlatExtentsLength
	ex_Width = SheetMetal.FlatExtentsWidth

'Checks flat pattern to see what length is longer and defines the longer side to be length
	If ex_Length &amp;gt; ex_Width Then
		oLength = ex_Length
		oWidth = ex_Width
	Else
		oWidth = ex_Length
		oLength = ex_Width
	End If



'Define Excel File to Lookup
	ExcelFile = "C:\CA Workspace\CAD Standards\CA Library A\iLogic Automation\CA - Sheetmetal Part Number Selection - Table.xlsx"
'Ignores any excel alerts
	GoExcel.DisplayAlerts = False

'Message box warning for non stocked items
	NonStockedNote = "This Item is not Stocked. Check with Purchasing on Availablity!"
	
	Dim SheetMetalStyle As String
	SheetMetalStyle = SheetMetal.GetActiveStyle
	SheetMaterial = iProperties.Material
	
'IF the sheet is larger than 72 X 144 notifys user sheet is custom order
If (oWidth &amp;gt;72) AndAlso (oLength &amp;gt;144) Then
	i = MessageBox.Show("Sheet is too large for Stocked material. Check with Purchasing if we can order custom sheet sizes", "Too Large of Sheet", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
	SheetPartnumber = "Check With Purchasing if we can order a sheet this size."
End If


''Setting Width depending on sheet size
If (oWidth &amp;lt;= 48) AndAlso (oWidth &amp;gt;0) Then
	oSetWidth = 48
Else If (oWidth &amp;lt;= 60) AndAlso (oWidth &amp;gt; 48.000001)
	oSetWidth = 60
Else If (oWidth &amp;lt;=72) AndAlso (oWidth &amp;gt; 60.000001) Then
	oSetWidth = 72
End If

''Setting Length depending on sheet size
If (oLength &amp;lt;= 120) AndAlso (oLength &amp;gt; 0)
	oSetLength = 120
Else If (oLength &amp;lt;= 144) AndAlso (oLength &amp;gt; 120.000001)
	oSetLength = 144
End If

'i = MessageBox.Show(oSetWidth &amp;amp; OSetLength, "Sheet Size", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1)


Dim rowNum As Integer = GoExcel.FindRow(ExcelFile, "Stocked", "Sheet Metal Rule", "=", SheetMetalStyle, "Material", "=", iProperties.Material, "Sheet Width (Short Side)", "=", oSetWidth, "Sheet Length (Long Side)", "=", oSetLength)
'If no option is available then message box
If (rowNum &amp;gt;0) Then

		If GoExcel.CurrentRowValue("Stocked") = "Yes" Then
			SheetPartnumber = GoExcel.CurrentRowValue("Part Number")
 			question = MessageBox.Show("The Stock Number will be replaced with the "&amp;amp; SheetPartnumber &amp;amp;" are you sure you want to procceed", "Warning Stock Number Change", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
				If question = vbNo Then
					Else If question = vbYes Then
				iProperties.Value("Project", "Stock Number") = SheetPartnumber
				Return
			End If
		Else If GoExcel.CurrentRowValue("Stocked") = "No" Then
			SheetPartnumber = GoExcel.CurrentRowValue("Part Number")
			question = MessageBox.Show(NonStockedNote &amp;amp; "The Stock Number will be replaced with the "&amp;amp; SheetPartnumber &amp;amp;" are you sure you want to procceed", "Non Stocked Sheet", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
				If question = vbNo Then
					Else If question = vbYes Then
				iProperties.Value("Project", "Stock Number") = SheetPartnumber
				Return
			End If
		End If
Else If (rowNum &amp;lt;0) Then
	i = MessageBox.Show("No Sheet Size Available. Check Purchasing for Part Number.", "No Sheet Size Available", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)

End If&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 15:58:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-select-stock-number-from-excel-file/m-p/11488210#M143979</guid>
      <dc:creator>KWarrenCA</dc:creator>
      <dc:date>2022-10-17T15:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic to select stock number from excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-select-stock-number-from-excel-file/m-p/11488275#M143981</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10839875"&gt;@KWarrenCA&lt;/a&gt;.&amp;nbsp; As for how to set this rule up so that it will only run on a sheet metal part, I think the following bit of code should do that for you, if put right at the very start of your rule.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;If ThisDoc.Document.SubType &amp;lt;&amp;gt; "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	MsgBox("This is not a Sheet Metal Part.  Exiting rule.", vbCritical, "iLogic")
	Exit Sub 'or Return
End If&lt;/LI-CODE&gt;
&lt;P&gt;I will revue the other request(s) and the Excel file next, if time/opportunity permits.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 16:15:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-select-stock-number-from-excel-file/m-p/11488275#M143981</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-10-17T16:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic to select stock number from excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-select-stock-number-from-excel-file/m-p/11504157#M144262</link>
      <description>&lt;P&gt;I was able to rework this code to get it to work the way I wanted it to by looking for stocked items first if no stocked items were found it would search again for non stocked items.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;''Sheet Metal Stock Number
'Checks to see if the file is sheet metal. If not it will return.
If oSubType = "Sheet Metal" Then

'Pulls flat pattern extents
	Dim oLength As Double
	Dim oWidth As Double

	ex_Length = SheetMetal.FlatExtentsLength
	ex_Width = SheetMetal.FlatExtentsWidth

'Checks flat pattern to see what length is longer and defines the longer side to be length
	If ex_Length &amp;gt; ex_Width Then
		oLength = ex_Length
		oWidth = ex_Width
	Else
		oWidth = ex_Length
		oLength = ex_Width
	End If



'Define Excel File to Lookup
	ExcelFile = "C:\CA Workspace\CAD Standards\CA Library A\iLogic Automation\CA - Sheetmetal Part Number Selection - Table.xlsx"
'Ignores any excel alerts
	GoExcel.DisplayAlerts = False

'Message box warning for non stocked items
	NonStockedNote = "This Item is not Stocked. Check with Purchasing on Availablity!"
	
	Dim SheetMetalStyle As String
	SheetMetalStyle = SheetMetal.GetActiveStyle
	SheetMaterial = iProperties.Material
	
'Checks the sheet if it is larger than 72 X 144 notifies user sheet is custom order
If (oWidth &amp;gt;72) AndAlso (oLength &amp;gt;144) Then
	i = MessageBox.Show("Sheet is too large for Stocked material. Check with Purchasing if we can order custom sheet sizes", "Too Large of Sheet", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
	SheetPartnumber = "Check With Purchasing if we can order a sheet this size."
End If


''Setting Width depending on sheet size
If (oWidth &amp;lt;= 48) AndAlso (oWidth &amp;gt;0) Then
	oSetWidth = 48
Else If (oWidth &amp;lt;= 60) AndAlso (oWidth &amp;gt; 48.000001)
	oSetWidth = 60
Else If (oWidth &amp;lt;=72) AndAlso (oWidth &amp;gt; 60.000001) Then
	oSetWidth = 72
End If

''Setting Length depending on sheet size
If (oLength &amp;lt;= 120) AndAlso (oLength &amp;gt; 0) Then
	oSetLength = 120
Else If (oLength &amp;lt;= 144) AndAlso (oLength &amp;gt; 120.000001)Then
	oSetLength = 144
End If

'Used to verify it works on sheet size
'i = MessageBox.Show(oSetWidth &amp;amp; OSetLength, "Sheet Size", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1)


Dim rowNum As Integer = GoExcel.FindRow(ExcelFile, "Stocked", "Sheet Metal Rule", "=", SheetMetalStyle, "Material", "=", iProperties.Material, "Sheet Width (Short Side)", "&amp;gt;=", oSetWidth, "Sheet Length (Long Side)", "&amp;gt;=", oSetLength, "Stocked", "=", "Yes")

'Checks if no option is available then displays message box to user
If (rowNum &amp;gt;0) Then
			SheetPartnumber = GoExcel.CurrentRowValue("Part Number")
			CostCode = GoExcel.CurrentRowValue("Cost Code")
 			question = MessageBox.Show("The Stock Number will be replaced with the "&amp;amp; SheetPartnumber &amp;amp;" are you sure you want to procceed?", "Warning Stock Number Change", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
				If question = vbNo Then
					Return
					Else If question = vbYes Then
				iProperties.Value("Project", "Stock Number") = SheetPartnumber
				iProperties.Value("Project", "Cost Center") = CostCode
				Return
			End If
		
	Else If (rowNum &amp;lt;0) Then
	End If
	
Dim rowNum2 As Integer = GoExcel.FindRow(ExcelFile, "Stocked", "Sheet Metal Rule", "=", SheetMetalStyle, "Material", "=", iProperties.Material, "Sheet Width (Short Side)", "&amp;gt;=", oSetWidth, "Sheet Length (Long Side)", "&amp;gt;=", oSetLength, "Stocked", "=", "No")

If (rowNum2 &amp;gt;0)Then
			SheetPartnumber = GoExcel.CurrentRowValue("Part Number")
			CostCode = GoExcel.CurrentRowValue("Cost Code")
			question = MessageBox.Show(NonStockedNote &amp;amp; "The Stock Number will be replaced with the "&amp;amp; SheetPartnumber &amp;amp;" are you sure you want to procceed?", "Non Stocked Sheet", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
				If question = vbNo Then
					Return
					Else If question = vbYes Then
				iProperties.Value("Project", "Stock Number") = SheetPartnumber
				iProperties.Value("Project", "Cost Center") = CostCode
				Return
				End If
		Else If (rowNum2 &amp;lt;0) Then
			i = MessageBox.Show("No Sheet Size Available. Check Purchasing for Part Number.", "No Sheet Size Available", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
		End If


Else 
	Return
End If&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 13:46:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-to-select-stock-number-from-excel-file/m-p/11504157#M144262</guid>
      <dc:creator>KWarrenCA</dc:creator>
      <dc:date>2022-10-24T13:46:13Z</dc:date>
    </item>
  </channel>
</rss>

