From fe33f76da493a95879965856f560ae04a690b5e4 Mon Sep 17 00:00:00 2001 From: Toke Jepsen Date: Wed, 26 Jun 2019 18:20:54 +0100 Subject: [PATCH] Create load_image_plane.py --- pype/plugins/maya/load/load_image_plane.py | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 pype/plugins/maya/load/load_image_plane.py diff --git a/pype/plugins/maya/load/load_image_plane.py b/pype/plugins/maya/load/load_image_plane.py new file mode 100644 index 0000000000..1d9008e09f --- /dev/null +++ b/pype/plugins/maya/load/load_image_plane.py @@ -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