1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Global Parameter for Part Suppression?

Discussion in 'Using Alibre Design' started by Brandon_Velmex, Nov 12, 2020.

  1. I have an assembly which I am controlling with a global parameter file. The assembly is somewhat complicated in that there are about a dozen or more different add-ons that can be added, like different adaptor plates, handles, and extra parts, etc. Is there a way to use the global parameter file to selectively hide or show these extra parts? Or selectively suppress or activate them? This would be very helpful, because a different configuration for each add on would be an enormous amount of configurations.
     
    Last edited: Nov 12, 2020
  2. bigseb

    bigseb Alibre Super User

    Use configurations. Best way to do this!

    Capture.JPG
     
  3. NateLiqGrav

    NateLiqGrav Alibre Super User

    An Alibre Script can do it fairly easily.

    Code:
    ScriptName = 'Optional Addons'
    
    print("\n"*20) # lazy mans clear console
    
    Win = Windows()
    
    # define options to show in dialog window
    Options = []
    
    Options.append(['Adaptor Plate A', WindowsInputTypes.Boolean, 0])
    Index_Adaptor_Plate_A = len(Options)-1
    
    Options.append(['Adaptor Plate B', WindowsInputTypes.Boolean, 0])
    Index_Adaptor_Plate_B = len(Options)-1
    
    Options.append(['Adaptor Plate C', WindowsInputTypes.Boolean, 0])
    Index_Adaptor_Plate_C = len(Options)-1
    
    Options.append(['Handle A', WindowsInputTypes.Boolean, 0])
    Index_Handle_A = len(Options)-1
    
    Options.append(['Handle B', WindowsInputTypes.Boolean, 0])
    Index_Handle_B = len(Options)-1
    
    Options.append(['Extra A', WindowsInputTypes.Boolean, 0])
    Index_Extra_A = len(Options)-1
    
    Options.append(['Extra B', WindowsInputTypes.Boolean, 0])
    Index_Extra_B = len(Options)-1
    
    Values = Win.OptionsDialog(ScriptName, Options, 200)
    
    if Values == None:
        print("Canceled... Exiting.")
        sys.exit()
    # other error checking and program here
    
    Assem = CurrentAssembly()
    try:
        if Values[Index_Adaptor_Plate_A]:
            Assem.UnsuppressPart('Adaptor Plate A<1>')
        else:
            Assem.SuppressPart('Adaptor Plate A<1>')
    except:
        print("No part named 'Adaptor Plate A' Found.")
    
    try:
        if Values[Index_Adaptor_Plate_B]:
            Assem.UnsuppressPart('Adaptor Plate B<1>')
        else:
            Assem.SuppressPart('Adaptor Plate B<1>')
    except:
        print("No part named 'Adaptor Plate B' Found.")
    
    try:
        if Values[Index_Adaptor_Plate_C]:
            Assem.UnsuppressPart('Adaptor Plate C<1>')
        else:
            Assem.SuppressPart('Adaptor Plate C<1>')
    except:
        print("No part named 'Adaptor Plate C' Found.")
    
    try:
        if Values[Index_Handle_A]:
            Assem.UnsuppressPart('Handle A<1>')
        else:
            Assem.SuppressPart('Handle A<1>')
    except:
        print("No part named 'Handle A' Found.")
    
    try:
        if Values[Index_Handle_B]:
            Assem.UnsuppressPart('Handle B<1>')
        else:
            Assem.SuppressPart('Handle B<1>')
    except:
        print("No part named 'Handle B' Found.")
    
    try:
        if Values[Index_Extra_A]:
            Assem.UnsuppressPart('Extra A<1>')
        else:
            Assem.SuppressPart('Extra A<1>')
    except:
        print("No part named 'Extra A' Found.")
    
    try:
        if Values[Index_Extra_B]:
            Assem.UnsuppressPart('Extra B<1>')
        else:
            Assem.SuppressPart('Extra B<1>')
    except:
        print("No part named 'Extra B' Found.")
    
    print("Done")
    
     
    Last edited: Nov 12, 2020
    Brandon_Velmex likes this.
  4. Wow, that looks like exactly what I'm looking for. It looks like I'm going to be learning some Python! Thanks Nate!
     
  5. NateLiqGrav

    NateLiqGrav Alibre Super User

    Your welcome. Here is what my example looks like when you run it:
    upload_2020-11-12_12-49-39.png
     
    Brandon_Velmex likes this.
  6. Beautiful!
     
  7. Okay so maybe I'm using it wrong, but no matter what the script says "No part named ______ found." Why would it not recognize the part in the assembly?
     
  8. NateLiqGrav

    NateLiqGrav Alibre Super User

    Did you change the names of all the parts to exactly match the parts?

    You must also include the instance identifier in part names too. For example the first instance of a part:
    Code:
    Assem.UnsuppressPart('Adaptor Plate B<1>')
    And the second instance:
    Code:
    Assem.UnsuppressPart('Adaptor Plate B<2>')
    I have updated the code above to reflect that.
     
    Brandon_Velmex likes this.
  9. Yes I changed my part to match the names in the script. After adding the <1> it gives an error,
    File "", line 11
    Index_Adaptor_Plate_A<1> = len(Options)-1
    ^
    SyntaxError: unexpected token '='

    Does everything have to be in ' '?
     
  10. Nevermind I got it working. The key is to remove the <1> when it references the index. Man this might be a sharp learning curve haha.

    Thank you again for the help!
     
  11. NateLiqGrav

    NateLiqGrav Alibre Super User

    In this script only the UnsuppressPart('Adaptor Plate B<1>') and
    SuppressPart('Adaptor Plate B<1>') need the <1>
     
    Brandon_Velmex likes this.

Share This Page