Hello everyone, I have an example script for maya_standalone that works in Maya2022 but doesn’t work in Maya2023.
The startup method I used was “mayapy.exe” in their installation directory.
Are there any operational differences between these two versions of Maya? Source code from
import time
def initialize():
try:
import maya.standalone
maya.standalone.initialize(name="python")
print("maya.standalone.initialize success!")
except:
pass
def uninitialize():
try:
import maya.standalone
maya.standalone.uninitialize()
print("maya.standalone.uninitialize success!")
except:
pass
def createModel():
# import mayapy
import maya.cmds as cmds
# create sphere and move it
sphereName = cmds.polySphere(name="mySphere")
cmds.move( -2, 1, 0, sphereName, absolute=True )
# create cube and move it
cubeName = cmds.polyCube(name="myCube")
cmds.move( 0, 0.5, 0, cubeName, absolute=True )
# create cylinder and move it
cylinderName = cmds.polyCylinder(name="myCylinder")
cmds.move( 2, 1, 0, cylinderName, absolute=True )
print("createModel success!")
def saveFile():
# import mayapy
import maya.cmds as cmds
# save .ma file
cmds.file(rename=r"D:\Maya_script\autoCreateMod.ma")
cmds.file(save=True, type="mayaAscii")
print("saveFile success!")
if __name__ == '__main__':
tic = time.time()
initialize()
createModel()
saveFile()
uninitialize()
toc = time.time()
print("run time cost: {}".format(toc-tic))
You don’t want to have bare try except blocks - it is best practice to catch a specific exception type and you also want to always report the error so users can see a problem has occurred
Ok, thank you for your help, I will try to catch the error, if there is progress I will continue to discuss, I am still a novice, please forgive my ignorance.
DLL load failed while importing standalone: The dynamic link library (DLL) initialization routine failed.
This is an initialization error, which was discussed a long time ago(In the link below). https://discourse.techart.online/t/import-maya-standalone-problem/1437
But the situation has changed. The Maya2023 installation directory has a lot less things than Maya2022(Some of the reduced folders are for python),I don’t know if these changes have anything to do with initialization errors
.
I don’t see any reason for the dll error.
Normally that happens when you try to import a compiled module that is incompatible with the current interpreter version
Traceback (most recent call last):
File "D:\Maya_script\import_maya.py", line 54, in <module>
initialize()
File "D:\Maya_script\import_maya.py", line 6, in initialize
import maya.standalone
DLL load failed while importing standalone: The dynamic link library (DLL) initialization routine failed.
I put “import maya print(maya)” into the script, and then run it with Maya2023 and Maya2022 respectively., I got the following picture,They are similar.I have no clue about this.
Adding name=“python” to the initialization is the approach of this article.(In the link below). https://forums.autodesk.com/t5/maya-programming/standalone-initialize-qt-error/td-p/12101213
Regardless of adding name=“python” or not, Maya2023 cannot run the script, but Maya2022 can.That shouldn’t be the point.
In the above article, “import maya.standalone as standalone” is normal. His Maya version is 2023.0. I am using 2023.3.I will try to switch to 2023.0.