Notifications
Clear all

[Closed] 3dsmax 2017 Python

Sure, but it doesn’t run python files there on startup. (only seems to run maxscript files)

 JHN

As a work around you can use a simple maxscript that calls your python script. Haven’t dived into the yet, so YMMV!

I’ve considered that, but feels like a cheap hack to get something to work that should have a legit method to actually work. I’d like to not rely on maxscript, what so ever. Appreciate the thought though. It would be like having to use the mel userSetup.mel in maya just to launch a python module on startup.

-Dan

Even though I use Maxscript, my startup is just single line script to call other script.
I do this so I can deploy/edit startup script easily across network.

I guess dev forgot to add python support for startup.
You should report as bug.

is c++ good for you? make c++ plugin which will start whatever you want.

I could do that, and perhaps i will. however an all python environment would be more ideal.
thanks for the info.

(apologies for the formatting)

I am running Max as an administrator, Windows 10

I also have a 64 bit build of Python 2.7.13 on my machine

I have been using pymxs in 2018 but find that some interaction is not the same as other uses with Python outside of Max.

For intstance, if I execute the following in a (previously saved) file open in Sublime, I get back all the paths etc. relative to the open script that I am editing. But in Max, I do not get what I expect. First it errors as:
Traceback (most recent call last):
NameError: name ‘file’ is not defined

If I omit all the other print statements and just print os_cwd, I do not get back the current dir of the script I am in unless I do a “save as” operation in the Maxscript Editor and overwrite the file, then printing os.cwd() gets me the correct location. If I edit the code and just “save”, the os.cwd() still defers to the last dir collected under the last “save as ” action, which may not be the file I am working in.

import os
import sys

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

I looked at various methods using the autocomplete, but the concatenation is not as it is in Python elsewhere, so its trial and error to get what I need.

If then, I do a final save as on my script, and then give it to someone else, will the path be right for their machine or the last path saved when I edited it? (I have not checked this yet)

In a fresh session, I opened a python script I made previously, the import being MaxPlus (not that it should be relative), and the same thing happens with the “save as” option in the editor:

import MaxPlus
import sys
import os
print os.getcwd()

Result:

C:\Program Files\Autodesk\3ds Max 2018

if I then “save as” on the file and run it again, I get:

C:\myStuff\MAXPLUS_Scripts

I was looking at scripting the “save as” with Quiet mode on (if available) but If there is a better way to get os.path info, I would welcome the pointer

Many thanks

The reason for file not working is the environment that Max evaluates a python script from it’s own editor is not the same as the environment when sending a script from Sublime.
Max sends the lines of text to the interpreter which means file is not defined as the script is not technically coming from a file.
Using Python.ExecuteFile, which Sublime uses to evaluate a Python file in Max, evaluates the given script in the Python interpreter which then defines file.
To quote the post from here:
https://stackoverflow.com/questions/16771894/python-nameerror-global-name-file-is-not-defined

It is the same with Motion Builder too.

To get around this you can use the following to get the directory or path of the currently executing script in the Python environment:


import os
import inspect
currentFrame = inspect.currentframe()
currentFile = os.path.abspath(inspect.getfile(currentFrame))
currentDir = os.path.dirname(currentFile)

Page 3 / 3