Pointing the camera at the center of a dataset using Python

E-mail from Cory at Kitware (lightly edited)

Say ‘canexo’ is the name of the ExodusIIReader object returned when you read the can.exo file.

If the filter is named ‘warpByVector1’. Then the code is basically the same, just replace ‘canexo’ in the example I provided with ‘warpByVector1’.

You can get its global bounds with
canexo = ExodusIIReader(…)
bds = canexo.GetDataInformation().DataInformation.GetBounds()

For the bounds of an individual block with, say, index 2, you can use

bds = canexo.GetDataInformation().DataInformation.GetDataInformationForCompositeIndex(2).GetBounds()

To get the bounds of multiple blocks, first use the Merge Blocks filter, and then use the Merge Blocks filter handle.

Bounds are specified as [xmin, xmax, ymin, ymax, zmin, zmax].

You can then set the camera focal point to the center of the bounds with

v = GetActiveView()
v.CameraFocalPoint = [0.5sum(bds[0:1]), 0.5sum(bds[2:3]), 0.5*sum(bds[4:5])]

Note that this may induce a rotation, so if you want to maintain the camera angle with respect to the dataset, you’ll need to compute the difference between the current and desired focal point, and add that movement to both the CameraFocalPoint and CameraPosition.