|
""" |
|
Name-US:List tags on object |
|
Description-US:List all tags attached to the selected object, by name and plugin ID |
|
""" |
|
import c4d |
|
|
|
""" |
|
This script lists all tags attached to the selected object, by name and plugin ID. |
|
It also shows if a tag is visible or invisible. |
|
""" |
|
|
|
def GetPluginName(pluginId, pluginType=c4d.PLUGINTYPE_ANY): |
|
# Check if it's the ID of a registered plugin |
|
foundPlugin = c4d.plugins.FindPlugin(pluginId, type=pluginType) |
|
if foundPlugin is not None: |
|
return foundPlugin.GetName() |
|
# It's not the ID of a registered plugin, but might still be a builtin |
|
# Try to allocate a new instance, and get type name |
|
newObj = c4d.BaseList2D(pluginId) |
|
if newObj is not None: |
|
return str(type(newObj).__name__) |
|
# No idea what this is |
|
return "N/A" |
|
|
|
|
|
def GetPluginFlags(bl): |
|
"""Return string with all plugin flags of a given BaseList2D element |
|
|
|
@param bl The BaseList2D element (e.g. BaseObject, BaseTag, |
|
BaseVideoPost, BaseMaterial, BaseShader, et cetera) |
|
|
|
@return A string containing all the identified plugin flags |
|
""" |
|
if bl is None: |
|
return '' |
|
|
|
flagInfoDict = { |
|
c4d.PLUGINTYPE_ANY : { |
|
# General plugin flags |
|
c4d.PLUGINFLAG_HIDE : 'PLUGINFLAG_HIDE', |
|
c4d.PLUGINFLAG_SMALLNODE : 'PLUGINFLAG_SMALLNODE', |
|
c4d.PLUGINFLAG_HIDEPLUGINMENU : 'PLUGINFLAG_HIDEPLUGINMENU', |
|
c4d.PLUGINFLAG_REFRESHALWAYS : 'PLUGINFLAG_REFRESHALWAYS' |
|
}, |
|
c4d.PLUGINTYPE_TAG : { |
|
# TagData flags |
|
c4d.TAG_VISIBLE : 'TAG_VISIBLE', |
|
c4d.TAG_MULTIPLE : 'TAG_MULTIPLE', |
|
c4d.TAG_HIERARCHICAL : 'TAG_HIERARCHICAL', |
|
c4d.TAG_EXPRESSION : 'TAG_EXPRESSION', |
|
c4d.TAG_TEMPORARY : 'TAG_TEMPORARY', |
|
c4d.TAG_TEMPORARY : 'TAG_TEMPORARY', |
|
c4d.TAG_ADDTOTAKEGROUP : 'TAG_ADDTOTAKEGROUP' |
|
} |
|
} |
|
|
|
# Get plugin type & info |
|
blInfo = bl.GetInfo() |
|
|
|
# General flags |
|
flagList = [] |
|
for flag in sorted(flagInfoDict[c4d.PLUGINTYPE_ANY].keys()): |
|
if blInfo&flag: |
|
flagList.append(flagInfoDict[c4d.PLUGINTYPE_ANY][flag]) |
|
|
|
# Iterate dictionary to find out which flags are set |
|
# Store set flags in list |
|
for flag in sorted(flagInfoDict[c4d.PLUGINTYPE_TAG].keys()): |
|
if blInfo&flag: |
|
flagList.append(flagInfoDict[c4d.PLUGINTYPE_TAG][flag]) |
|
|
|
# Build result string |
|
if len(flagList) == 0: |
|
resultStr = 'NONE' |
|
else: |
|
resultStr = '|'.join(flagList) |
|
|
|
return resultStr |
|
|
|
|
|
def ListTagsOnObject(op): |
|
resultStr = 'Tags on object "' + op.GetName() + '": ' |
|
|
|
# Iterate tags on op |
|
tagIndex = 0 |
|
tag = op.GetFirstTag() |
|
while tag: |
|
# Get name and plugin ID |
|
pluginType = tag.GetType() |
|
resultStr += str(tagIndex) + ': "' + tag.GetName() + '" (id=' + str(pluginType) + '; type=' + GetPluginName(pluginType) |
|
|
|
# List plugin flags |
|
resultStr += '; flags=' + GetPluginFlags(tag) + ')' |
|
|
|
# Continue iteration |
|
tag = tag.GetNext() |
|
|
|
# Add a separator if there's another tag to come |
|
if tag is not None: |
|
resultStr += ', ' |
|
|
|
# Increase index |
|
tagIndex += 1 |
|
|
|
return resultStr |
|
|
|
|
|
def main(): |
|
selectedObjects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) |
|
|
|
if len(selectedObjects) > 0: |
|
print('Listing tags on ' + str(len(selectedObjects)) + ' objects:') |
|
for theObject in selectedObjects: |
|
print(ListTagsOnObject(theObject)) |
|
else: |
|
print('No objects are selected. Select at least one object and execute this script again!') |
|
|
|
|
|
def state(): |
|
if doc.GetActiveObject() is None: |
|
return False |
|
return True |
|
|
|
|
|
if __name__=='__main__': |
|
main() |
Example console output: