iLogic - CASE Statement Help

iLogic - CASE Statement Help

arkelec
Collaborator Collaborator
3,203 Views
4 Replies
Message 1 of 5

iLogic - CASE Statement Help

arkelec
Collaborator
Collaborator

As a rookie in Inventor VBA & iLogic, can I ask for a quick steer on the right approach to solve what I think is a fairly simple problem.

 

I need to set a dimension in an iPart to be conditional on the "Length" parameter (this is the actual parameter name).

 

I have some other parameters, one of which is used as the dimension in question, it's called "Dist_1".

 

Dist_1 will be either of two values:

 

Condition 1: 0
Condition 2: The result of another calculated formula within the iPart parameters

 


The iPart has 20 or so different lengths programmed into it. For every length which is a multiple of 100mm, I need to set Dist_1 to condition 2. For all others, condition 1.

 

A bit of net trawling suggest using the CASE function. I have created an iLogic rule containing the following code:

 

Select Case Length
Case "100"
Dist_1 =Dist_2
Case "200"
Dist_1 =Dist_2
Case "300"
Dist_1 =Dist_2
Case "400"
Dist_1 =Dist_2
Case "500"
Dist_1 =Dist_2
Case "600"
Dist_1 =Dist_2
Case "700"
Dist_1 =Dist_2
Case "800"
Dist_1 =Dist_2
Case "900"
Dist_1 =Dist_2
Case "1000"
Dist_1 =Dist_2
Case "1100"
Dist_1 =Dist_2
Case "1200"
Dist_1 =Dist_2
Case "1300"
Dist_1 =Dist_2
Case "1400"
Dist_1 =Dist_2
Case "1500"
Dist_1 =Dist_2
Case Else
Dist_1 =0
End Select

 

 

Clicking Save & Run does not generate any errors but assuming the above is correct, I'm not sure what to do next.

Some questions:

 

  1. Is the syntax for the length values correct (are the " " needed & do I need to specify the units used in the parameter setting - i.e. mm)?
  2. How do I link the dimension in the sketch to the output of the iLogic rule?

 

 

Thanks 🙂

0 Likes
3,204 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

1. The quotation marks depend entirely on what data type you are comparing. Given that it LOOKS like you are using Length as a parameter, I believe that means it's type will be "DoubleForEquals". Not sure what this means for the results of your code, but you can always write a simple example program to test it out.

 

2. Get the rule to set the PARAMETER, and have go into your sketch and make it reference that PARAMETER, like intended.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 5

arkelec
Collaborator
Collaborator
Thanks for replying.

I'm not sure what point one of your answer means but agree it can be tested.


MechMachineMan wrote:

 

2. Get the rule to set the PARAMETER, and have go into your sketch and make it reference that PARAMETER, like intended.


This is the bit I can't seem to work out - "Get the rule to set the PARAMETER".  How & where is this done?

 

Dist_1 & Dist_2 are already parameters (user defined) & the sketch dimension (d27) already references Dist_1.

 

 

 

I assume that this will all work with an iPart?

0 Likes
Message 4 of 5

arkelec
Collaborator
Collaborator

OK, I think the problem might lay with updating.

 

In the "Driving Rule" column in the parameters box, it lists the name of the rule I created.

 

I also created a form with the parameter "Length" visible so when I change that from 500 to 550mm, the DIST_1  value changes from Dist_2 to 0 (as per the rule code).

 

But when I "Change Component" in an assembly, the 0 value (Dist_1 parameter) is not updated.

 

 

 

Edit:  

 

There is something else wrong.  It seems Dist_1 is either equal to Dist_2 or 0, but not both when there are two or more instances of the iPart in the same assembly.

 

 

0 Likes
Message 5 of 5

rossano_praderi
Collaborator
Collaborator

Hi,

I just would like to give you an alternative to "Select case" only for your information.

 

This is an "if" operator also called "ternary" with which you can get a shorter syntax for your code.

(https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/if-operator)

 

I'm also used the "mod" operator to check if the given number is a multiple of 100.

(https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/mod-operator)

 

Dist_1 = If((Val(Lenght) Mod 100) = 0, Dist_2, 0)

This doesn't solve your last question but can be helpful to make more readable your code.

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
0 Likes