Ilogic Automatic Stock Size rule, doesnt always work

Ilogic Automatic Stock Size rule, doesnt always work

Anonymous
Not applicable
877 Views
8 Replies
Message 1 of 9

Ilogic Automatic Stock Size rule, doesnt always work

Anonymous
Not applicable

We have a rule that runs when files are dirty and they are saved, It sets the stock size automatically for the BOMs and detail sheets...   Only problems are that it tends to crash for reasons i cant duplicate reliably.  Once i restart inventor and run it, it will work fine...

 

On the other hand, It will not compensate for a machined plate.  It uses the final limit size of the object instead of the initial thickness.  Currently i supress the rule and manually enter it. I wouldn't be opposed to adding a checkbox to our detail information form that states a machined part....

 

The employee that wrote the code no longer works here, I don't understand code enough to try to fix it at this time....

 

Posting Code in a reply to this post.

 

Can anyone assist me with this?

0 Likes
878 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

If ThisApplication.ActiveDocument.Dirty = True Then

'set purchase component iProperty to pass to ERP
Try
If purchasedComponent = True Then
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
iProperties.Value("Custom", "purchasedComponent") = "P"
Else purchasedComponent = False
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
iProperties.Value("Custom", "purchasedComponent") = "M"
End If
Catch
End Try
If ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
'part is a purchased component and does not require a stock size
'Write To iProperties To pass To ERP
iProperties.Value("Custom", "erpMaterial") = ""
iProperties.Value("Custom", "cutLength") = ""
Else
'part is a make component and does require a stock size
'get the physical extents of the model
Try
If SheetMetal.FlatExtentsLength > 0 Or SheetMetal.FlatExtentsWidth > 0 Then
sideA = SheetMetal.FlatExtentsLength
sideB = SheetMetal.FlatExtentsWidth
sideC = Parameter("Thickness")
Else
sideA = Measure.ExtentsLength
sideB = Measure.ExtentsWidth
sideC = Measure.ExtentsHeight
End If
Catch
sideA = Measure.ExtentsLength
sideB = Measure.ExtentsWidth
sideC = Measure.ExtentsHeight
End Try

'change thickness verbage to a gage if thickness is a sheet metal gage. Note: ranges are used because the equal operator is not reliable
If MinOfMany(sideA, sideB, sideC) > 0.1344 And MinOfMany(sideA, sideB, sideC) < 0.1346 And iProperties.Material = "1020 HRS" Then
thick = "10 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.1195 And MinOfMany(sideA, sideB, sideC) < 0.1197 And iProperties.Material = "1020 HRS" Then
thick = "11 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.1045 And MinOfMany(sideA, sideB, sideC) < 0.1047 And iProperties.Material = "1020 HRS" Then
thick = "12 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0896 And MinOfMany(sideA, sideB, sideC) < 0.0898 And iProperties.Material = "1020 HRS" Then
thick = "13 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0746 And MinOfMany(sideA, sideB, sideC) < 0.0748 And iProperties.Material = "1020 HRS" Then
thick = "14 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0672 And MinOfMany(sideA, sideB, sideC) < 0.0674 And iProperties.Material = "1020 HRS" Then
thick = "15 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0597 And MinOfMany(sideA, sideB, sideC) < 0.0599 And iProperties.Material = "1020 HRS" Then
thick = "16 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.1405 And MinOfMany(sideA, sideB, sideC) < 0.1407 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then
thick = "10 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.1249 And MinOfMany(sideA, sideB, sideC) < 0.1251 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then
thick = "11 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.1093 And MinOfMany(sideA, sideB, sideC) < 0.1095 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then
thick = "12 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0936 And MinOfMany(sideA, sideB, sideC) < 0.0938 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then
thick = "13 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0780 And MinOfMany(sideA, sideB, sideC) < 0.0782 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then
thick = "14 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0702 And MinOfMany(sideA, sideB, sideC) < 0.0704 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then
thick = "15 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0624 And MinOfMany(sideA, sideB, sideC) < 0.0626 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then
thick = "16 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.1018 And MinOfMany(sideA, sideB, sideC) < 0.1020 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then
thick = "10 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0906 And MinOfMany(sideA, sideB, sideC) < 0.0908 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then
thick = "11 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0807 And MinOfMany(sideA, sideB, sideC) < 0.0809 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then
thick = "12 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0719 And MinOfMany(sideA, sideB, sideC) < 0.0721 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then
thick = "13 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0640 And MinOfMany(sideA, sideB, sideC) < 0.0642 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then
thick = "14 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0570 And MinOfMany(sideA, sideB, sideC) < 0.0572 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then
thick = "15 GA."
Else If MinOfMany(sideA, sideB, sideC) > 0.0507 And MinOfMany(sideA, sideB, sideC) < 0.0509 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then
thick = "16 GA."
End If

'determine the order of dimensions of the part, smallest to largest
Dim dimList As New ArrayList()

If sideA = sideB And sideA = sideC Then
dimList.add(sideA)
dimList.add(sideB)
dimList.add(sideC)
Else If sideA = sideB And sideA > sideC Then
dimList.add(sideC)
dimList.add(sideA)
dimList.add(sideB)
Else If sideB = sideC And sideB > sideA Then
dimList.add(sideA)
dimList.add(sideB)
dimList.add(sideC)
Else If sideC = sideA And sideC > sideB Then
dimList.add(sideB)
dimList.add(sideC)
dimList.add(sideA)
Else If sideA = sideB And sideA < sideC Then
dimList.add(sideB)
dimList.add(sideA)
dimList.add(sideC)
Else If sideB = sideC And sideB < sideA Then
dimList.add(sideC)
dimList.add(sideB)
dimList.add(sideA)
Else If sideC = sideA And sideC < sideB Then
dimList.add(sideA)
dimList.add(sideC)
dimList.add(sideB)
Else If sideA > sideB And sideB > sideC Then
dimList.add(sideC)
dimList.add(sideB)
dimList.add(sideA)
Else If sideB > sideC And sideC > sideA Then
dimList.add(sideA)
dimList.add(sideC)
dimList.add(sideB)
Else If sideC > sideA And sideA > sideB Then
dimList.add(sideB)
dimList.add(sideA)
dimList.add(sideC)
Else If sideC > sideB And sideB > sideA Then
dimList.add(sideA)
dimList.add(sideB)
dimList.add(sideC)
Else If sideA > sideC And sideC > sideB Then
dimList.add(sideB)
dimList.add(sideC)
dimList.add(sideA)
Else If sideB > sideA And sideA > sideC Then
dimList.add(sideC)
dimList.add(sideA)
dimList.add(sideB)
End If

'label dimensions
If thick = "" Then
thick = CDblAny(dimList(0))
End If

shortSide = CDblAny(dimList(1))
longSide = CDblAny(dimList(2))

'assumption: There are no more than 40 widths for any given Thickness
Dim columnList As New ArrayList()
columnList.add("B")
columnList.add("C")
columnList.add("D")
columnList.add("E")
columnList.add("F")
columnList.add("G")
columnList.add("H")
columnList.add("I")
columnList.add("J")
columnList.add("K")
columnList.add("L")
columnList.add("M")
columnList.add("N")
columnList.add("O")
columnList.add("P")
columnList.add("Q")
columnList.add("R")
columnList.add("S")
columnList.add("T")
columnList.add("U")
columnList.add("V")
columnList.add("W")
columnList.add("X")
columnList.add("Y")
columnList.add("Z")
columnList.add("AA")
columnList.add("AB")
columnList.add("AC")
columnList.add("AD")
columnList.add("AE")
columnList.add("AF")
columnList.add("AG")
columnList.add("AH")
columnList.add("AI")
columnList.add("AJ")
columnList.add("AK")
columnList.add("AL")
columnList.add("AM")
columnList.add("AN")
columnList.add("AO")

Dim widthList As New ArrayList()

'open excel file that contains a list of stock sizes and try to match up width
Try
excelRow = GoExcel.FindRow("C:\Henshaw\Templates\Design Data\XLS\Stock Sizes.xlsx", "Sheet1", "Thickness", "=", thick)
GoExcel.Close

If excelRow > 0 Then
'parse thru the excel file and retreive a list of widths for the stock thickness
GoExcel.Open("C:\Henshaw\Templates\Design Data\XLS\Stock Sizes.xlsx", "Sheet1")
Dim index As Integer = 0
While GoExcel.CellValue(columnList(index) & CStr(excelRow))
widthList.add(GoExcel.CellValue(columnList(index) & CStr(excelRow)))
index = index + 1
End While
GoExcel.Close

'match width dimension with entry in widthList
If widthList.Contains(shortSide) Then
width = shortSide
cutLength = longSide
Else If widthList.Contains(longSide) Then
width = longSide
cutLength = shortSide
Else
width = shortSide
cutLength = longSide
End If
Else
width = shortSide
cutLength = longSide
End If
Catch
'if all else fails, assign shortest side to width and longest side to length
width = shortSide
cutLength = longSide
End Try

'format stock sizes for humans and write to Stock Number iProperty
'rounds, assumption: user has labeled largest OD of part as "diameter"
Try
roundDia = Parameter("diameter")

If EqualWithinTolerance(roundDia, Int(roundDia), .00001) Then
roundDiaText = Int(roundDia) & """ DIA."
ElseIf roundDia < 1 Then
roundDiaText = RoundToFraction(roundDia, 1/16, RoundingMethod.RoundUp) & """ DIA."
ElseIf roundDia > 1 And (roundDia - Int(roundDia)) > .9375 Then
roundDiaText = Round(roundDia) & """ DIA."
ElseIf roundDia > 1 Then
roundDiaText = Int(roundDia) & "-" & RoundToFraction((roundDia - Int(roundDia)), 1/16, RoundingMethod.RoundUp) & """ DIA."
End If

If EqualWithinTolerance(sideA, sideB, .06) Then
rCutLength = sideC
ElseIf EqualWithinTolerance(sideA, sideC, .06) Then
rCutLength = sideB
ElseIf EqualWithinTolerance(sideC, sideB, .06) Then
rCutLength = sideA
End If

If EqualWithinTolerance(rCutLength, Int(rCutLength), .00001) Then
rCutLengthText = Int(rCutLength) & """ LG."
ElseIf rCutLength < 1 Then
rCutLengthText = RoundToFraction(rCutLength, 1/16, RoundingMethod.RoundUp) & """ LG."
ElseIf rCutLength > 1 And (rCutLength - Int(rCutLength)) > .9375 Then
rCutLengthText = Round(rCutLength) & """ LG."
ElseIf rCutLength > 1 Then
rCutLengthText = Int(rCutLength) & "-" & RoundToFraction((rCutLength - Int(rCutLength)), 1/16, RoundingMethod.RoundUp) & """ LG."
End If

iProperties.Value("Project", "Stock Number") = roundDiaText & " x " & rCutLengthText

'write to iProperty to pass to ERP
iProperties.Value("Custom", "erpMaterial") = iProperties.Material & " " & roundDiaText

iProperties.Value("Custom", "cutLength") = CStr(rCutLength)
'cuboids
Catch
If IsNumeric(thick) Then
If EqualWithinTolerance(thick, Int(thick), .00001) Then
thickText = Int(thick) & """"
ElseIf thick < 1 Then
thickText = RoundToFraction(thick, 1/16, RoundingMethod.RoundUp) & """"
ElseIf thick > 1 And (thick - Int(thick)) > .9375 Then
thickText = Round(thick) & """"
ElseIf thick > 1 Then
thickText = Int(thick) & "-" & RoundToFraction((thick - Int(thick)), 1/16, RoundingMethod.RoundUp) & """"
End If
Else
thickText = thick
End If

If EqualWithinTolerance(width, Int(width), .00001) Then
widthText = Int(Width) & """"
ElseIf width < 1 Then
widthText = RoundToFraction(width, 1/16, RoundingMethod.RoundUp) & """"
ElseIf width > 1 And (width - Int(width)) > .9375 Then
widthText = Round(width) & """"
ElseIf width > 1 Then
widthText = Int(width) & "-" & RoundToFraction((width - Int(width)), 1/16, RoundingMethod.RoundUp) & """"
End If

If EqualWithinTolerance(cutLength, Int(cutLength), .00001) Then
cutLengthText = Int(cutLength) & """"
ElseIf cutLength < 1 Then
cutLengthText = RoundToFraction(cutLength, 1/16, RoundingMethod.RoundUp) & """"
ElseIf cutLength > 1 And (cutLength - Int(cutLength)) > .9375 Then
cutLengthText = Round(cutLength) & """"
ElseIf cutLength > 1 Then
cutLengthText = Int(cutLength) & "-" & RoundToFraction((cutLength - Int(cutLength)), 1/16, RoundingMethod.RoundUp) & """"
End If

iProperties.Value("Project", "Stock Number") = thickText & " x " & widthText & " x " & cutLengthText

'write to iProperty to pass to ERP
iProperties.Value("Custom", "erpMaterial") = iProperties.Material & " " & thickText & " x " & widthText

iProperties.Value("Custom", "cutLength") = CStr(cutLength)
End Try

End If

iProperties.Value("Custom", "templateVersion") = "2.0.1"
Else
End If

0 Likes
Message 3 of 9

bradeneuropeArthur
Mentor
Mentor
This code runs on save event?
is this I logic code?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 9

Anonymous
Not applicable

Yes to both.

0 Likes
Message 5 of 9

bradeneuropeArthur
Mentor
Mentor
could you please send a file with the related properties in it

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 9

Anonymous
Not applicable

Attached example ipt

0 Likes
Message 7 of 9

bradeneuropeArthur
Mentor
Mentor

I already found an issue

Keep reading>

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 9

bradeneuropeArthur
Mentor
Mentor
If ThisApplication.ActiveDocument.Dirty = True Then

'set purchase component iProperty to pass to ERP
Try
If purchasedComponent = True Then
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
iProperties.Value("Custom", "purchasedComponent") = "P"
Else 
purchasedComponent = False
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure iProperties.Value("Custom", "purchasedComponent") = "M" End If Catch End Try If ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then 'part is a purchased component and does not require a stock size 'Write To iProperties To pass To ERP iProperties.Value("Custom", "erpMaterial") = "" iProperties.Value("Custom", "cutLength") = "" Else 'part is a make component and does require a stock size 'get the physical extents of the model Try If SheetMetal.FlatExtentsLength > 0 Or SheetMetal.FlatExtentsWidth > 0 Then sideA = SheetMetal.FlatExtentsLength sideB = SheetMetal.FlatExtentsWidth sideC = Parameter("Thickness") Else sideA = Measure.ExtentsLength sideB = Measure.ExtentsWidth sideC = Measure.ExtentsHeight End If Catch sideA = Measure.ExtentsLength sideB = Measure.ExtentsWidth sideC = Measure.ExtentsHeight End Try 'change thickness verbage to a gage if thickness is a sheet metal gage. Note: ranges are used because the equal operator is not reliable If MinOfMany(sideA, sideB, sideC) > 0.1344 And MinOfMany(sideA, sideB, sideC) < 0.1346 And iProperties.Material = "1020 HRS" Then thick = "10 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.1195 And MinOfMany(sideA, sideB, sideC) < 0.1197 And iProperties.Material = "1020 HRS" Then thick = "11 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.1045 And MinOfMany(sideA, sideB, sideC) < 0.1047 And iProperties.Material = "1020 HRS" Then thick = "12 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0896 And MinOfMany(sideA, sideB, sideC) < 0.0898 And iProperties.Material = "1020 HRS" Then thick = "13 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0746 And MinOfMany(sideA, sideB, sideC) < 0.0748 And iProperties.Material = "1020 HRS" Then thick = "14 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0672 And MinOfMany(sideA, sideB, sideC) < 0.0674 And iProperties.Material = "1020 HRS" Then thick = "15 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0597 And MinOfMany(sideA, sideB, sideC) < 0.0599 And iProperties.Material = "1020 HRS" Then thick = "16 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.1405 And MinOfMany(sideA, sideB, sideC) < 0.1407 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then thick = "10 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.1249 And MinOfMany(sideA, sideB, sideC) < 0.1251 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then thick = "11 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.1093 And MinOfMany(sideA, sideB, sideC) < 0.1095 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then thick = "12 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0936 And MinOfMany(sideA, sideB, sideC) < 0.0938 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then thick = "13 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0780 And MinOfMany(sideA, sideB, sideC) < 0.0782 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then thick = "14 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0702 And MinOfMany(sideA, sideB, sideC) < 0.0704 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then thick = "15 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0624 And MinOfMany(sideA, sideB, sideC) < 0.0626 And (iProperties.Material = "304 SS" Or iProperties.Material = "310 SS" Or iProperties.Material = "316 SS" Or iProperties.Material = "321 SS") Then thick = "16 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.1018 And MinOfMany(sideA, sideB, sideC) < 0.1020 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then thick = "10 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0906 And MinOfMany(sideA, sideB, sideC) < 0.0908 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then thick = "11 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0807 And MinOfMany(sideA, sideB, sideC) < 0.0809 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then thick = "12 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0719 And MinOfMany(sideA, sideB, sideC) < 0.0721 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then thick = "13 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0640 And MinOfMany(sideA, sideB, sideC) < 0.0642 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then thick = "14 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0570 And MinOfMany(sideA, sideB, sideC) < 0.0572 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then thick = "15 GA." Else If MinOfMany(sideA, sideB, sideC) > 0.0507 And MinOfMany(sideA, sideB, sideC) < 0.0509 And (iProperties.Material = "6061 ALUM." Or iProperties.Material = "3003 ALUM.") Then thick = "16 GA." End If 'determine the order of dimensions of the part, smallest to largest Dim dimList As New ArrayList() If sideA = sideB And sideA = sideC Then dimList.Add(sideA) dimList.Add(sideB) dimList.Add(sideC) Else If sideA = sideB And sideA > sideC Then dimList.Add(sideC) dimList.Add(sideA) dimList.Add(sideB) Else If sideB = sideC And sideB > sideA Then dimList.Add(sideA) dimList.Add(sideB) dimList.Add(sideC) Else If sideC = sideA And sideC > sideB Then dimList.Add(sideB) dimList.Add(sideC) dimList.Add(sideA) Else If sideA = sideB And sideA < sideC Then dimList.Add(sideB) dimList.Add(sideA) dimList.Add(sideC) Else If sideB = sideC And sideB < sideA Then dimList.Add(sideC) dimList.Add(sideB) dimList.Add(sideA) Else If sideC = sideA And sideC < sideB Then dimList.Add(sideA) dimList.Add(sideC) dimList.Add(sideB) Else If sideA > sideB And sideB > sideC Then dimList.Add(sideC) dimList.Add(sideB) dimList.Add(sideA) Else If sideB > sideC And sideC > sideA Then dimList.Add(sideA) dimList.Add(sideC) dimList.Add(sideB) Else If sideC > sideA And sideA > sideB Then dimList.Add(sideB) dimList.Add(sideA) dimList.Add(sideC) Else If sideC > sideB And sideB > sideA Then dimList.Add(sideA) dimList.Add(sideB) dimList.Add(sideC) Else If sideA > sideC And sideC > sideB Then dimList.Add(sideB) dimList.Add(sideC) dimList.Add(sideA) Else If sideB > sideA And sideA > sideC Then dimList.Add(sideC) dimList.Add(sideA) dimList.Add(sideB) End If 'label dimensions If thick = "" Then thick = CDblAny(dimList(0)) End If shortSide = CDblAny(dimList(1)) longSide = CDblAny(dimList(2)) 'assumption: There are no more than 40 widths for any given Thickness Dim columnList As New ArrayList() columnList.Add("B") columnList.Add("C") columnList.Add("D") columnList.Add("E") columnList.Add("F") columnList.Add("G") columnList.Add("H") columnList.Add("I") columnList.Add("J") columnList.Add("K") columnList.Add("L") columnList.Add("M") columnList.Add("N") columnList.Add("O") columnList.Add("P") columnList.Add("Q") columnList.Add("R") columnList.Add("S") columnList.Add("T") columnList.Add("U") columnList.Add("V") columnList.Add("W") columnList.Add("X") columnList.Add("Y") columnList.Add("Z") columnList.Add("AA") columnList.Add("AB") columnList.Add("AC") columnList.Add("AD") columnList.Add("AE") columnList.Add("AF") columnList.Add("AG") columnList.Add("AH") columnList.Add("AI") columnList.Add("AJ") columnList.Add("AK") columnList.Add("AL") columnList.Add("AM") columnList.Add("AN") columnList.Add("AO") Dim widthList As New ArrayList() 'open excel file that contains a list of stock sizes and try to match up width Try excelRow = GoExcel.FindRow("C:\Henshaw\Templates\Design Data\XLS\Stock Sizes.xlsx", "Sheet1", "Thickness", "=", thick) GoExcel.Close If excelRow > 0 Then 'parse thru the excel file and retreive a list of widths for the stock thickness GoExcel.Open("C:\Henshaw\Templates\Design Data\XLS\Stock Sizes.xlsx", "Sheet1") Dim index As Integer = 0 While GoExcel.CellValue(columnList(index) & CStr(excelRow)) widthList.Add(GoExcel.CellValue(columnList(index) & CStr(excelRow))) index = index + 1 End While GoExcel.Close 'match width dimension with entry in widthList If widthList.Contains(shortSide) Then width = shortSide cutLength = longSide Else If widthList.Contains(longSide) Then width = longSide cutLength = shortSide Else width = shortSide cutLength = longSide End If Else width = shortSide cutLength = longSide End If Catch 'if all else fails, assign shortest side to width and longest side to length width = shortSide cutLength = longSide End Try 'format stock sizes for humans and write to Stock Number iProperty 'rounds, assumption: user has labeled largest OD of part as "diameter" Try roundDia = Parameter("diameter") If EqualWithinTolerance(roundDia, Int(roundDia), .00001) Then roundDiaText = Int(roundDia) & """ DIA." ElseIf roundDia < 1 Then roundDiaText = RoundToFraction(roundDia, 1/16, RoundingMethod.RoundUp) & """ DIA." ElseIf roundDia > 1 And (roundDia - Int(roundDia)) > .9375 Then roundDiaText = Round(roundDia) & """ DIA." ElseIf roundDia > 1 Then roundDiaText = Int(roundDia) & "-" & RoundToFraction((roundDia - Int(roundDia)), 1/16, RoundingMethod.RoundUp) & """ DIA." End If If EqualWithinTolerance(sideA, sideB, .06) Then rCutLength = sideC ElseIf EqualWithinTolerance(sideA, sideC, .06) Then rCutLength = sideB ElseIf EqualWithinTolerance(sideC, sideB, .06) Then rCutLength = sideA End If If EqualWithinTolerance(rCutLength, Int(rCutLength), .00001) Then rCutLengthText = Int(rCutLength) & """ LG." ElseIf rCutLength < 1 Then rCutLengthText = RoundToFraction(rCutLength, 1/16, RoundingMethod.RoundUp) & """ LG." ElseIf rCutLength > 1 And (rCutLength - Int(rCutLength)) > .9375 Then rCutLengthText = Round(rCutLength) & """ LG." ElseIf rCutLength > 1 Then rCutLengthText = Int(rCutLength) & "-" & RoundToFraction((rCutLength - Int(rCutLength)), 1/16, RoundingMethod.RoundUp) & """ LG." End If iProperties.Value("Project", "Stock Number") = roundDiaText & " x " & rCutLengthText 'write to iProperty to pass to ERP iProperties.Value("Custom", "erpMaterial") = iProperties.Material & " " & roundDiaText iProperties.Value("Custom", "cutLength") = CStr(rCutLength) 'cuboids Catch If IsNumeric(thick) Then If EqualWithinTolerance(thick, Int(thick), .00001) Then thickText = Int(thick) & """" ElseIf thick < 1 Then thickText = RoundToFraction(thick, 1/16, RoundingMethod.RoundUp) & """" ElseIf thick > 1 And (thick - Int(thick)) > .9375 Then thickText = Round(thick) & """" ElseIf thick > 1 Then thickText = Int(thick) & "-" & RoundToFraction((thick - Int(thick)), 1/16, RoundingMethod.RoundUp) & """" End If Else thickText = thick End If If EqualWithinTolerance(width, Int(width), .00001) Then widthText = Int(Width) & """" ElseIf width < 1 Then widthText = RoundToFraction(width, 1/16, RoundingMethod.RoundUp) & """" ElseIf width > 1 And (width - Int(width)) > .9375 Then widthText = Round(width) & """" ElseIf width > 1 Then widthText = Int(width) & "-" & RoundToFraction((width - Int(width)), 1/16, RoundingMethod.RoundUp) & """" End If If EqualWithinTolerance(cutLength, Int(cutLength), .00001) Then cutLengthText = Int(cutLength) & """" ElseIf cutLength < 1 Then cutLengthText = RoundToFraction(cutLength, 1/16, RoundingMethod.RoundUp) & """" ElseIf cutLength > 1 And (cutLength - Int(cutLength)) > .9375 Then cutLengthText = Round(cutLength) & """" ElseIf cutLength > 1 Then cutLengthText = Int(cutLength) & "-" & RoundToFraction((cutLength - Int(cutLength)), 1/16, RoundingMethod.RoundUp) & """" End If iProperties.Value("Project", "Stock Number") = thickText & " x " & widthText & " x " & cutLengthText 'write to iProperty to pass to ERP iProperties.Value("Custom", "erpMaterial") = iProperties.Material & " " & thickText & " x " & widthText iProperties.Value("Custom", "cutLength") = CStr(cutLength) End Try End If iProperties.Value("Custom", "templateVersion") = "2.0.1" Else End If

Read the first lines in red>>>>>>

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 9

bradeneuropeArthur
Mentor
Mentor

or this will also work

 

If purchasedComponent = True Then
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
iProperties.Value("Custom", "purchasedComponent") = "P"
Else If purchasedComponent = False
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
iProperties.Value("Custom", "purchasedComponent") = "M"
End If

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes