Question

I am trying to write a turntable script in which it will automatically fits all my objects(bounding box) within the frame of my resolution gate which is HD 1080 (1920x1080)

test = cmds.select('MODELS*')
mel.eval('FrameSelectedInAllViews')
cmds.setAttr('TT_CAM.cameraScale', 1)

As I have quite a few, is my above code the correct way to script for bounding boxes?

Was it helpful?

Solution

I could only think of creating temporary locators, that fill the bounding box of the selected objects, then framing those locators, this works fine so far from what I've tested.

I've included comments in the script below:

from pymel.core import *

select("MODELS*")

## Gather our world bounding box and store it in a variable called b
b = general.exactWorldBoundingBox()

## b now contains min and max XYZ world coords
## Name our temporary locators

locName = "tempLoc"
## Create a locator at each min and max point to form a fake bounding box

positions = [[0,1,2], [0,4,2], [0,4,5], [3,4,5], [3,1,5], [3,4,2], [3,1,2], [0,1,5]]

## Create the locators 
for position in positions:
    print position
    spaceLocator(p=(b[position[0]],b[position[1]],b[position[2]]), name=locName)

## Once we create the locators, frame locators, delete

tempLocators = select("tempLoc*", r=1)
runtime.FrameSelectedInAllViews()
delete()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top