def listParentName( entity ): parent = Hammer.getEntity( entity['parentId'] ) self.path.append( parent['name'] + '/' ) if parent['entityType'] in ['Show', 'BaseEntity']: return listParentName( parent )
def __addActionsToMenuBar( self, tree, parent ): entityId = tree.getCurrentItemId() if entityId: entity = Hammer.getEntity( entityId ) actions = Hammer.getActions( entity ) arg = {} parent.clean() if actions: for action in actions: parent.add( Anvil.core.Button(name=action.__name__, cmd=Forge.core.Process.partial( action, entity, arg, self ), w=110) )
def _doAction( self, entity, arg, ui ): import nuke import Hammer self.returnValue = [] entitiesInfo = Hammer.Hnuke.Actions.GetEntitiesInfoFromScene( entity=entity, arg=arg, ui=ui ).returnValue for entityInfo in entitiesInfo: currentEntityId = entityInfo.knob('entityId').value() self.returnValue.append( Hammer.getEntity(currentEntityId) )
def _doAction(self, entity, arg, ui): import maya.cmds import Hammer self.returnValue = [] entitiesInfo = Hammer.Hmaya.Actions.GetEntitiesInfoFromScene(entity=entity, arg=arg, ui=ui).returnValue for entityInfo in entitiesInfo: currentEntityId = maya.cmds.getAttr("%s.entityId" % (entityInfo)) self.returnValue.append(Hammer.getEntity(currentEntityId))
def setHierarchyList( childrenIds, parentId ): for childrenId in childrenIds: child = Hammer.getEntity( childrenId ) entityType = child.getType() parent = None if parentId: parent = Hammer.getEntity( parentId ).getName() hierarchyList.append( { 'name':child.getName(), 'id':childrenId, 'iconPath':'../core/icon/%s%s.png' %( entityType[0].lower(), entityType[1:] ), 'tooltip':'%s | entityId:%s, name:%s, assetId:%s' %( child.getType(), child.getEntityId(), child.getName(), child.getAssetId() ), 'iconTooltip':'type:%s' %( child.getType() ), 'parent':parent, 'parentId':parentId, } ) subChildren = child.getChildrenId() child.getParentId() if subChildren: setHierarchyList( subChildren, childrenId )
def __addActionsToMenuBar( self, tree, parent ): entityId = tree.getCurrentItemId() itemName = tree.getCurrentItemName() version = eval( itemName.split( ':' )[0] ) if entityId: entity = Hammer.getEntity( entityId ) entity.setVersion( version=version ) actions = Hammer.getActions( entity, 'Version' ) actions += Hammer.getActions( entity ) arg = {} parent.clean() if actions: for action in actions: if action.__name__ in [ 'approved', 'setCurrent', 'openScene', 'openSourceScene', 'get' ]: parent.add( Anvil.core.Button(name=action.__name__, cmd=Forge.core.Process.partial( action, entity, arg, self ), w=110) )
def editEntity( self, entityId, version=None, approved=None ): import Hammer entity = Hammer.getEntity( entityId ) newVersion = entity['version'] if version: newVersion = version newApproved = entity['approved'] if approved: newApproved = approved # define data with open( self.db, 'r' ) as file: data = file.readlines() # grab entity entityLine = self.__getDbLine( entity['entityId'] ) data[entityLine] = str({ 'entityId':entity['entityId'], 'name':entity['name'], 'type':entity['entityType'], 'path':entity['path'], 'version':newVersion, 'descriptions':entity['descriptions'], 'approved':newApproved, 'currentUser':entity['currentUser'], 'parentId':entity['parentId'], 'childrenId':entity['childrenId'], 'copyId':entity['copyId'], 'referenceId':entity['referenceId'], 'assetId':entity['assetId'], 'masterAssetId':entity['masterAssetId'], 'dependencyId':entity['dependencyId'], 'bundleId':entity['bundleId'], 'sources':entity['sources'], }) + '\n' with open( self.db, 'w' ) as file: file.writelines( data )
def upFolder( arg ): import Hammer if arg._currentEntityId != 1: # set current entityId to parentId entity = Hammer.getEntity( arg._currentEntityId ) arg._currentEntityId = entity.getParentId() # remove last folder in the urlPath field folders = arg.textfield_urlPath.getValue().split( '/' ) for i in [0,-2,-1]: del folders[i] path = '/' for folder in folders: path += '%s/' %(folder) arg.textfield_urlPath.setValue( path ) # rebuild tree arg._buildTreeEntity( entityIdOverride=True )
def _buildTreeEntity( self, entityIdOverride=False ): if not entityIdOverride: self._currentEntityId = self.__getEntityIdFromPath() entity = Hammer.getEntity( self._currentEntityId ) hierarchyList = [] def setHierarchyList( childrenIds, parentId ): for childrenId in childrenIds: child = Hammer.getEntity( childrenId ) entityType = child.getType() parent = None if parentId: parent = Hammer.getEntity( parentId ).getName() hierarchyList.append( { 'name':child.getName(), 'id':childrenId, 'iconPath':'../core/icon/%s%s.png' %( entityType[0].lower(), entityType[1:] ), 'tooltip':'%s | entityId:%s, name:%s, assetId:%s' %( child.getType(), child.getEntityId(), child.getName(), child.getAssetId() ), 'iconTooltip':'type:%s' %( child.getType() ), 'parent':parent, 'parentId':parentId, } ) subChildren = child.getChildrenId() child.getParentId() if subChildren: setHierarchyList( subChildren, childrenId ) setHierarchyList( entity.getChildrenId(), None ) # tree init self.tree_hierarchy.add( hierarchyList )
def _buildTreeEntity( self, entityId ): entity = Hammer.getEntity( entityId ) hierarchyList = [] # versions init for version in range( len(entity['approved']) ): version = version + 1 if entity['approved'][version]: iconType = 'approved' else: iconType = 'unapproved' if version == entity['version']: iconType += 'Actif' source = '' if entity['source']: source = entity['source'][version] hierarchyList.append( { 'name':' %i : %s' %( version, entity['descriptions'][version] ), 'id':entity['entityId'], 'iconPath':'../core/icon/%s.png' %( iconType ), 'tooltip':'source : %s ' %(source), 'iconTooltip':'', 'parent':None, 'parentId':None, } ) # tree init self.tree_hierarchy.add( hierarchyList )
def listAllChildren( parentId ): childrens = Hammer.getEntity( parentId ).getChildrenId() if childrens: for children in childrens: childrenList.append( children ) listAllChildren( children )
def menuBar( self, tree ): entityId = tree.getCurrentItemId() if entityId: entity = Hammer.getEntity( entityId ) print entity.getName()
def checkMatch( entityId, name ): childrenIds = Hammer.getEntity( entityId ).getChildrenId() for childrenId in childrenIds: if Hammer.getEntity( childrenId ).getName() == name: return childrenId return None