ScriptJob = Frame selection

ScriptJob = Frame selection

dg3duy
Collaborator Collaborator
1,513 Views
7 Replies
Message 1 of 8

ScriptJob = Frame selection

dg3duy
Collaborator
Collaborator

I am investigating how to select the objects on screen and keep them centered on the screen, the closest I found is this.
With the current option I am using I have to deselect the element and select a new one for the scriptjob to act, I would like it to be activated every time I select an object on the screen.

 I would like to be able to use the SelectionChanged option, but I don't know how to use it.

import maya.cmds as cmds
jobNum = cmds.scriptJob( ct= ["SomethingSelected","cmds.viewFit()"])

#cmds.scriptJob( kill=jobNum, force=True)

(view in My Videos)


0 Likes
Accepted solutions (3)
1,514 Views
7 Replies
Replies (7)
Message 2 of 8

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

I have to be honest, I think the constant view jumping would make me throw up if I had this on all the time.

But here is how you do it, have fun:

import maya.cmds as cmds
jobNum = cmds.scriptJob( e = ["SelectionChanged","cmds.viewFit()"])

 

I hope it helps!

Message 3 of 8

dg3duy
Collaborator
Collaborator

It is excellent!

0 Likes
Message 4 of 8

dg3duy
Collaborator
Collaborator

@Kahylan I forget the idea that it can be done without the on-screen jump, it's a losing battle I'm looking for?

0 Likes
Message 5 of 8

Kahylan
Advisor
Advisor
Accepted solution

I looked it up and the viewFit command does have a flag for animated transitions.

import maya.cmds as cmds
jobNum = cmds.scriptJob( e = ["SelectionChanged","cmds.viewFit(an = True)"])

 you might also want use the fitfactor or center flag. depending on what you have in mind

 

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/CommandsPython/viewFit.html

Message 6 of 8

dg3duy
Collaborator
Collaborator

@Kahylan 
The publication of this post became more and more profound but very didactic.
The noChildren(noc) option I can't get it to work, I didn't manage to apply it.
Surely I am missing something.

cmds.viewFit( 'persp1', noc=True )

dg3duy_0-1665519472145.png

 

0 Likes
Message 7 of 8

Kahylan
Advisor
Advisor
Accepted solution

The noc flag is True by default, so you don't see any change when setting it True, only when setting it to False

Message 8 of 8

dg3duy
Collaborator
Collaborator

 

 

import maya.cmds as cmds
jobNum = cmds.scriptJob( ct = ["SomethingSelected","cmds.viewFit(an = True),cmds.viewFit(c = True),cmds.viewFit( f=0.5 )"]),cmds.scriptJob( e= ["SelectionChanged","cmds.select( clear=True ),cmds.undo()"])

##cmds.scriptJob(kill=jobNum)

 

I want to show you what I was able to do based on your great help.