Load python script on startup

Load python script on startup

Admiral.Pixel
Enthusiast Enthusiast
10,757 Views
5 Replies
Message 1 of 6

Load python script on startup

Admiral.Pixel
Enthusiast
Enthusiast

Hi all. I created my own custom window script using python and I wonder how can I LOAD it automatically everytime I open Maya? I don't want to open my script manager and load my script everytime I open Maya. I tried using the userSetup.py but it pops up as a separate window and not on Maya itself. Also, how do I turn on Antialiasing on startup as well? Please see image for clarification. Thanks in advance. sample.pngsample2.png

0 Likes
Accepted solutions (1)
10,758 Views
5 Replies
Replies (5)
Message 2 of 6

morten_bohne
Advocate
Advocate

I'm guessing you made the ui in pyside? then you should be able to parent it to the main maya window

import maya.OpenMayaUI as omui
from shiboken import wrapInstance

def getMayaWindow():
    """pointer to the main maya window"""
    ptr = omui.MQtUtil.mainWindow()
    if ptr:
        return wrapInstance(long(ptr), QtGui.QMainWindow)

win = your_ui(parent=getMayaWindow())

 

as for the Antialiasing, I guess you could do something like this on startup (throw it in a script that gets run by your usersetup):

import pymel.core as pm

hwr = pm.PyNode("hardwareRenderingGlobals")
try:
    hwr.multiSampleEnable.set(1)
except:
    print("Couldn't set Anti-aliasing")

 or do the same through maya.cmds (might be faster to load?)

0 Likes
Message 3 of 6

Admiral.Pixel
Enthusiast
Enthusiast

Hey there and thanks for replying. Yes I did put the script inside because I don't know the python procedure like in userSetup.mel wherein you just put "source examplescriptname.mel;"  From

win = your_ui(parent=getMayaWindow()) <<I don't have UI I made the GUI with Python(or should I put the name of my script here?)
0 Likes
Message 4 of 6

morten_bohne
Advocate
Advocate
Accepted solution

you should just be able to import and run the tool from userSetup.py same way as you normally do?

 

something like:

import examplescriptname
examplescriptname.run_ui()

 Jeremy Ernst did some videos on fiddling with the userSetup.py a while back you could take a look at:

Message 5 of 6

Admiral.Pixel
Enthusiast
Enthusiast

Hi again. I finally figured it out. I used a def function and cmds.scriptJob(event = ["NewSceneOpened", function_name]) and call the function in the end. Thanks for the video. 

0 Likes
Message 6 of 6

Anonymous
Not applicable

Hi, where do you call the function in the end? In the userStartup.py or your custom script file?

Thank you! I have the same problem as yours.

0 Likes