Check Parameter Value before If statement - External iLogic Rule

Check Parameter Value before If statement - External iLogic Rule

Jack.Swindells
Explorer Explorer
372 Views
4 Replies
Message 1 of 5

Check Parameter Value before If statement - External iLogic Rule

Jack.Swindells
Explorer
Explorer

I'm trying to create a simple rule that will update a standard tolerances box on a drawing depending on the selection of FINE, MEDIUM, COARSE, VERY COARSE.

 

This works fine until I changed it to an external rule to keep it with all our other iLogic rules. The default value is set to " " and this is supposed to trigger a form on opening or saving the drawing until it is changed to one of the other options. If I open the form manually and change the parameter it works fine. I feel like it needs  to check the parameter before the if statement but not sure how this would normally be done? Is there a better way to do this?

 

If TolSelect = " " Then
	iLogicForm.Show("Machining Tolerance Selection", FormMode.Modal)
	iProperties.Value("Custom", "Tol1") = "XX"
	iProperties.Value("Custom", "Tol2") = "XX"
	iProperties.Value("Custom", "Tol3") = "XX"
	iProperties.Value("Custom", "Tol4") = "XX"
	iProperties.Value("Custom", "Tol5") = "XX"
	iProperties.Value("Custom", "Tol6") = "XX"
	iProperties.Value("Custom", "Tol7") = "XX"
	iProperties.Value("Custom", "Tol8") = "XX"
	iProperties.Value("Custom", "TolSelect") = "SELECT TOLERANCE"

ElseIf TolSelect = "4. VERY COARSE" Then
	iProperties.Value("Custom", "Tol1") = "-"
	iProperties.Value("Custom", "Tol2") = 0.5
	iProperties.Value("Custom", "Tol3") = 1
	iProperties.Value("Custom", "Tol4") = 1.5
	iProperties.Value("Custom", "Tol5") = 2.5
	iProperties.Value("Custom", "Tol6") = 4
	iProperties.Value("Custom", "Tol7") = 6
	iProperties.Value("Custom", "Tol8") = 8
	iProperties.Value("Custom", "TolSelect") = "VERY COARSE"
	
ElseIf TolSelect = "3. COARSE" Then
	iProperties.Value("Custom", "Tol1") = 0.2
	iProperties.Value("Custom", "Tol2") = 0.3
	iProperties.Value("Custom", "Tol3") = 0.5
	iProperties.Value("Custom", "Tol4") = 0.8
	iProperties.Value("Custom", "Tol5") = 1.2
	iProperties.Value("Custom", "Tol6") = 2
	iProperties.Value("Custom", "Tol7") = 3
	iProperties.Value("Custom", "Tol8") = 4
	iProperties.Value("Custom", "TolSelect") = "COARSE"
	
ElseIf TolSelect = "2. MEDIUM" Then
	iProperties.Value("Custom", "Tol1") = 0.1
	iProperties.Value("Custom", "Tol2") = 0.1
	iProperties.Value("Custom", "Tol3") = 0.2
	iProperties.Value("Custom", "Tol4") = 0.3
	iProperties.Value("Custom", "Tol5") = 0.5
	iProperties.Value("Custom", "Tol6") = 0.8
	iProperties.Value("Custom", "Tol7") = 1.2
	iProperties.Value("Custom", "Tol8") = 2
	iProperties.Value("Custom", "TolSelect") = "MEDIUM"
	
ElseIf TolSelect = "1. FINE" Then
	iProperties.Value("Custom", "Tol1") = 0.05
	iProperties.Value("Custom", "Tol2") = 0.05
	iProperties.Value("Custom", "Tol3") = 0.1
	iProperties.Value("Custom", "Tol4") = 0.15
	iProperties.Value("Custom", "Tol5") = 0.2
	iProperties.Value("Custom", "Tol6") = 0.3
	iProperties.Value("Custom", "Tol7") = 0.5
	iProperties.Value("Custom", "Tol8") = "-"
	iProperties.Value("Custom", "TolSelect") = "FINE"

End If

 

0 Likes
Accepted solutions (2)
373 Views
4 Replies
Replies (4)
Message 2 of 5

alexanderboogaard
Enthusiast
Enthusiast

Hi,

Please find below a working solution. Please let me know if this is OK for you:

 

First add a parameter to the model/drawing
Tol_Selected True/False

alexanderboogaard_0-1698402063375.png

Set it to False in your template and as default.

 

Then create an ilogic rule:

 

 

Sub Main()
  If Tol_Selected() = True
    Exit Sub
  Else
    Dim CExt As New ArrayList
      CExt.Add("1. FINE")
      CExt.Add("2. MEDIUM")
      CExt.Add("3. COARSE")
      CExt.Add("4. VERY COARSE")

    TolSelect = InputListBox("Choose Tolerance", CExt, "Part", Title:="Tolerance", ListName:="Available tolerance sets")

    If TolSelect = "" Then 'Failed to select tolerance
      MessageBox.Show("Failed to select tolerance. Rule will abort", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
      Return
    End If

    'Set tolerances
    Select Case TolSelect
      Case "1. FINE"
        iProperties.Value("Custom", "Tol1") = 0.05
        iProperties.Value("Custom", "Tol2") = 0.05
        iProperties.Value("Custom", "Tol3") = 0.1
        iProperties.Value("Custom", "Tol4") = 0.15
        iProperties.Value("Custom", "Tol5") = 0.2
        iProperties.Value("Custom", "Tol6") = 0.3
        iProperties.Value("Custom", "Tol7") = 0.5
        iProperties.Value("Custom", "Tol8") = "-"
        iProperties.Value("Custom", "TolSelect") = "FINE"
      Case "2. MEDIUM"
        iProperties.Value("Custom", "Tol1") = 0.1
        iProperties.Value("Custom", "Tol2") = 0.1
        iProperties.Value("Custom", "Tol3") = 0.2
        iProperties.Value("Custom", "Tol4") = 0.3
        iProperties.Value("Custom", "Tol5") = 0.5
        iProperties.Value("Custom", "Tol6") = 0.8
        iProperties.Value("Custom", "Tol7") = 1.2
        iProperties.Value("Custom", "Tol8") = 2
        iProperties.Value("Custom", "TolSelect") = "MEDIUM"
      Case "3. COARSE"
        iProperties.Value("Custom", "Tol1") = 0.2
        iProperties.Value("Custom", "Tol2") = 0.3
        iProperties.Value("Custom", "Tol3") = 0.5
        iProperties.Value("Custom", "Tol4") = 0.8
        iProperties.Value("Custom", "Tol5") = 1.2
        iProperties.Value("Custom", "Tol6") = 2
        iProperties.Value("Custom", "Tol7") = 3
        iProperties.Value("Custom", "Tol8") = 4
        iProperties.Value("Custom", "TolSelect") = "COARSE"
      Case "4. VERY COARSE"
        iProperties.Value("Custom", "Tol1") = 0.2
        iProperties.Value("Custom", "Tol2") = 0.3
        iProperties.Value("Custom", "Tol3") = 0.5
        iProperties.Value("Custom", "Tol4") = 0.8
        iProperties.Value("Custom", "Tol5") = 1.2
        iProperties.Value("Custom", "Tol6") = 2
        iProperties.Value("Custom", "Tol7") = 3
        iProperties.Value("Custom", "Tol8") = 4
        iProperties.Value("Custom", "TolSelect") = "VERY COARSE"
    End Select
    Tol_Selected = True
  End If
End Sub

 

 

The code will check if a tolerance has been set by checking the True/False parameter.

When something is selected it will add/change the iProperties and change the parameter to True.


Kind regards,
Alexander Boogaard
0 Likes
Message 3 of 5

Jack.Swindells
Explorer
Explorer

Thank you for this, this works great. However, there will be situations where once the tolerance is selected we will need to go back in and change it. Which is why I went with a form as its easy to show people where that is if they need to change it.

 

The only way I can think of with this is a separate rule that we run manually that sets the Tol_selected parameter back to False, the TolSelect to " ", and then triggers this rule again. Is there a better way to do this?

0 Likes
Message 4 of 5

alexanderboogaard
Enthusiast
Enthusiast
Accepted solution

To add a form, you could:

alexanderboogaard_2-1698407529321.png

alexanderboogaard_3-1698407791019.png

Click OK and then you have a form where you can change the true/false parameter.

 

If you than also add the iLogic rule to an eventtrigger "Before save document" the rule will check if the Tol_Selected parameter is True. Because you just set it to False it will continue running and show the list again.

 

Event triggers:

alexanderboogaard_0-1698409294891.png

alexanderboogaard_2-1698409671835.png

 

 

Inventor 2022 Help | To Work with Event Triggers in iLogic | Autodesk

 


Kind regards,
Alexander Boogaard
Message 5 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Jack.Swindells.  When you changed your internal iLogic rule into an external rule, that's when the problem started right?  I assume then that the "TolSelect" being used in your code was the unquoted name of a parameter within the same document that the rule was saved within, right?  You will no longer be able to use an unquoted name of a parameter in an external iLogic rule, because an external rule is not saved within the same document as the parameter, so it will no longer be recognized as representing a parameter.  You may simply be able to change that to

Parameter("TolSelect")

...instead of just

TolSelect

...that way it will be recognized as representing the value of a parameter again.  However, as you can see, that line of code does not specify what document to access the parameter within, which can cause confusion or problems in some situations.  Same for the iProperties.Value() snippets you are using...they do not specify which document to access that iProperty from.  When using external iLogic rules, making sure your rule will be focusing on the correct / intended target document becomes more important and more challenging.  And since the help documentation does not explain in detail which document these snippets will focus on in different situations, it is best if they are always used when the document you want them to focus on is actively visible on your screen at the time, to help avoid any potential problems.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes