2

I have this problem where I'm unable to get the function FrameSelected() to work Basically in my scene, there is a camera called TT_CAM and a list of models with the labels called 'Model' (It's like pCube/Sphere etc are called polygon)

My objective is when the user executes the script, the viewport will change to TT_CAM while focusing ('f' keyboard key) on all the Model objects.

I tried using the code below but it fails for the FrameSelected.

Here's what I have tried:

import maya.cmds as cmds
    cmds.lookThru("TT_CAM")
    mAssets = cmds.select('Model*')
    #cmds.viewFit(mAssets)
    cmds.FrameSelected(mAssets)
Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95
yan
  • 631
  • 9
  • 30
  • What was wrong with `viewFit()`? Also, to my knowledge, cmds does not have a `FrameSelected()` function. That being said, the way you have it typed would imply that `FrameSelected()` is a class and you are adding the selected objects to that class. – Argiri Kotsaris Feb 17 '14 at 14:45
  • Hi there, well, `viewFit()` kinda works but not in the manner I would want it as the `FrameSelected()` (aka focus) Earlier I came across `pymel.core.runtime.FrameSelected` in which it documentated as `FrameSelected(*args, **kwargs)` Any ideas how this works? – yan Feb 17 '14 at 15:10

1 Answers1

1

I'll just post this as an answer. I didn't realize that pymel had such a function actually, but you would have to import it explicitly to use it (that being one of the problems here seeing as how you were calling it from cmds). Due to the size of your code I'll just rewrite this using pymel..

import pymel.core as pm
from pymel.core.runtime import FrameSelected

pm.lookThru("TT_CAM")
mAssets = pm.select('Model*')
FrameSelected() # no arguments need be passed, works off selected objects

Though this does seem to work just like viewFit(), which accepts other arguments like fitFactor where you can pass a float to determine what percentage of the viewport you want fitted.

Argiri Kotsaris
  • 492
  • 3
  • 7
  • Cool, I will try it out asap when I am able to get hands on my program, and get back to you to see if it words. By the way, I tried to search online trying to understand what are the *args and **kwargs, any ideas? – yan Feb 17 '14 at 15:57
  • Unfortunately no idea, there doesn't seem to be any documentation on it anywhere.. – Argiri Kotsaris Feb 17 '14 at 16:03
  • @yan *args and *kwargs stand for Arguments and keyword arguements, you can use them to let your functions take an arbitrary number of keyword arguments, you would use `*args` when you are unsure how many arguments might be passed to your function, Similarly, `**kwargs `allows you to handle named arguments that you have not defined in advance. – Shannon Hochkins Feb 17 '14 at 21:54
  • @ShannonHochkins I believe what he is referring to is what those arguments actually do in this particular function.. – Argiri Kotsaris Feb 17 '14 at 22:46
  • I believe that still answers his question, additionally he doesn't actually have *args or **kwargs in any question here. – Shannon Hochkins Feb 18 '14 at 00:33
  • 2
    Hi all, thanks for the feedback. I just tried out the code posted by @ArigirlKotsaris... It is still selecting my objects, however the FrameSelect ain't working. Still stuck with the same view in my cam before/after I execute the code – yan Feb 18 '14 at 01:47