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

Find Path to Script

Discussion in 'Alibre Script' started by NateLiqGrav, Apr 8, 2019.

  1. NateLiqGrav

    NateLiqGrav Alibre Super User

    I'm trying to find the path to the script instead of having the path coded - so I can load information from an xml file sitting in the same folder. So far all the paths that I can find point to 'C:\Program Files\Alibre Design\Program' or a subfolder of that folder. Any ideas?

    Code:
    from System.IO import Directory
    directory = Directory.GetCurrentDirectory()
     
  2. idslk

    idslk Alibre Super User

  3. NateLiqGrav

    NateLiqGrav Alibre Super User

    I thought about locating the file by searching the entire hard drive but it didn't seem economical.
     
  4. simonb65

    simonb65 Alibre Super User

    Not tried it, but does this work in Alibre Script, it works in python ...

    Code:
    import os
    scriptDirectory = os.path.dirname(os.path.realpath(__file__))
     
  5. NateLiqGrav

    NateLiqGrav Alibre Super User

    Nope gives path to Alibre program.
     
  6. simonb65

    simonb65 Alibre Super User

    Bummer! Sounds like a new feature request, but then again, if the scripts are saved with the part, where are the scripts actually run from??? Yet another question for @ajayre me thinks!
     
  7. NateLiqGrav

    NateLiqGrav Alibre Super User

    Good point.
    My intentions were to make this tool save settings per user/pc instead of per assembly/part. I hadn't thought about what I'd do if the script was saved in / run from in the assembly/part. I'll have to add a step to my load/save settings function that uses the GetUserData and SetUserData to check for existing settings in the assembly/part.
     
  8. ajayre

    ajayre Alibre Super User

    Code:
    print ScriptFileName
    print ScriptFolder
    
    Andy
     
    NateLiqGrav, idslk and simonb65 like this.
  9. NateLiqGrav

    NateLiqGrav Alibre Super User

    Awesome! This will allow me to determine if the script is run from "in memory" or from a saved location too.

    Please add information like this to the Help Reference. Otherwise the only people who know are you and those of us reading everything on the forum.
     
  10. idslk

    idslk Alibre Super User

    I also didn't found CurrentPart(),CurrentAssembly() and AlibreScriptVersion, maybe they could be added to the help too.

    Regards
    Stefan
     
    NateLiqGrav likes this.
  11. ajayre

    ajayre Alibre Super User

    These have been added to the AlibreScript manual - thanks for the suggestion.

    Andy
     
    NateLiqGrav likes this.

Share This Page