Searched the forums and I can't find an answer to this so I was wondering if it was possible to create a custom button for use on a form. Essentially what I have is a form that allows you to select a raw material however not all of our raw materials have purchased part numbers so the script looks like the below.
What I'm wondering is if I can create a custom button for use on the form that would make the call to the function instead of the line if partnumber = "" then call function
An alternative is the custom button could be tied to a second iLogic rule which fires off the email as well. Currently it's set up with a msgbox and the msgbox is kind of annoying so if there's a way to get rid of it that would be great, otherwise this will have to get rolled out to the group with the minor annoyance.
' Tons of script
if partnumber for material doesn't exist call function to create email
function:
msgbox with vbYesNo asking "do you want to create a request?"
if vbYes then ' push pre-defined email to outlook with material and size information
if vbNo then exit function
Searched the forums and I can't find an answer to this so I was wondering if it was possible to create a custom button for use on a form. Essentially what I have is a form that allows you to select a raw material however not all of our raw materials have purchased part numbers so the script looks like the below.
What I'm wondering is if I can create a custom button for use on the form that would make the call to the function instead of the line if partnumber = "" then call function
An alternative is the custom button could be tied to a second iLogic rule which fires off the email as well. Currently it's set up with a msgbox and the msgbox is kind of annoying so if there's a way to get rid of it that would be great, otherwise this will have to get rolled out to the group with the minor annoyance.
' Tons of script
if partnumber for material doesn't exist call function to create email
function:
msgbox with vbYesNo asking "do you want to create a request?"
if vbYes then ' push pre-defined email to outlook with material and size information
if vbNo then exit function
Hi @e_frissell
I would think this block of code would just go into your existing block as an error catch statement. Having the user click another button would be duplicating the action elsewhere and involves an extra step. A message box question is important to avoid running off emails without the user thinking or indeed forgetting to put in a material from available library. But if that isn't required then comment out or delete as required.
Hi @e_frissell
I would think this block of code would just go into your existing block as an error catch statement. Having the user click another button would be duplicating the action elsewhere and involves an extra step. A message box question is important to avoid running off emails without the user thinking or indeed forgetting to put in a material from available library. But if that isn't required then comment out or delete as required.
That's a good thought but all the sizes are pre-defined in multivalue list so an error never really exists. The dynamic multivalue lists are a blessing and a curse because prior to the if horizleg < x or horizleg > x the most common error would be from changing from a small size to a big size - i.e. .5" angle to 4" angle and the websize wouldn't exist for that size thus no partnumber exists (alternatively a try-catch error would have roughly the same effect here) and pop up the msgbox. The way it's coded now prevents 90% of that but would still prefer a button to run the email because it's easier than a msgbox popping up when you're in the middle of selecting the material.
Can't create that runs on update because every time the dynamic list would update the rule would run and it'd have the same functionality. Only way I can think of to maintain the dynamic list (i.e. not changing the buttons to a continue/apply) but prevent the msgbox from inadvertently popping up is a separate button
Else If verticalLeg = 8 Then
If horizLeg < 4 Or horizLeg > 8 Or horizLeg = 5 Then horizLeg = 4
If webWidth < .375 Or webWidth > 1 Then webWidth = .5
MultiValue.SetList("horizLeg", 4, 6, 8)
If horizLeg = 4 Then
MultiValue.SetList("webWidth", .375, .5, .625, .75, 1)
If webWidth = .375 Then epicMatMod = "0083"
If webWidth = .5 Then epicMatMod = "0039"
If webWidth = .625 Then epicMatMod = "0412"
If webWidth = .75 Then epicMatMod = ""
If webWidth = 1 Then epicMatMod = ""
Else If horizLeg = 6 Then
MultiValue.SetList("webWidth", .5, .625, .75, 1)
If webWidth = .5 Then epicMatMod = "0010"
If webWidth = .625 Then epicMatMod = ""
If webWidth = .75 Then epicMatMod = "0616"
If webWidth = 1 Then epicMatMod = "0019"
Else If horizLeg = 8 Then
MultiValue.SetList("webWidth", .5, .625, .75, 1)
If webWidth = .5 Then epicMatMod = "0750"
If webWidth = .625 Then epicMatMod = ""
If webWidth = .75 Then epicMatMod = "0752"
If webWidth = 1 Then epicMatMod = ""
End If
End If
End If
If partMaterial <> "HRS" Then
MsgBox("Not Available")
Exit Sub
End If
MultiValue.SetValueOptions(True, DefaultIndex := 0)
Vert_leg = verticalLeg
Web = webWidth
Horiz_leg = horizLeg
epicorNumber = epicMatNumber & epicMatMod
visDesc = verticalLeg & " X " & horizLeg & " X " & webWidth & " - " & epicMatType & " - " & partMaterial
epicorParamNumber = epicorNumber
iProperties.Value("Custom", "Visual Part Number") = epicorNumber
iProperties.Value("Custom", "Visual Description") = visDesc
If Length > .1 Then
extfeat.Suppressed = False
ThisDoc.Document.ObjectVisibility.Sketches = False
End If
If Len(epicorParamNumber) < 7 Then Call EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
End Sub
Function EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
alert1 = MsgBox("Epicor number for selected material does not exist, do you need this size?", vbYesNo, "Alert")
If alert1 = vbYes Then alert2 = MsgBox("Create request for material to be added to Epicor and template?", vbYesNo)
That's a good thought but all the sizes are pre-defined in multivalue list so an error never really exists. The dynamic multivalue lists are a blessing and a curse because prior to the if horizleg < x or horizleg > x the most common error would be from changing from a small size to a big size - i.e. .5" angle to 4" angle and the websize wouldn't exist for that size thus no partnumber exists (alternatively a try-catch error would have roughly the same effect here) and pop up the msgbox. The way it's coded now prevents 90% of that but would still prefer a button to run the email because it's easier than a msgbox popping up when you're in the middle of selecting the material.
Can't create that runs on update because every time the dynamic list would update the rule would run and it'd have the same functionality. Only way I can think of to maintain the dynamic list (i.e. not changing the buttons to a continue/apply) but prevent the msgbox from inadvertently popping up is a separate button
Else If verticalLeg = 8 Then
If horizLeg < 4 Or horizLeg > 8 Or horizLeg = 5 Then horizLeg = 4
If webWidth < .375 Or webWidth > 1 Then webWidth = .5
MultiValue.SetList("horizLeg", 4, 6, 8)
If horizLeg = 4 Then
MultiValue.SetList("webWidth", .375, .5, .625, .75, 1)
If webWidth = .375 Then epicMatMod = "0083"
If webWidth = .5 Then epicMatMod = "0039"
If webWidth = .625 Then epicMatMod = "0412"
If webWidth = .75 Then epicMatMod = ""
If webWidth = 1 Then epicMatMod = ""
Else If horizLeg = 6 Then
MultiValue.SetList("webWidth", .5, .625, .75, 1)
If webWidth = .5 Then epicMatMod = "0010"
If webWidth = .625 Then epicMatMod = ""
If webWidth = .75 Then epicMatMod = "0616"
If webWidth = 1 Then epicMatMod = "0019"
Else If horizLeg = 8 Then
MultiValue.SetList("webWidth", .5, .625, .75, 1)
If webWidth = .5 Then epicMatMod = "0750"
If webWidth = .625 Then epicMatMod = ""
If webWidth = .75 Then epicMatMod = "0752"
If webWidth = 1 Then epicMatMod = ""
End If
End If
End If
If partMaterial <> "HRS" Then
MsgBox("Not Available")
Exit Sub
End If
MultiValue.SetValueOptions(True, DefaultIndex := 0)
Vert_leg = verticalLeg
Web = webWidth
Horiz_leg = horizLeg
epicorNumber = epicMatNumber & epicMatMod
visDesc = verticalLeg & " X " & horizLeg & " X " & webWidth & " - " & epicMatType & " - " & partMaterial
epicorParamNumber = epicorNumber
iProperties.Value("Custom", "Visual Part Number") = epicorNumber
iProperties.Value("Custom", "Visual Description") = visDesc
If Length > .1 Then
extfeat.Suppressed = False
ThisDoc.Document.ObjectVisibility.Sketches = False
End If
If Len(epicorParamNumber) < 7 Then Call EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
End Sub
Function EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
alert1 = MsgBox("Epicor number for selected material does not exist, do you need this size?", vbYesNo, "Alert")
If alert1 = vbYes Then alert2 = MsgBox("Create request for material to be added to Epicor and template?", vbYesNo)
You could move the message box to the end of the code and just have a filter statement down there. If you really want a button just place an external rule into the local/global form and use this as the button to send your email.
Without seeing all the workflow it is hard to offer any assistance. Can you screen shot the form your using?
You could move the message box to the end of the code and just have a filter statement down there. If you really want a button just place an external rule into the local/global form and use this as the button to send your email.
Without seeing all the workflow it is hard to offer any assistance. Can you screen shot the form your using?
@A.Acheson thanks, here's a screenshot of the form but I can't screenshot the code since it's about 400 lines of the same thing repeating over and over. As you can see the form is the basic layout but it has the dynamic multivalue.setlist - i.e. when you change the size from C3 to CX the list changes which is the flow I'm looking for, as opposed to having ALL the channel sizes in one list. What happens though is that when you change variable "Size" from one value to another the "Weight" doesn't update to one of the values on the list until the dropdown is selected.
Here's the form
Here's what happens when you change C3 to a different number
There is no C10x4.1 channel, thus the purchase part number doesn't exist, thus the prompt to send the email pops up.
What I'd like is the form to have a second button called "Material Request" that calls a function within the rule to create the email. This would prevent the email prompt from popping up
On the other hand now that I typed all that out I just realized why you recommended a second rule - the second rule would run after the first one is complete. Does the problem make sense? Not sure if I explained it well enough... Alternatively would it be possible to have that rule run when the form is closed, but prior to the part being saved? Wouldn't want a slightly different variation of the same problem as the prompt for the email is
if len(RawMaterialNumber) < 7 then call function RequestMaterial
@A.Acheson thanks, here's a screenshot of the form but I can't screenshot the code since it's about 400 lines of the same thing repeating over and over. As you can see the form is the basic layout but it has the dynamic multivalue.setlist - i.e. when you change the size from C3 to CX the list changes which is the flow I'm looking for, as opposed to having ALL the channel sizes in one list. What happens though is that when you change variable "Size" from one value to another the "Weight" doesn't update to one of the values on the list until the dropdown is selected.
Here's the form
Here's what happens when you change C3 to a different number
There is no C10x4.1 channel, thus the purchase part number doesn't exist, thus the prompt to send the email pops up.
What I'd like is the form to have a second button called "Material Request" that calls a function within the rule to create the email. This would prevent the email prompt from popping up
On the other hand now that I typed all that out I just realized why you recommended a second rule - the second rule would run after the first one is complete. Does the problem make sense? Not sure if I explained it well enough... Alternatively would it be possible to have that rule run when the form is closed, but prior to the part being saved? Wouldn't want a slightly different variation of the same problem as the prompt for the email is
if len(RawMaterialNumber) < 7 then call function RequestMaterial
Hi @e_frissell
To have the code run only once a method is to change the style of the form action button to Apply so you can select all the variables hit apply and then the code runs. If possible paste in the code to see what worflow the code is running. Otherwise it can be difficult to replicate what your seeing.
Hi @e_frissell
To have the code run only once a method is to change the style of the form action button to Apply so you can select all the variables hit apply and then the code runs. If possible paste in the code to see what worflow the code is running. Otherwise it can be difficult to replicate what your seeing.
That was one of the things I tried and found that it had the exact same issue except you had to hit apply for every change. Like, the form defaults to C3x4.1 channel. Hit the dropdown, select C5 channel but weight still shows the dropdown for C3 and 4.1 is selected. Hit apply, list updates to C5 weight sizes (however 4.1 is still the active size). No part record exists for C5x4.1 so msgbox opens.
It's kind of hard to explain without watching it but... notice how the form starts off with C3x4.1, when you can change the channel size to C5 the weight is still set to 4.1 and because there's no C5x4.1 it throws the material doesn't exist msgbox. The way to fix this is to make the weight default to the first value if the weight for C3 doesn't equal 4.1, 5 or 6...except that's a lot of coding. The next best alternative would be
If Size = C3 then
If Weight < 4.1 or Weight > 6 then Weight = 4.1
Except other channel sizes have weights in between 4.1 and 6 so the frequency of the error is reduced but it's not really solved since something like C3x5.4 would trigger the alert (5.4 is a weight for C4).
I sort of solved it for angle iron but the amount of coding was frustrating and it doesn't work with C-Channel
Else If verticalLeg = 2.5 Then
If horizLeg < 1.5 Or horizLeg > 2.5 Or horizLeg = 1.75 Or horizLeg = 2.25 Then horizLeg = 1.5
If webWidth < .125 Or webWidth > .5 Then webWidth = .1875
MultiValue.SetList("horizLeg", 1.5,2,2.5)
The entire code is here. It's long
Public Sub Main()
Dim materialOption1 As String
Dim materialOption2 As String
Dim subOpt1 As Double
Dim subOpt2 As Double
Dim subOpt3 As Double
Dim subOpt4 As Double
Dim curPart As Inventor.PartDocument = ThisDoc.Document
Dim epicorNumber As String
Dim extfeat = Feature.InventorFeature("Extrusion1")
Dim epicMatMod As String
Dim visDesc As String
Dim partMaterial As String
Dim epicMatNumber As String = "351-0"
Dim epicMatType As String = "Channel"
oLibraryName = "Autodesk Material Library"
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item(oLibraryName)
extfeat.Suppressed = True
ThisDoc.Document.ObjectVisibility.Sketches = True
MultiValue.UpdateAfterChange = True
materialOption1 = "ASTM A36"
materialOption2 = "Aluminum"
MultiValue.SetList("channelMaterial", materialOption1, materialOption2)
If channelMaterial = materialOption1 Then
'oLibraryName = "Autodesk Material Library"
'Dim assetLib As AssetLibrary
'assetLib = ThisApplication.AssetLibraries.Item(oLibraryName)
ThisApplication.ActiveMaterialLibrary = assetLib
iProperties.Material = "Steel ASTM A36"
MultiValue.SetList("channelSize", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C12", "C15")
If channelSize = "C3" Then
Grip = .273
Dim_d = 3
subOpt1 = 4.1
subOpt2 = 5
subOpt3 = 6
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 1.41
Dim_tw = .17
Else If chanWeight = subOpt2 Then
Dim_bf = 1.498
Dim_tw = .258
Else If chanWeight = subOpt3 Then
Dim_bf = 1.596
Dim_tw = .356
End If
Else If channelSize = "C4" Then
Grip = 0.296
Dim_d = 4
subOpt1 = 5.4
subOpt2 = 7.25
MultiValue.SetList("chanWeight", subOpt1, subOpt2)
If chanWeight = subOpt1 Then
Dim_bf = 1.584
Dim_tw = .184
Else If chanWeight = subOpt2 Then
Dim_bf = 1.721
Dim_tw = 0.321
End If
Else If channelSize = "C5" Then
Dim_d = 5
Grip = 0.32
subOpt1 = 6.7
subOpt2 = 9
MultiValue.SetList("chanWeight", subOpt1, subOpt2)
If chanWeight = subOpt1 Then
Dim_bf = 1.75
Dim_tw = 0.19
Else If chanWeight = subOpt2 Then
Dim_bf = 1.885
Dim_tw = 0.325
End If
Else If channelSize = "C6" Then
Dim_d = 6
Grip = 0.343
subOpt1 = 8.2
subOpt2 = 10.5
subOpt3 = 13
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 1.92
Dim_tw = 0.2
Else If chanWeight = subOpt2 Then
Dim_bf = 2.034
Dim_tw = 0.314
Else If chanWeight = subOpt3 Then
Dim_bf = 2.157
Dim_tw = 0.437
End If
Else If channelSize = "C7" Then
Dim_d = 7
Grip = 0.366
subOpt1 = 9.8
subOpt2 = 12.25
subOpt3 = 14.75
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.09
Dim_tw = 0.21
Else If chanWeight = subOpt2 Then
Dim_bf = 2.194
Dim_tw = 0.314
Else If chanWeight = subOpt3 Then
Dim_bf = 2.299
Dim_tw = 0.419
End If
Else If channelSize = "C8" Then
Dim_d = 8
Grip = 0.39
subOpt1 = 11.5
subOpt2 = 13.75
subOpt3 = 18.75
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.26
Dim_tw = 0.22
Else If chanWeight = subOpt2 Then
Dim_bf = 2.343
Dim_tw = 0.303
Else If chanWeight = subOpt3 Then
Dim_bf = 2.527
Dim_tw = 0.487
End If
Else If channelSize = "C9" Then
Dim_d = 9
Grip = 0.413
subOpt1 = 13.4
subOpt2 = 15
subOpt3 = 20
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.433
Dim_tw = 0.233
Else If chanWeight = subOpt2 Then
Dim_bf = 2.485
Dim_tw = 0.285
Else If chanWeight = subOpt3 Then
Dim_bf = 2.648
Dim_tw = 0.448
End If
Else If channelSize = "C10" Then
Dim_d = 10
Grip = 0.436
subOpt1 = 15.3
subOpt2 = 20
subOpt3 = 25
subOpt4 = 30
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3, subOpt4)
If chanWeight = subOpt1 Then
Dim_bf = 2.6
Dim_tw = 0.24
Else If chanWeight = subOpt2 Then
Dim_bf = 2.739
Dim_tw = 0.379
Else If chanWeight = subOpt3 Then
Dim_bf = 2.886
Dim_tw = 0.526
Else If chanWeight = subOpt4 Then
Dim_bf = 3.033
Dim_tw = 0.673
End If
Else If channelSize = "C12" Then
Dim_d = 12
Grip = 0.501
subOpt1 = 20.7
subOpt2 = 25
subOpt3 = 30
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.942
Dim_tw = 0.282
Else If chanWeight = subOpt2 Then
Dim_bf = 3.047
Dim_tw = 0.387
Else If chanWeight = subOpt3 Then
Dim_bf = 3.17
Dim_tw = 0.51
End If
Else If channelSize = "C15" Then
Dim_d = 15
Grip = 0.65
subOpt1 = 33.9
subOpt2 = 40
subOpt3 = 50
MultiValue.SetList(chanWeight, subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 3.4
Dim_tw = 0.4
Else If chanWeight = subOpt2 Then
Dim_bf = 3.52
Dim_tw = 0.52
Else If chanWeight = subOpt3 Then
Dim_bf = 3.716
Dim_tw = 0.716
End If
End If
End If
MultiValue.SetValueOptions(True, DefaultIndex := 0)
epicMatMod = ""
If channelSize = "C12" And chanWeight = 25 Then epicMatMod = "0075"
If channelSize = "C10" And chanWeight = 30 Then epicMatMod = "0074"
If channelSize = "C10" And chanWeight = 25 Then epicMatMod = "0073"
If channelSize = "C10" And chanWeight = 20 Then epicMatMod = "0072"
If channelSize = "C10" And chanWeight = 15.3 Then epicMatMod = "0070"
If channelSize = "C9" And chanWeight = 20 Then epicMatMod = "0069"
If channelSize = "C9" And chanWeight = 15 Then epicMatMod = "0068"
If channelSize = "C9" And chanWeight = 13.4 Then epicMatMod = "0067"
If channelSize = "C8" And chanWeight = 18.75 Then epicMatMod = "0066"
If channelSize = "C8" And chanWeight = 13.75 Then epicMatMod = "0065"
If channelSize = "C8" And chanWeight = 11.5 Then epicMatMod = "0064"
If channelSize = "C7" And chanWeight = 14.75 Then epicMatMod = "0058"
If channelSize = "C7" And chanWeight = 12.25 Then epicMatMod = "0063"
If channelSize = "C7" And chanWeight = 9.8 Then epicMatMod = "0062"
If channelSize = "C6" And chanWeight = 13 Then epicMatMod = "0055"
If channelSize = "C6" And chanWeight = 10.5 Then epicMatMod = "0057"
If channelSize = "C6" And chanWeight = 8.2 Then epicMatMod = "0079"
If channelSize = "C5" And chanWeight = 9 Then epicMatMod = "0050"
If channelSize = "C5" And chanWeight = 6.7 Then epicMatMod = "0054"
If channelSize = "C4" And chanWeight = .25 Then epicMatMod = "0053"
If channelSize = "C4" And chanWeight = 6.25 Then epicMatMod = "0052"
If channelSize = "C4" And chanWeight = 5.4 Then epicMatMod = "0051"
If channelSize = "C3" And chanWeight = 6 Then epicMatMod = "0049"
If channelSize = "C3" And chanWeight = 5 Then epicMatMod = "0047"
If channelSize = "C3" And chanWeight = 4.1 Then epicMatMod = "0046"
epicorNumber = epicMatNumber & epicMatMod
epicorParamNumber = epicorNumber
If channelMaterial = materialOption1 Then
visDesc = epicMatType & " - " & channelSize & "x" & chanWeight & " " & " - " & materialOption1
End If
iProperties.Value("Custom", "Visual Part Number") = epicorNumber
iProperties.Value("Custom", "Visual Description") = visDesc
If Length > .1 Then
extfeat.Suppressed = False
ThisDoc.Document.ObjectVisibility.Sketches = False
If Len(epicorParamNumber) < 7 Then Call EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
End If
End Sub
Function EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
alert1 = MsgBox("Epicor number for selected material does not exist, do you need this size?", vbYesNo, "Alert")
If alert1 = vbYes Then alert2 = MsgBox("Create request for material to be added to Epicor and template?", vbYesNo)
If alert2 = vbYes Then
Try
oOApp = CreateObject("Outlook.Application")
oOMail = oOApp.CreateItem(0)
Catch
MessageBox.Show("Error in request. Please email the request to e.frissell@linkeng.com", "Failed Error")
Exit Function
End Try
strbody = "<p style='font-family:calibri;font-size:16'>" & _
"This is an automated request for " & visDesc
'"This is an automated request for " & partMaterial & " " & epicMatType & " with vertical leg " & verticalLeg & ", horizontal leg " & horizLeg & ", and web width " & webWidth & vbCrLf
strbody += "<br /><br />"
strbody += "Epicor Identifier - " & epicorNumber & vbCrLf
strbody += "<br /><br />"
strbody += "Visual Description - " & visDesc
With oOMail
.bodyformat = 2
.To = "plzdon'temailme"
.CC = ""
.BCC = ""
.Subject = "Epicor Material Request " & partMaterial & " - " & epicMatType
.Display 'Toggle this for a Signature on/off
End With
With oOMail
'
.HTMLbody = strbody & vbNewLine & .HTMLBody ' add the signature without losing the HTML-formatting of the signature
'.Attachments.Add (FilePath & "\" & StockNum & ".jpg")
'.Display 'Toggle ON to show the Email Window
End With
End If
If alert1 = vbNo Or alert2 = vbNo Then Exit Function
End Function
There was also code that said if weight <> subOpt1 or weight <> subOpt2 or weight <> subOpt3 then weight = subOpt1 except that code didn't work, I think, due to conversion errors. Couldn't get a double for equals to work and basically gave up on it. Last ditch effort to prevent the box from popping up needlessly was to hide it in the if length > .1 statement
That was one of the things I tried and found that it had the exact same issue except you had to hit apply for every change. Like, the form defaults to C3x4.1 channel. Hit the dropdown, select C5 channel but weight still shows the dropdown for C3 and 4.1 is selected. Hit apply, list updates to C5 weight sizes (however 4.1 is still the active size). No part record exists for C5x4.1 so msgbox opens.
It's kind of hard to explain without watching it but... notice how the form starts off with C3x4.1, when you can change the channel size to C5 the weight is still set to 4.1 and because there's no C5x4.1 it throws the material doesn't exist msgbox. The way to fix this is to make the weight default to the first value if the weight for C3 doesn't equal 4.1, 5 or 6...except that's a lot of coding. The next best alternative would be
If Size = C3 then
If Weight < 4.1 or Weight > 6 then Weight = 4.1
Except other channel sizes have weights in between 4.1 and 6 so the frequency of the error is reduced but it's not really solved since something like C3x5.4 would trigger the alert (5.4 is a weight for C4).
I sort of solved it for angle iron but the amount of coding was frustrating and it doesn't work with C-Channel
Else If verticalLeg = 2.5 Then
If horizLeg < 1.5 Or horizLeg > 2.5 Or horizLeg = 1.75 Or horizLeg = 2.25 Then horizLeg = 1.5
If webWidth < .125 Or webWidth > .5 Then webWidth = .1875
MultiValue.SetList("horizLeg", 1.5,2,2.5)
The entire code is here. It's long
Public Sub Main()
Dim materialOption1 As String
Dim materialOption2 As String
Dim subOpt1 As Double
Dim subOpt2 As Double
Dim subOpt3 As Double
Dim subOpt4 As Double
Dim curPart As Inventor.PartDocument = ThisDoc.Document
Dim epicorNumber As String
Dim extfeat = Feature.InventorFeature("Extrusion1")
Dim epicMatMod As String
Dim visDesc As String
Dim partMaterial As String
Dim epicMatNumber As String = "351-0"
Dim epicMatType As String = "Channel"
oLibraryName = "Autodesk Material Library"
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item(oLibraryName)
extfeat.Suppressed = True
ThisDoc.Document.ObjectVisibility.Sketches = True
MultiValue.UpdateAfterChange = True
materialOption1 = "ASTM A36"
materialOption2 = "Aluminum"
MultiValue.SetList("channelMaterial", materialOption1, materialOption2)
If channelMaterial = materialOption1 Then
'oLibraryName = "Autodesk Material Library"
'Dim assetLib As AssetLibrary
'assetLib = ThisApplication.AssetLibraries.Item(oLibraryName)
ThisApplication.ActiveMaterialLibrary = assetLib
iProperties.Material = "Steel ASTM A36"
MultiValue.SetList("channelSize", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C12", "C15")
If channelSize = "C3" Then
Grip = .273
Dim_d = 3
subOpt1 = 4.1
subOpt2 = 5
subOpt3 = 6
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 1.41
Dim_tw = .17
Else If chanWeight = subOpt2 Then
Dim_bf = 1.498
Dim_tw = .258
Else If chanWeight = subOpt3 Then
Dim_bf = 1.596
Dim_tw = .356
End If
Else If channelSize = "C4" Then
Grip = 0.296
Dim_d = 4
subOpt1 = 5.4
subOpt2 = 7.25
MultiValue.SetList("chanWeight", subOpt1, subOpt2)
If chanWeight = subOpt1 Then
Dim_bf = 1.584
Dim_tw = .184
Else If chanWeight = subOpt2 Then
Dim_bf = 1.721
Dim_tw = 0.321
End If
Else If channelSize = "C5" Then
Dim_d = 5
Grip = 0.32
subOpt1 = 6.7
subOpt2 = 9
MultiValue.SetList("chanWeight", subOpt1, subOpt2)
If chanWeight = subOpt1 Then
Dim_bf = 1.75
Dim_tw = 0.19
Else If chanWeight = subOpt2 Then
Dim_bf = 1.885
Dim_tw = 0.325
End If
Else If channelSize = "C6" Then
Dim_d = 6
Grip = 0.343
subOpt1 = 8.2
subOpt2 = 10.5
subOpt3 = 13
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 1.92
Dim_tw = 0.2
Else If chanWeight = subOpt2 Then
Dim_bf = 2.034
Dim_tw = 0.314
Else If chanWeight = subOpt3 Then
Dim_bf = 2.157
Dim_tw = 0.437
End If
Else If channelSize = "C7" Then
Dim_d = 7
Grip = 0.366
subOpt1 = 9.8
subOpt2 = 12.25
subOpt3 = 14.75
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.09
Dim_tw = 0.21
Else If chanWeight = subOpt2 Then
Dim_bf = 2.194
Dim_tw = 0.314
Else If chanWeight = subOpt3 Then
Dim_bf = 2.299
Dim_tw = 0.419
End If
Else If channelSize = "C8" Then
Dim_d = 8
Grip = 0.39
subOpt1 = 11.5
subOpt2 = 13.75
subOpt3 = 18.75
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.26
Dim_tw = 0.22
Else If chanWeight = subOpt2 Then
Dim_bf = 2.343
Dim_tw = 0.303
Else If chanWeight = subOpt3 Then
Dim_bf = 2.527
Dim_tw = 0.487
End If
Else If channelSize = "C9" Then
Dim_d = 9
Grip = 0.413
subOpt1 = 13.4
subOpt2 = 15
subOpt3 = 20
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.433
Dim_tw = 0.233
Else If chanWeight = subOpt2 Then
Dim_bf = 2.485
Dim_tw = 0.285
Else If chanWeight = subOpt3 Then
Dim_bf = 2.648
Dim_tw = 0.448
End If
Else If channelSize = "C10" Then
Dim_d = 10
Grip = 0.436
subOpt1 = 15.3
subOpt2 = 20
subOpt3 = 25
subOpt4 = 30
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3, subOpt4)
If chanWeight = subOpt1 Then
Dim_bf = 2.6
Dim_tw = 0.24
Else If chanWeight = subOpt2 Then
Dim_bf = 2.739
Dim_tw = 0.379
Else If chanWeight = subOpt3 Then
Dim_bf = 2.886
Dim_tw = 0.526
Else If chanWeight = subOpt4 Then
Dim_bf = 3.033
Dim_tw = 0.673
End If
Else If channelSize = "C12" Then
Dim_d = 12
Grip = 0.501
subOpt1 = 20.7
subOpt2 = 25
subOpt3 = 30
MultiValue.SetList("chanWeight", subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 2.942
Dim_tw = 0.282
Else If chanWeight = subOpt2 Then
Dim_bf = 3.047
Dim_tw = 0.387
Else If chanWeight = subOpt3 Then
Dim_bf = 3.17
Dim_tw = 0.51
End If
Else If channelSize = "C15" Then
Dim_d = 15
Grip = 0.65
subOpt1 = 33.9
subOpt2 = 40
subOpt3 = 50
MultiValue.SetList(chanWeight, subOpt1, subOpt2, subOpt3)
If chanWeight = subOpt1 Then
Dim_bf = 3.4
Dim_tw = 0.4
Else If chanWeight = subOpt2 Then
Dim_bf = 3.52
Dim_tw = 0.52
Else If chanWeight = subOpt3 Then
Dim_bf = 3.716
Dim_tw = 0.716
End If
End If
End If
MultiValue.SetValueOptions(True, DefaultIndex := 0)
epicMatMod = ""
If channelSize = "C12" And chanWeight = 25 Then epicMatMod = "0075"
If channelSize = "C10" And chanWeight = 30 Then epicMatMod = "0074"
If channelSize = "C10" And chanWeight = 25 Then epicMatMod = "0073"
If channelSize = "C10" And chanWeight = 20 Then epicMatMod = "0072"
If channelSize = "C10" And chanWeight = 15.3 Then epicMatMod = "0070"
If channelSize = "C9" And chanWeight = 20 Then epicMatMod = "0069"
If channelSize = "C9" And chanWeight = 15 Then epicMatMod = "0068"
If channelSize = "C9" And chanWeight = 13.4 Then epicMatMod = "0067"
If channelSize = "C8" And chanWeight = 18.75 Then epicMatMod = "0066"
If channelSize = "C8" And chanWeight = 13.75 Then epicMatMod = "0065"
If channelSize = "C8" And chanWeight = 11.5 Then epicMatMod = "0064"
If channelSize = "C7" And chanWeight = 14.75 Then epicMatMod = "0058"
If channelSize = "C7" And chanWeight = 12.25 Then epicMatMod = "0063"
If channelSize = "C7" And chanWeight = 9.8 Then epicMatMod = "0062"
If channelSize = "C6" And chanWeight = 13 Then epicMatMod = "0055"
If channelSize = "C6" And chanWeight = 10.5 Then epicMatMod = "0057"
If channelSize = "C6" And chanWeight = 8.2 Then epicMatMod = "0079"
If channelSize = "C5" And chanWeight = 9 Then epicMatMod = "0050"
If channelSize = "C5" And chanWeight = 6.7 Then epicMatMod = "0054"
If channelSize = "C4" And chanWeight = .25 Then epicMatMod = "0053"
If channelSize = "C4" And chanWeight = 6.25 Then epicMatMod = "0052"
If channelSize = "C4" And chanWeight = 5.4 Then epicMatMod = "0051"
If channelSize = "C3" And chanWeight = 6 Then epicMatMod = "0049"
If channelSize = "C3" And chanWeight = 5 Then epicMatMod = "0047"
If channelSize = "C3" And chanWeight = 4.1 Then epicMatMod = "0046"
epicorNumber = epicMatNumber & epicMatMod
epicorParamNumber = epicorNumber
If channelMaterial = materialOption1 Then
visDesc = epicMatType & " - " & channelSize & "x" & chanWeight & " " & " - " & materialOption1
End If
iProperties.Value("Custom", "Visual Part Number") = epicorNumber
iProperties.Value("Custom", "Visual Description") = visDesc
If Length > .1 Then
extfeat.Suppressed = False
ThisDoc.Document.ObjectVisibility.Sketches = False
If Len(epicorParamNumber) < 7 Then Call EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
End If
End Sub
Function EpicAlert(verticalLeg, horizLeg, webWidth, epicMatType, partMaterial, epicorNumber, visDesc)
alert1 = MsgBox("Epicor number for selected material does not exist, do you need this size?", vbYesNo, "Alert")
If alert1 = vbYes Then alert2 = MsgBox("Create request for material to be added to Epicor and template?", vbYesNo)
If alert2 = vbYes Then
Try
oOApp = CreateObject("Outlook.Application")
oOMail = oOApp.CreateItem(0)
Catch
MessageBox.Show("Error in request. Please email the request to e.frissell@linkeng.com", "Failed Error")
Exit Function
End Try
strbody = "<p style='font-family:calibri;font-size:16'>" & _
"This is an automated request for " & visDesc
'"This is an automated request for " & partMaterial & " " & epicMatType & " with vertical leg " & verticalLeg & ", horizontal leg " & horizLeg & ", and web width " & webWidth & vbCrLf
strbody += "<br /><br />"
strbody += "Epicor Identifier - " & epicorNumber & vbCrLf
strbody += "<br /><br />"
strbody += "Visual Description - " & visDesc
With oOMail
.bodyformat = 2
.To = "plzdon'temailme"
.CC = ""
.BCC = ""
.Subject = "Epicor Material Request " & partMaterial & " - " & epicMatType
.Display 'Toggle this for a Signature on/off
End With
With oOMail
'
.HTMLbody = strbody & vbNewLine & .HTMLBody ' add the signature without losing the HTML-formatting of the signature
'.Attachments.Add (FilePath & "\" & StockNum & ".jpg")
'.Display 'Toggle ON to show the Email Window
End With
End If
If alert1 = vbNo Or alert2 = vbNo Then Exit Function
End Function
There was also code that said if weight <> subOpt1 or weight <> subOpt2 or weight <> subOpt3 then weight = subOpt1 except that code didn't work, I think, due to conversion errors. Couldn't get a double for equals to work and basically gave up on it. Last ditch effort to prevent the box from popping up needlessly was to hide it in the if length > .1 statement
I haven't really had a chance to dive into the code but just from observation. There is a ilogic function available for parameter("ParameterName") which allows for more targeting of when the parameter changes, updating while the code is running or at the end etc. This differs from the blue local parameter "ParameterName", where any change in the parameter triggers the rule so if you have multiple parameter changes in the form then it will trigger each and every time a parameter is change. Maybe you can see if that helps you out. For the weight parameter I would think that should be displayed as read only and not a list box type as the user doesn't select that correct? That will eliminate one source of error.
I haven't really had a chance to dive into the code but just from observation. There is a ilogic function available for parameter("ParameterName") which allows for more targeting of when the parameter changes, updating while the code is running or at the end etc. This differs from the blue local parameter "ParameterName", where any change in the parameter triggers the rule so if you have multiple parameter changes in the form then it will trigger each and every time a parameter is change. Maybe you can see if that helps you out. For the weight parameter I would think that should be displayed as read only and not a list box type as the user doesn't select that correct? That will eliminate one source of error.
Thanks! I wasn't aware of the parameter("ParameterName") option, I'll see if that can work but I think I'll have to live with the functionality the way it is right now. Currently if the extrusion command is suppressed (i.e. length is < =.1) then the alert is disabled which won't prevent the pop-up all the time but it'll prevent it a majority of the time when initially creating the part. For C-channel the weight is required as that's how steel C-channel is sized. Which is different than aluminum C-channel that is sized based on the width and the flange height... Fun stuff
Thanks! I wasn't aware of the parameter("ParameterName") option, I'll see if that can work but I think I'll have to live with the functionality the way it is right now. Currently if the extrusion command is suppressed (i.e. length is < =.1) then the alert is disabled which won't prevent the pop-up all the time but it'll prevent it a majority of the time when initially creating the part. For C-channel the weight is required as that's how steel C-channel is sized. Which is different than aluminum C-channel that is sized based on the width and the flange height... Fun stuff
Can't find what you're looking for? Ask the community or share your knowledge.