Create load_image_plane.py

This commit is contained in:
Toke Jepsen 2019-06-26 18:20:54 +01:00
parent 93ec72767a
commit fe33f76da4

View file

@ -0,0 +1,79 @@
import pymel.core as pc
from avalon import api
from Qt import QtWidgets
class ImagePlaneLoader(api.Loader):
"""Specific loader of plate for image planes on selected camera."""
families = ["plate"]
label = "Create imagePlane on selected camera."
representations = ["mov"]
icon = "image"
color = "orange"
def load(self, context, name, namespace, data):
new_nodes = []
image_plane_depth = 100
# Getting camera from selection.
selection = pc.ls(selection=True)
if len(selection) > 1:
QtWidgets.QMessageBox.critical(
None,
"Error!",
"Multiple nodes selected. Please select only one.",
QtWidgets.QMessageBox.Ok
)
return
if len(selection) < 1:
QtWidgets.QMessageBox.critical(
None,
"Error!",
"No camera selected.",
QtWidgets.QMessageBox.Ok
)
return
relatives = pc.listRelatives(selection[0], shapes=True)
if not pc.ls(relatives, type="camera"):
QtWidgets.QMessageBox.critical(
None,
"Error!",
"Selected node is not a camera.",
QtWidgets.QMessageBox.Ok
)
return
camera = selection[0]
camera.displayResolution.set(1)
camera.farClipPlane.set(image_plane_depth * 10)
# Create image plane
image_plane_transform, image_plane_shape = pc.imagePlane(
camera=camera, showInAllViews=False
)
image_plane_shape.depth.set(image_plane_depth)
# Need to get "type" by string, because its a method as well.
pc.Attribute(image_plane_shape + ".type").set(2)
image_plane_shape.imageName.set(
context["representation"]["data"]["path"]
)
image_plane_shape.useFrameExtension.set(1)
start_frame = pc.playbackOptions(q=True, min=True)
end_frame = pc.playbackOptions(q=True, max=True)
image_plane_shape.frameOffset.set(1 - start_frame)
image_plane_shape.frameIn.set(start_frame)
image_plane_shape.frameOut.set(end_frame)
new_nodes.extend(
[image_plane_transform.name(), image_plane_shape.name()]
)
return new_nodes