iLogic Tutorial for Creating a SmartPart 3

 
 
 
 
 
 
 
 

In this, the final installment in this little sidebar iLogic tutorial for the Shaker Table series of tutorials, we will add the iLogic code that will hook the model to the spec’s posted at the beginning of this miniseries. Once this tutorial is completed, we will insert this part into the table and have the table control it automatically.

This iLogic Tutorial is winding down –there is not a lot left to do so let’s get right at it. Open up the Hanger Bolt.iam assembly, then open up the iLogic Rule Editor. You should have the following code there…

 

Inventor Tutorial for SmartPart – Part 3 image 01 - Autodesk Inventor's iLogic code

…if not, you will need to get it there. From looking at the list of available hanger bolts below, we can see that there are no bolts that have two different diameters for a particular length…

 

1/4-20 x 1 1/2 Hanger Bolt Dry Lube
1/4-20 x 2 Hanger Bolt Dry Lube
1/4-20 x 2 1/2 Hanger Bolt Dry Lube
1/4-20 x 3 Hanger Bolt Dry Lube
1/4-20 x 3 1/2 Hanger Bolt Dry Lube
5/16-18 x 4 Hanger Bolt Dry Lube
5/16-18 x 4 1/2 Hanger Bolt Dry Lube
5/16-18 x 5 Hanger Bolt Dry Lube

 

…so we will write the code so that it automatically gives the right diameter depending on length, and we will put in a fail-safe that will only allow the sizes available to be chosen. Before we can write the code, we need to add another parameter called Length. We already have a parameter called Length in the .ipt, but we need one here in the assembly as well. If you forgot how to do so, just go back a post or nine and refresh your memory.

 

Inventor Tutorial for SmartPart – Part 3 image 02 - Adding a parameter in Autodesk Inventor

Now that we have our new Length parameter in the Hanger Bolt assembly, we will fire up the iLogic Code Editor and start by giving ourselves some room at the top to add the new code, clicking on the User Parameters text just under the Hanger Bolt part name in the Model Tab, then double clicking on the new Length parameter to add it to the iLogic code window below…

 

 Inventor Tutorial for SmartPart – Part 3 image 03 - Adding a parameter into iLogic's code Editor

Now put your text insertion indicator before the Length parameter in the iLogic code window, then drill down into the Hanger Bolt part, click on User Parameters to get a parameter listing in the Parameters window, then double click on the Bolt_Length parameter to add it to the iLogic code window. Add an equal (=) sign between the two and you wind up with this…

 

 Inventor Tutorial for SmartPart – Part 3 image 04 - linking parameters in the iLogic code Editor

The length of the bolt part (.ipt) is now controlled at the assembly (.iam) level by the Length parameter. Now it’s time to tie the bolt diameter to the length. The following code will do the trick, just make sure you place it between the previous code blocks as shown…

 

 Inventor Tutorial for SmartPart – Part 3 image 05 - Matching lengths to diameters using iLogic Code

That’s almost it for today. There will be some code in the top level model, the Shaker Table, that chooses only a valid size, so no worries there, but we may as well create a quickie min/max right here so we don’t screw things up whilst playing around with the length. To do so, create some space below the top line of code that equalizes the length parameter between the assembly and the part, and put a Length parameter there…

 

 Inventor Tutorial for SmartPart – Part 3 image 05 - Adding the length parameter using Autodesk inventor's iLogic Code Editor

Inventor Tutorial for SmartPart – Part 3 image 06 - The iLogic Limits Wizard

 

 

 

Now highlight the new Length parameter and  switch to the Wizards Tab. Choose the Parameter Limits button when you get there. The iLogic Limits Wizard will appear, where you enter 1.5 for the Min. Value and 5 for the Max. Value. The Length parameter will be pre-chosen because you had it highlighted when the Wizard was started. Click Apply, then Close.

 

 

 

 

 

 

Blazam! You got yourself a highfalutin min/max rules with genuine Windoze error messages! Sweet!

 

Inventor Tutorial for SmartPart – Part 3 image 07 - The new iLogic rule created by the min/max iLogic rule creator

That will wrap up this iLogic tutorial.Try it out for a bit. I’ll be back shortly with the next installment where, and I’m just guessing here, we will create the holes in the Shaker Table that will accept this puppy. Later.

 





8 thoughts on “iLogic Tutorial for Creating a SmartPart 3

  1. Hello Mark,
    Glad to see these new installments!
    I am scratching my head trying to figure this out…
    When I run this code, it works once, then the names of the content center parts (nuts, washers) change after they have been suppressed. Then the code won't execute because the parts cannot be found! How do I stabilize the part names?
    Did I do something wrong to cause this?
    Thanks,
    Jerry

    • Hi Jerry,

      Sounds very odd. The names are changing on you? Are you sure you are not suppressing the wrong parts?
      This is the code without the min/max rule:

      Parameter("Hanger Bolt:1", "Bolt_Length") = Length
      If Length = 1.5 Or Length = 2 Or Length = 2.5 Or Length = 3.5 Then
      Diam = .25
      Else If Length = 4 Or Length = 4.5 Or Length = 5 Then
      Diam = .3125
      End If

      If Diam = .25 Then
      Parameter("Hanger Bolt:1", "Bolt_Diam") = .25
      Component.IsActive("Hex Nut – Inch 5/16 – 18:1") = False
      Component.IsActive("Hex Nut – Inch 1/4 – 20:1") = True
      Component.IsActive("Circular Washer (Inch) 5/16:1") = False
      Component.IsActive("Circular Washer (Inch) 1/4:1") = True
      Else If Diam = .3125 Then
      Parameter("Hanger Bolt:1", "Bolt_Diam") = .3125
      Component.IsActive("Hex Nut – Inch 5/16 – 18:1") = True
      Component.IsActive("Hex Nut – Inch 1/4 – 20:1") = False
      Component.IsActive("Circular Washer (Inch) 5/16:1") = True
      Component.IsActive("Circular Washer (Inch) 1/4:1") = False
      End If

      See if yours matches

      • Thanks for your reply, Mark.
        The code matches exactly. I'll try to explain what I mean about the presto change-o name swapping…
        For example, while in the rule editor window, model tab,when I click the "Hex Nut – Inch 5/16 – 18:1", the part is correctly listed in the window to the right, on the Names Tab as "Hex Nut – Inch 5/16 – 18:1". (Part UN-suppressed).
        When the part is suppressed, clicking the same part in the model tab ("Hex Nut – Inch 5/16 – 18:1") produces a different listing to the right, on the Names Tab as "ANSI B18.2.2 – 5_16 – 18(2):1". Same part, different name.
        Is this normal? If so, I am barking up the wrong tree trying to solve the error, "The component named "Hex Nut – Inch 5/16 – 18:1" was not found." Same thing happens with all content center nuts and washers.
        I am sure this post has "NOOB" smeared all over it. Thanks for your patience.
        Jerry

        • Hi Jerry, Could you use the Q & A form (link in the top navigation bar) to upload your model? You would need to zip the folder with all of the parts in it. The ANSI B18.2.2 – 5_16 – 18(2):1 has me baffled. I would like to take a look, and maybe post the results.

          • Mark,
            Although I haven't figured out the cause of the problem above (yet…), I did find a simple work around where I renamed the nuts and washers (via the browser), edited the code to include the new names, and viola! The $%^@ thing works! Just in time to fill the new holes in my Shaker Table.
            In the mean time I will be working on my i-door…
            Thanks again for all of the great learning material you have made available here!
            Jerry

          • Hi Jerry, yeah, that has me baffled as to what could be causing the part name grief… but glad you found a work-around. I’ll be posting the next installment in a couple hours so keep a lookout.

            Mark

  2. Hi Mark. Great stuff. Really enjoying following along. Will we need the Hanger Bolt form in future posts (as the additional iLogic code in Part 3 seems to override it)? Also, what would you name the second Nut Offset constraint (with regards to 1/4" washer)?

    William

    • .Hi William,

      Thanks for the complement. No, we will not need the form later on. The hanger bolt assembly will be entirely controlled by the table after it is placed there and connected via iLogic. As for the second nut constraint –I forgot all about that. I forgot there were going to be two when I named the first one. I just went back and named them :

      Nut Offset 01 – for the 5/16” set and Nut Offset 02 for the ¼” set

      I’ll mention that in the next post for those who don’t read the comments. Thanks for the heads-up!

      Mark

Leave a Reply