// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // // // Creation Date: October 2001 // // Written by: cpam // // Procedure Name: // createAnnotation // // Description: // Builds an annotation node with the given string // // Input Arguments: // None. // // Return Value: // None. global proc createAnnotation(string $annotation) { //get the object to annotate string $object[] = `ls -sl`; //make sure it's a valid transform node string $checkIfTransform[] = `ls -sl -typ transform $object[0]`; if (1 == size($checkIfTransform)) { // carry on if it is and calculate the offset for the annotation // based on the object's bounding box float $bbox[] = `xform -q -ws -bb $object[0]`; $pos[0] = abs($bbox[3] - $bbox[0]); $pos[1] = abs($bbox[4] - $bbox[1]); $pos[2] = abs($bbox[5] - $bbox[2]); // create a locator for easier manipulation $locator = `spaceLocator -n "annotationLocator#" `; xform -ws -t ($bbox[0]+($pos[0]/2)) ($bbox[1]+($pos[1]/2)) ($bbox[2]+($pos[2]/2)); parent $locator $object[0]; // sort the sides of the bounding box from lowest to highest so // that the annotation has a more predictable and consistent offset $pos = `sort $pos`; // add annotation select -r $locator; $annotationNode = `annotate -tx $annotation -p ($bbox[0]+($pos[2])) ($bbox[1]+($pos[2])) ($bbox[2]+($pos[2]))`; // get parent transform of annotation string $transform[] = `listRelatives -parent $annotationNode`; // parent annotation to locator parent $transform[0] $locator; select -r $annotationNode; } else { error (uiRes("m_createAnnotation.kErrorInvalidObject")); } }