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

Suggestion for UnitTypes

Discussion in 'Alibre Script' started by NateLiqGrav, Jun 9, 2019.

  1. NateLiqGrav

    NateLiqGrav Alibre Super User

    My suggestion is to add a dropdown option to the Alibre Script Option Dialog for the user to pick a default setting for UnitTypes (Millimeters, Centimeters, or Inches) that will be used if the script does not explicitly set one or if the script sets it to UnitTypes.UserDefault

    This would be nice for future scripts. It often doesn't matter what UnitTypes are for my scripts.
     
  2. idslk

    idslk Alibre Super User

    Hello Nate,

    it would be ok to have configurable units in the Alibre Script Option Dialog.
    If you are talking about future scripts, do have something special in your mind?
    Which will be the usage of different types of units between system and script, if they can be choosen by the user?
    If i'm the writer of the script, i can react to the Units.Current.
    I let the script do internal calculations with the script intended units and can let convert the results to the Units.Current of the user, if needed.

    If i want to give the user the chance to change the Unit.Types i can do the following:
    Code:
    #print unchanged unittypes on start of the script
    print 'Startunits',Units.Current
    
    
    def choose_unittypes():
      #
      # userwindow with dropdown to change current script units
      #
      win = Windows()
      unitlist = ['Millimeter','Cemtimeter','Inches']
      info = ('Your current system units are:\n\n'+str(Units.Current)+
      '\n\nyou can change the script units:\n')
      options = []
      values = []
      options.append(['Info', WindowsInputTypes.Label, info])
      options.append(['UnitType', WindowsInputTypes.StringList, unitlist])
      dialogwidth = 165
      values = win.OptionsDialog('IDSLK', options, dialogwidth)
      if values[1] == 0:
        Units.Current = UnitTypes.Millimeters
      elif values[1] == 1:
        Units.Current = UnitTypes.Centimeters
      elif values[1] == 2:
        Units.Current = UnitTypes.Inches
    
    
    choose_unittypes()
    
    #print changed unittypes after using choose_unittypes
    print 'Changed units',Units.Current
    Regards
    Stefan

    Edit: Typo... it has to be values[1] in the if's
     
    Last edited: Jun 10, 2019
  3. idslk

    idslk Alibre Super User

    Hello cooleagues,

    here a very tiny demo...

    You can choose the units which the script should use:
    upload_2019-6-10_15-4-38.png

    then the script generates a dropdown (for the demo with inch fractions)

    upload_2019-6-10_15-6-31.png
    if you have choosen a fraction the script will translate it to the choosen units (in this case Millimeters)

    upload_2019-6-10_15-5-58.png

    I think the conversion from values to fractions to dropdown to value to units in alibre script / python might be interesting...

    Regards
    Stefan
     

    Attached Files:

  4. ajayre

    ajayre Alibre Super User

    If your script doesn't care what the units are then isn't it just easier to use the built in default of millimeters?

    Andy
     
  5. NateLiqGrav

    NateLiqGrav Alibre Super User

    Sure, but this idea is to let the user set what they want that default to be for their pc. I can create this user setting for each script ( see Stefan's examples above) but why not make it more consistent for the user.
     
  6. ajayre

    ajayre Alibre Super User

    Users can choose their preferred display units for parts and assemblies, however there is currently no way of accessing that via Alibre Script. I've added this for the next release:

    Code:
    Units.Current = CurrentPart().DisplayUnits()
    Andy
     
    NateLiqGrav likes this.
  7. NateLiqGrav

    NateLiqGrav Alibre Super User

    That will work nicely. Thank you!
    I wonder though; How does it translate the different display units into the 3 UnitTypes options? Feet for example?
     
  8. ajayre

    ajayre Alibre Super User

    AlibreScript currently only supports mm, cm, and inches. If anyone wants other units supported they should submit a request to support. I've never had a request to support feet.

    Andy
     
  9. NateLiqGrav

    NateLiqGrav Alibre Super User

    I realize that. I'm just wondering if it's possible that CurrentPart().DisplayUnits() could be something other than mm, cm, and inches and what Alibre Script would to in those cases?
     
  10. Lew_Merrick

    Lew_Merrick Alibre Super User

    Ah, but where are: Barley corns, Furlongs, or Light-seconds?
     
  11. ajayre

    ajayre Alibre Super User

    Generate an error. Andy
     
  12. idslk

    idslk Alibre Super User

    :D

    @NateLiqGrav
    Please help my imagination, i've thought about that and didn't found a usage that makes sense for me...

    Regards
    Stefan
     
  13. NateLiqGrav

    NateLiqGrav Alibre Super User

    For example: the script doesn't use ANY preset length values so UnitType doesn't matter to it. Instead all values are entered by the user in dialog boxes. I could code a dialog box and store their preference to a file on the users drive that I will look in for their default. I could then copy and paste this in each script. It's a user preference that will not change often, so I thought it best to be in the Options to remove repetition in scripts.
     
  14. idslk

    idslk Alibre Super User

    Hello Nate,

    if i choose my system defaults for units (for me it's easy, i use SI units...) i also suppose that my scripts will run with the same units.
    As well as i can understand to make use of a "file" with some additional user presets, as a standard i would "tell" the user: "Hey user, this script uses the same units as your Alibre defaults! If you want to change that, rearange the script code..."(or something like this).
    I think it's more important for scripts that they are able to deal with different standard settings of the host (Alibre).
    What i have discovered is that (my system (windows) is a german installation and my Alibre is a german installation, too) if i change the alibre properties to feet or inches and i ask "Units.Current" with a script, i get Millimeters. The dimensions while sketching are in inches as supposed. I haven't found how to get the design properties read out with the script. The "Units.Current" in the script will only change (and only for the script!) if i set them in the script(eg. UnitTypes.Inches). I have not taken care about this before...

    upload_2019-6-11_20-40-48.png

    upload_2019-6-11_20-41-22.png

    upload_2019-6-11_20-42-16.png

    Regards
    Stefan
     

Share This Page