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