[Maya-Python] Re: Get the current Maya session
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. On Saturday, 25 August 2018 09:27:40 UTC+10, kiteh wrote: > > 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+unsubscr...@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.
[Maya-Python] Re: Maya API: rotate around certain point without affecting rotate pivot
Hi, see if this works Basically you need to compute the transformation matrix that represents the rotation from a specific point ("vertex" in your case). That can be generally done by matrix composition m1*m2-1*transform*m2. Where m1 is the matrix of the object you want to move, m2-1 is the inverse matrix of the object you want to use as reference (parent space), transform is your rotation matrix, then you move it back to world by multiplying back m2. A quick example in maya can look like this: from maya.api import OpenMaya from maya import cmds cube = cmds.polyCube()[0] vtx = cube+'.vtx[2]' vtx_pos = cmds.xform(vtx, q=1,ws=1,t=1) # vertex does not have orientation, so will keep world # you can use vertex normals or custom... # ill just extract the position vtx_world_mmat = OpenMaya.MMatrix() for i in xrange(3): vtx_world_mmat.setElement(3,i, vtx_pos[i]) grp = cmds.createNode('transform') cmds.xform(grp, t=(5,0,0)) obj = cmds.polyPrism()[0] cmds.parent(obj,grp,r=1) obj_world_mat = cmds.xform(obj, q=1,ws=1,m=1) # compose the rotation matrix however you want, ill just make from euler rotation rot_eu = OpenMaya.MEulerRotation() rot_eu.y=3.1415*.5 # 90 deg (ish) rot_mmat = rot_eu.asMatrix() obj_world_mmat = OpenMaya.MMatrix(obj_world_mat) # transform *resulting_mmat = obj_world_mmat * vtx_world_mmat.inverse() * rot_mmat * vtx_world_mmat* # rotate cmds.xform(obj, ws=1, m=list(resulting_mmat)) If I understood you correctly this should be it. Cheers. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/12ffcb0c-37f1-4f13-9e27-153ccbe4ee1c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.