Discussion:
[Maya-Python] Get the current Maya session
kiteh
2018-08-24 23:27:40 UTC
Permalink
Is there a way to check if the current maya session is 'new'?

I have a tool created using PyQt, in which it stores the widgets inputs
using QSettings (asked this question previously). The settings and all
works out great, however I realized that if I launched a new maya session,
followed by relaunching my tool, the 'stored' settings is/ are being loaded.

And hence, I would wanted to see if I can implemented in a way such that:

- if user clicks on 'new scene' or open/ load a new file in the current
maya session > if my tool is relaunched, it will prompt a popup and ask if
User wants to load the 'old' settings or use default settings?
- if user launch a new maya session > open/ load a new file > launch my
tool, it should load in the default settings.

Will this be too complicated to do so? I am hoping to implement in the
first point if possible.

Many thanks in advance!
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/027560d6-b26d-4407-9329-1c019808ea93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-24 23:49:13 UTC
Permalink
Post by kiteh
Is there a way to check if the current maya session is 'new'?
I have a tool created using PyQt, in which it stores the widgets inputs
using QSettings (asked this question previously). The settings and all
works out great, however I realized that if I launched a new maya session,
followed by relaunching my tool, the 'stored' settings is/ are being loaded.
- if user clicks on 'new scene' or open/ load a new file in the
current maya session > if my tool is relaunched, it will prompt a popup and
ask if User wants to load the 'old' settings or use default settings?
- if user launch a new maya session > open/ load a new file > launch
my tool, it should load in the default settings.
Will this be too complicated to do so? I am hoping to implement in the
first point if possible.
You can check cmds.file(query=True, sceneName=True) to see if the scene has
been saved to a file yet.

For more control, you can track the NewSceneOpened event using a scriptJob:
http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/scriptJob.html#flaglistEvents

Or using the API to to track specified scene events:
http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__cpp_ref_class_m_scene_message_html

This would allow you to handle the first point. If you tracked the new
scene event, you could switch a OptionVar bool back and forth between your
event handler and your UI launch.
Post by kiteh
Many thanks in advance!
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/027560d6-b26d-4407-9329-1c019808ea93%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/027560d6-b26d-4407-9329-1c019808ea93%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3PuxSCN%3Dai-BpLmr6uco0sREqfRCmvywHPfwnWOSovFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Michael Boon
2018-08-27 03:37:11 UTC
Permalink
The way Maya itself handles this is to only save settings when you close
Maya. I save settings from a lot of my tools using QSettings when they are
closed and it generally works well. The most significant caveat is that you
need to make doubly sure you handle exceptions when saving settings,
because you don't want to prevent other cleanup from being run. It also has
the disadvantage that if you have two sessions open, and you make a lot of
changes to your settings in one, but close that one first, the second
session can overwrite all the changes you saved from the first session.
Post by kiteh
Is there a way to check if the current maya session is 'new'?
I have a tool created using PyQt, in which it stores the widgets inputs
using QSettings (asked this question previously). The settings and all
works out great, however I realized that if I launched a new maya session,
followed by relaunching my tool, the 'stored' settings is/ are being loaded.
- if user clicks on 'new scene' or open/ load a new file in the
current maya session > if my tool is relaunched, it will prompt a popup and
ask if User wants to load the 'old' settings or use default settings?
- if user launch a new maya session > open/ load a new file > launch
my tool, it should load in the default settings.
Will this be too complicated to do so? I am hoping to implement in the
first point if possible.
Many thanks in advance!
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8457214a-cd5b-4e62-b4e5-244b67510b98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
kiteh
2018-08-27 16:50:41 UTC
Permalink
Hi all, many thanks for getting back.

It is upon the use of QSettings that I started to notice and wanted to
implement checking conditions, as what Michael has mentioned, especially
so, if there are 2 Maya sessions opened..
Will look into implementing callbacks then.

Thanks again!
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3c806381-a6b4-4aaf-8db7-366c88ae871a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-27 19:46:00 UTC
Permalink
Post by kiteh
Hi all, many thanks for getting back.
It is upon the use of QSettings that I started to notice and wanted to
implement checking conditions, as what Michael has mentioned, especially
so, if there are 2 Maya sessions opened..
Will look into implementing callbacks then.
Oh sorry. I thought you meant dealing with new sessions within one Maya
instance as opposed to "session" meaning a second Maya process.
QSettings has a "sync()" method, which usually is called automatically for
you when the QSettings is being destroyed. But you could call it manually
at points when you want to flush your changes to the file and to pick up
external changes. You can still have to instances stomping on each other
but at least they can be writing their changes sooner instead of on Maya
shut down.
For multiple instances of Maya, you could check the process list for
running pids.
Post by kiteh
Thanks again!
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/3c806381-a6b4-4aaf-8db7-366c88ae871a%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/3c806381-a6b4-4aaf-8db7-366c88ae871a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3eLK6-%2Bdk6h03psiwJRKj6EMMG4ZUim-eNX3zAP%3DW8pg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...