How to use select case in inventor 13

How to use select case in inventor 13

Anonymous
Not applicable
757 Views
11 Replies
Message 1 of 12

How to use select case in inventor 13

Anonymous
Not applicable

I am trying to write a code that says if a door width is within a certain range to select a specific product. The range is something like 19" to 21" selecct hinge 1, if it it within 21.125 = > 24" use hinge 2 .... etc. Anyone able to help? I am new to iLogic programming, and I am pretty much self taught. I am also getting used to doing things a different way so I can make iParts out of them. I already have my door dimensions in a spreadsheet so I can control it from there

Thanks in advance!!!

0 Likes
758 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

here is a copy of my code, can anyone help?

 

 

If "door width" > 21 And < = 22 Then
"strap hinge length" = A
Else If "door width" > 22.125 And < = 26 Then
"strap hinge length" = B
Else If "door width" > 26.125 And < = 32 Then
"strap hinge length" = C
Else If "door width" > 32.125 And < = 38 Then
"strap hinge length" = D
Else "door width" > 38.125 And < = 40 Then
"strap hinge length" = E
End If

A = Case 18:
B: = Case 22:
C: = Case 28:
😧 = Case 30:
E: = Case 34:


Select Case Length
Case 18:
iPart.ChangeRow("Rolled Barrel Strap Hinge","H-316FW-18")
Case 22:
iPart.ChangeRow("Rolled Barrel Strap Hinge","H-316FW-22")
Case 28:
iPart.ChangeRow("Rolled Barrel Strap Hinge","H-316FW-28")
Case 30:
iPart.ChangeRow("Rolled Barrel Strap Hinge","H-316FW-30")
Case 34:
iPart.ChangeRow("Rolled Barrel Strap Hinge","H-316FW-34")
End Select

 

0 Likes
Message 3 of 12

ekinsb
Alumni
Alumni

Breaking this up into two sections of logic doesn't seem to be needed in this case.  Instead you can just do something like:

 

Dim DoorWidth As Double
DoorWidth = 35.5

If DoorWidth > 21 and DoorWidth <= 22 Then
    iPart.ChangeRows("Rolled Barrel Strap Hinge", "H-316FW-18")
Else If DoorWidth > 22.125 and DoorWidth <= 26 Then
    iPart.ChangeRows("Rolled Barrel Strap Hinge", "H-316FW-22")
Else If DoorWidth > 26.125 and DoorWidth <= 32 Then
    iPart.ChangeRows("Rolled Barrel Strap Hinge", "H-316FW-28")
End If

 

If you think it makes your code easier to read and maintain to break it into two parts then you can do something like this:

 

Dim DoorWidth As Double
DoorWidth = 35.5

dim DoorCase as Integer
If DoorWidth > 21 and DoorWidth <= 22 Then
    DoorCase = 18
Else If DoorWidth > 22.125 and DoorWidth <= 26 Then
    DoorCase = 22
Else If DoorWidth > 26.125 and DoorWidth <= 32 Then
    DoorCase = 28
End If

Select Case DoorCase
    Case 18
        iPart.ChangeRows("Rolled Barrel Strap Hinge", "H-316FW-18")
    Case 22
        iPart.ChangeRows("Rolled Barrel Strap Hinge", "H-316FW-22")
    Case 28
        iPart.ChangeRows("Rolled Barrel Strap Hinge", "H-316FW-28")
End Select

 Watch the Mod the Machine blog this week for a post I'm putting together about comparing numbers that could affect the results of your program.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 4 of 12

Anonymous
Not applicable

I like to know why I am using certain things, so I can understand them and adapt accordingly to different situations. Can you explain why the 2nd code is written the way it is?I find the 2nd one easier to read.

 

0 Likes
Message 5 of 12

Anonymous
Not applicable

Well, I swapped out my code for your 2nd one. it cant find the part anymore even though I cave put it back into the rule. it ran with no errors , but it didn"t change anything. I updated the door size, and the straps didn't adjust. Any idea why?
 I only had an issue with one of the models of the hinge, the other 6 worked fine.... any rhyme or reason to why?

 

0 Likes
Message 6 of 12

ekinsb
Alumni
Alumni

I was just copying what you had done when writing the second sample.  It's the same logic flow as in your original sample.  Personally, I would choose the first one because it's more direct but if the second one is easier for you to see what's happening there's nothing wrong with using it.  I'm a fan of breaking complex logic up into simpler pieces to make it easier to follow and it also makes it easier to debug and maintain later.

 

As far as it not computing, I would need a full test case to see what's going on.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 12

Anonymous
Not applicable
Would you like me to upload my files? You would only need 2 of them


-Jonathon Wood A-101
0 Likes
Message 8 of 12

ekinsb
Alumni
Alumni

Please simplify the files as much as possible along with directions on how to reproduce the problem.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 9 of 12

Anonymous
Not applicable

I need to put in a custom size door in excel and it reflect in Inventor (Done)

once the door has been sized, I need a hinge to be selected from either an 18, 22, 28, 30, 34, or 36" straphinge selected automatically and placed in a perdetermined spot. (HELP!!!!)

I have made the hinge into an iPart factory and built and sized accordingly.

I can now control the drro from excel, but I still have to manually swap out the hinges. (A HUGE bonus would be both hinges change at the same time)


I am uploading the three files now, and I hope what I'm looking to do can be done.

 

at the moment, I am unable t have the 30-36" in the rule for "Strap_Sizing" and within that rule I need to be able to select the material thickness by selecting interior or exterior in excel (3/16" or 1/4" respectively) and the "door width" needs to decide on the length of the strap to use.

0 Likes
Message 10 of 12

ekinsb
Alumni
Alumni

Did you intend to include the Excel file?  There are two attachments of the hinge file.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 11 of 12

Anonymous
Not applicable

Oops, I added the wrong one, you only need one of them, but here is the excel file.

0 Likes
Message 12 of 12

Anonymous
Not applicable
Geeze That was painful.... it didn"t like the file
0 Likes