A little late on this one. In case anyone is looking for an answer.
def getTemplateResourceType():
"""Resource type string."""
return 'component-template'
def getTemplateFilter():
"""Filter throw away for template types."""
return lambda x: bool(x.getResourceType() == getTemplateResourceType())
def getContext(event):
"""Context."""
return event.source.parent.getAppContext()
def getProjectReference(event):
"""Project reference."""
return getContext(event).getProject()
def getTemplateFolderMembers(event, folderName):
"""
Returns a list of resource objects.
# Requires an event object and a template folder path.
# i.e. 'tank_components'
"""
if event and folderName:
context = getContext(event)
project_obj = context.getProject()
# Get the folders resource id from the Template Manager.
folder_resource_id = context.getTemplateManager().getId(folderName).getLeft()
# Get the folder resource_object by the id.
resource = project_obj.getResource(folder_resource_id)
# get the folder uuid.
folder_uuid = resource.getDataAsUUID()
# returns an array of template objects under the specified folder.
return project_obj.browseFolder('fpmi', [getTemplateResourceType()], folder_uuid)
return []
def getAllTemplates(event):
"""
Returns a list of all template resource objects.
# Requires an event object.
"""
if event:
# Get all resources.
resources = getProjectReference(event).getResources()
# returns an array of template objects.
return filter(getTemplateFilter(), resources)
return []
#example
for resource in getAllTemplates(event):
print resource.getName()
#example
folder_name = 'tank_components'
for resource in getTemplateFolderMembers(event, folder_name):
print resource.getName()