What's new

File path ?

DavidJ

Administrator
Staff member
My Python manuals tell me that if file name is used, it is assumed to be in the same folder as the current Python program.

If I try that in Alibre Script (saving my text file in the Alibre Script Library along with the Script), I get complaint that the file can't be found in C:\Program Files\Alibre Design\Program.

I can easily get around this by specifying the full absolute file path in my script. This means that I'll have to tell anyone I pass the script to to edit the path in the script - rather than tell them to juts make sure to put the text file in the same folder as the script.

Am I missing something obvious, or does Alibre Script just work a bit differently from how my Python manuals suggest?
 

idslk

Alibre Super User
Hi David,

if you have a saved script:
Code:
print 'My script is saved in : ',ScriptFolder #gives you the folder
print 'My script filename is : ',ScriptFileName #gives you the filename of the script

Regards
Stefan
 

DavidJ

Administrator
Staff member
Stefan,

Interesting, your lines of code just confirm that the script is stored where I saved it.

Doesn't explain why file 'FavMat.txt' which is stored in the SAME folder will not open from the Script UNLESS I use the full absolute path. Everything I read suggests that I should be able to open the file from the saved script using

open('FavMat.txt')

but that complains that there's no file of that name in C:\Program Files\Alibre Design\Program. That suggests to me that the 'working directory' is C:\Program Files\Alibre Design\Program
 

DavidJ

Administrator
Staff member
Thanks for digging that out Stefan ! - it appears that 'ScriptFolder' is a useful tool to work around this (use it to combine with file name to get full path dynamically).

Sometimes I'm too close to the problem to see the solution....

Alibre Script clearly doesn't work like standard Python.
 
Top