[Maya-Python] Callback for Set Project?

845 views
Skip to first unread message

Marcus Ottosson

unread,
Oct 5, 2016, 3:58:55 AM10/5/16
to python_in...@googlegroups.com

Hi all,

I’m looking to run a snippet of Python when the user changes project.

For example, I’d like the string "Project was set!" to be printed when running this.

from maya import cmds

def on_setproject():
    print("Project was set!")

cmds.workspace("C:/my/project", openWorkspace=True)

The MSceneMessage class is the closest thing I found, but it doesn’t provide anything related to projects/workspaces.

Any ideas?

Thanks!

--
Marcus Ottosson
konstr...@gmail.com

Mahmoodreza Aarabi

unread,
Oct 5, 2016, 4:39:04 AM10/5/16
to python_in...@googlegroups.com

hey man
i did this and it works fine for me

from maya import cmds, mel
import pymel.core as pm
workspace_path = os.path.normpath("your/path")
pm.mel.setProject(workspace_path)
mel.eval("print \"Project set successfully\\n\";")

check it


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBo508CRtQCXwAi3%2BcPafk%2BT2P-6iP0dbZ421MKiHDy5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

Mahmoodreza Aarabi

unread,
Oct 5, 2016, 4:43:21 AM10/5/16
to python_in...@googlegroups.com
This is for setting project, but i think it have callback too, i didn't check that though. or scriptJob.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.



--


Bests,
madoodia



--


Bests,
madoodia

Nicolas Chaverou

unread,
Oct 5, 2016, 11:20:38 AM10/5/16
to python_in...@googlegroups.com
Hey,

Kinda tricky but if you check the setProject.mel, it looks like the workspace is changed pretty heavily
You may want to use a scriptJob on the workspaceChanged event and in the callback, compare the value of the optionVar RecentProjectsList (which is touched by addRecentProject.mel)

Else overriding proc sp_workAfterOpeningProject(string $projectLocation). But that's a bit dirty and dependant on your Maya version...

My 2cts
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CADvbQwJDGYy5_4KojYWO1S%3DX6eeduiu47R-6WfceovrY%3DDJrvA%40mail.gmail.com.

Marcus Ottosson

unread,
Oct 5, 2016, 12:00:33 PM10/5/16
to python_in...@googlegroups.com

Thanks Mahmoodreza and Nicolas!

You may want to use a scriptJob on the workspaceChanged event

That sounds like just what I’m looking for, however I can’t find this event? I’m on Maya 2015, preferably I’d like it to work from 2013 and above.

from maya import cmds
cmds.scriptJob(conditionTrue=["workspaceChanged", "cmds.warning('changed')"])
# RuntimeError: Could not find condition or event named "workspaceChanged" #

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Nicolas Chaverou

unread,
Oct 5, 2016, 12:54:21 PM10/5/16
to python_in...@googlegroups.com
On Wed, Oct 5, 2016 at 5:59 PM, Marcus Ottosson <konstr...@gmail.com> wrote:

Thanks Mahmoodreza and Nicolas!

You may want to use a scriptJob on the workspaceChanged event

That sounds like just what I’m looking for, however I can’t find this event? I’m on Maya 2015, preferably I’d like it to work from 2013 and above.


Oh... I find an example in the Maya 2017 workspace Python doc:
http://help.autodesk.com/cloudhelp/2017/CHS/Maya-Tech-Docs/CommandsPython/workspace.html

Maybe try using the event flag:
workspaceChangedID = cmds.scriptJob( event = ["workspaceChanged", workspaceChangedCallback] )
 



--
Marcus Ottosson
konstr...@gmail.com

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Marcus Ottosson

unread,
Oct 5, 2016, 1:04:39 PM10/5/16
to python_in...@googlegroups.com

That works!

from maya import cmds

def on_setproject():
    print("Project was set!"
)

cmds.scriptJob(event=["workspaceChanged", on_setproject])
cmds.workspace("C:/my/project", openWorkspace=True)

In 2015 too! Thanks Nicolas!

Reply all
Reply to author
Forward
0 new messages