- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can you tell me why the following does not work when I execute it from a saved file, in the script editor in max, yet running it from the same file in Sublime produces the result I expect?
s1 = sys.argv[0] fileDir = os.path.dirname(__file__) fileNm = os.path.basename(__file__) abPth =os.path.dirname(os.path.abspath(__file__)) os_cwd = os.getcwd() print s1 print fileDir print fileNm print abPth print os_cwd
Max errors with this:
Traceback (most recent call last): NameError: name '__file__' is not defined
I looked (as best as I could) through what I hoped would be the auto complete list for os commands regarding the same commands in the script I executed in sublime with success, but the results were not as expected or gave no result either way on execution.
I am assuming that its a formatting issue that I am not implementing correctly as if I try and construct a command with the os functionality provided by pymxs, I am not getting back what I need.
I also tried the following, getting pretty much the same results from Max and Sublime, except for line 2:
print os.path.__file__ print os.path.basename(os.path.abspath(os.path.__file__)) print os.path.dirname #Returns """ <function dirname at 0x00000195E3295E48> C:\Program Files\Autodesk\3ds Max 2018\python27.zip\ntpath.py ntpath.py <function dirname at 0x00000195E3295E48> """
I need to be able to edit the sys.path, get filenames etc as I would normally do with Python external to max or in Maya without this convoluted hassle.
os.getcwd() works if I have performed a "save as" on the script, otherwise, it just prints the location of the last file that was saved via a "save as" option, which is not what is required.
I have been developing my script as a .py file but the inability to correctly call os and other python commands is proving a hassle at present.
I also get the same issues if I save as a mxs file, so there could be a bug with the environment unless someone has found a way to correctly use the os and sys commands or can show a method that can be used.
I tried print pymxs.runtime.getThisScriptFilename() in a py file and an mxs file. Neither worked, just returned None
regards
Solved! Go to Solution.
