def createUfePathSegment(usdPath): """ Create an UFE path from a given usd path. Args: usdPath (str): The usd path to use Returns : PathSegment of the given usdPath """ return ufe.PathSegment(usdPath, usdRuntimeID, usdSeparator)
def createUfePathSegment(mayaPath): """ Create an UFE path from a given maya path. Make sure that it starts with |world. We are currently supporting Maya nodes being at the top of UFE Paths (03/26/2018) Args: mayaPath (str): The maya path to use Returns : PathSegment of the given mayaPath """ if not mayaPath.startswith("|world"): mayaPath = "|world" + mayaPath return ufe.PathSegment(mayaPath, mayaRuntimeID, mayaSeparator)
def testObservableScene(self): # Setup ca = ufe.PathComponent("a") cb = ufe.PathComponent("b") cc = ufe.PathComponent("c") sa = ufe.PathSegment([ca], 3, '/') sab = ufe.PathSegment([ca, cb], 1, '|') sc = ufe.PathSegment([cc], 2, '/') a = ufe.Path(sa) b = ufe.Path(sab) c = ufe.Path([sab, sc]) itemA = TestSceneItem(a) itemB = TestSceneItem(b) itemC = TestSceneItem(c) # End Setup # No observers from the test yet, but Maya could have observers # created on startup initialNbObservers = ufe.Scene.nbObservers() snObs = TestObserver() # Add observer to the scene. ufe.Scene.addObserver(snObs) # Order of expected notifications. No notifications yet. self.checkNotifications(snObs, [0, 0, 0, 0, 0, 0]) self.assertEqual(ufe.Scene.nbObservers() - initialNbObservers, 1) self.assertTrue(ufe.Scene.hasObserver(snObs)) ufe.Scene.notify(ufe.ObjectAdd(itemA)) # we should now have an ObjectAdd notification self.checkNotifications(snObs, [1, 0, 0, 0, 0, 0])
def _createPrim(self, underItem, primType, expectedPath): ''' Helper that creates a prim of the given type under the given item, and return its item. ''' # create a proxy shape and add a Cone prim proxyShapeContextOps = ufe.ContextOps.contextOps(underItem) proxyShapeContextOps.doOp(['Add New Prim', primType]) primPath = ufe.Path([ ufe.PathString.path("|stage|stageShape").segments[0], ufe.PathSegment(expectedPath, mayaUsdUfe.getUsdRunTimeId(), "/") ]) return ufe.PathString.string(primPath)
def createUfePathSegment(mayaPath): """ Create a UFE path from a given maya path and return the first segment. Args: mayaPath (str): The maya path to use Returns : PathSegment of the given mayaPath """ if ufeUtils.ufeFeatureSetVersion() >= 2: return ufe.PathString.path(mayaPath).segments[0] else: if not mayaPath.startswith("|world"): mayaPath = "|world" + mayaPath return ufe.PathSegment(mayaPath, mayaUsdUfe.getMayaRunTimeId(), mayaSeparator)
def createPrim(self, underItem, underPath, primType, expectedPath): ''' Helper that creates a prim of the given type under the given item, and return its item. ''' proxyShapeContextOps = ufe.ContextOps.contextOps(underItem) proxyShapeContextOps.doOp(['Add New Prim', primType]) primPath = ufe.Path([ underPath.segments[0], ufe.PathSegment(expectedPath, mayaUsd.ufe.getUsdRunTimeId(), "/") ]) primItem = ufe.Hierarchy.createItem(primPath) prim = mayaUsd.ufe.ufePathToPrim(ufe.PathString.string(primPath)) return prim, primItem, primPath
def onCreate(self, *args): frontPath = self.path.popSegment() attr = self.prim.GetAttribute(self.attrName) attrLabel = getPrettyName( self.attrName) if self.useNiceName else self.attrName attrType = attr.GetMetadata('typeName') singleWidgetWidth = mel.eval( 'global int $gAttributeEditorTemplateSingleWidgetWidth; $gAttributeEditorTemplateSingleWidgetWidth += 0' ) with AEUITemplate(): # Because of the way the Maya AE template is defined we use a 5 column setup, even # though we only have two fields. We resize the main field and purposely set the # adjustable column to 3 (one we don't have a field in). We want the textField to # remain at a given width. rl = cmds.rowLayout(nc=5, adj=3) with LayoutManager(rl): cmds.text(nameTxt, al='right', label=attrLabel, annotation=attr.GetDocumentation()) cmds.textField(attrTypeFld, editable=False, text=attrType, backgroundColor=[0.945, 0.945, 0.647], font='obliqueLabelFont', width=singleWidgetWidth * 1.5) # Add a menu item for each connection. cmds.popupMenu() for c in attr.GetConnections(): parentPath = c.GetParentPath() primName = parentPath.MakeRelativePath( parentPath.GetParentPath()) mLabel = '%s%s...' % (primName, c.elementString) usdSeg = ufe.PathSegment(str(c.GetPrimPath()), mayaUsdUfe.getUsdRunTimeId(), '/') newPath = (frontPath + usdSeg) newPathStr = ufe.PathString.string(newPath) cmds.menuItem( label=mLabel, command=lambda *args: showEditorForUSDPrim(newPathStr))