I am working on limited C4D python api understanding, so forgive what may be an noob question.
I am building a specialized script for my personal workflow to extract parameter data from a project build. The goal being that it loops through all the scene objects, tags, and parameters, then checks if parameter is not default (or has been changed), then returns a tab delimited string consisting of Object name / Parameter name / Parameter Value
The resulting list I like to use as a notes reference for when I make my video tutorials. It helps me remember what I changed to achieve final result. So only the changed parameters are required.
Currently I have the Object/parameter loop, name & value retrieval functioning by cobbling together some snippets I've found online, and from my own knowledge. Some checks and adjustments made to results along the way as well. What I am having issues with are the parameter description name attributes located in this list: https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/Description/index.html#c4d.Description
So far I have tried using changed and default to check parameter, but both fail and return None instead of True/False I assume I am using them improperly or there may be a limitation to how I want to use them. As I read in the help docs (url above), changed returns bool if entry is changed, and default returns the parameter default value. Changed would be an easier use, but if I have to do a...
default != "value"
...kind of check, that's ok too.
c4d.DESC_CHANGED
c4d.DESC_DEFAULT
Any insight as to how I can check for a parameter that in not default or has changed would be appreciated.
This is the code I have so far, and I am aware that some parameters that are Gradients, Time, Custom, etc.. are not handled with this code currently. Next hurdle to cross when I get to that though.
import c4d
from c4d import gui
# Main function
def main():
o = op
if o is not None:
recurse(o)
def recurse(o):
obj = o
if obj is not None:
#Misc variables
tab = "\t"
#Header
print "Name\tParameter\tValue\tParam ID"
#Print object name
on = obj.GetName()
print on
#Print object PSR
print on + "\t" + "Position\t" + str(obj[c4d.ID_BASEOBJECT_REL_POSITION])
print on + "\t" + "Scale\t" + str(obj[c4d.ID_BASEOBJECT_REL_SCALE])
print on + "\t" + "Rotation\t" + str(obj[c4d.ID_BASEOBJECT_REL_ROTATION])
print on + "\t" + "Vis Editor\t" + str(obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR])
print on + "\t" + "Vis Renderer\t" + str(obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER])
#Display color check/conversion and print
uc = obj[c4d.ID_BASEOBJECT_USECOLOR]
if uc == 2:
dc = obj[c4d.ID_BASEOBJECT_COLOR]
print on + "\t" + "Display Color\tVector(" + str(dc[0]*255) + ", " + str(dc[1]*255) + ", " + str(dc[2]*255) + ")"
#Get object data
data = obj.GetData()
#Get object description
description = obj.GetDescription(c4d.DESCFLAGS_DESC_0)
for bc, paramid, groupid in description:
#Process object parameters
isgroup = paramid[0].dtype==c4d.DTYPE_GROUP
if isgroup:
continue
group = groupid[0].id
filtergroup = group!=c4d.Tbaselist2d and group!=c4d.FALLOFF_GROUPFALLOFF
idname = bc[c4d.DESC_IDENT]
if idname:
filtergroup = filtergroup and not idname.startswith("ID_BASEOBJECT")
if filtergroup:
if bc[c4d.DESC_NAME] and bc[c4d.DESC_IDENT]:
#-------------------------------------------
#ATTEMPTS TO CHECK FOR PARAMETER CHANGED OR DEFAULT
#-------------------------------------------
#Fails to return changed correctly
#if bc[c4d.DESC_CHANGED] == 1:
#Fails to return default correctly
#if bc[c4d.DESC_DEFAULT] == 1:
#-------------------------------------------
try:
#Adjust color float to 255 range
vec = obj[paramid]
if "Color" in bc[c4d.DESC_NAME] and "Vector" in str(vec):
vec = obj[paramid]
val = "Vector(" + str(vec[0]*255) + ", " + str(vec[1]*255) + ", " + str(vec[2]*255) + ")"
else:
val = str(obj[paramid])
print on + "\t" + bc[c4d.DESC_NAME] + "\t" + val
except:
print on + "\t" + bc[c4d.DESC_NAME] + ": PARAMETER REQUIRES MANUAL EXTRACTION"
#Get object tags
tags = obj.GetTags()
for t in tags:
tn = t.GetTypeName()
if tn is not "" or None:
#Add spacer in output
print ""
#Get tag name
print t.GetTypeName()
try:
#Process tag parameters
tdesc = t.GetDescription(c4d.DESCFLAGS_DESC_0)
for bc, paramid, groupid in tdesc:
#-------------------------------------------
#ATTEMPTS TO CHECK FOR PARAMETER CHANGED OR DEFAULT
#-------------------------------------------
#Fails to return changed correctly
#if tn[c4d.DESC_CHANGED] == 1:
#Fails to return default correctly
#if tn[c4d.DESC_DEFAULT] == 1:
#-------------------------------------------
isgroup = paramid[0].dtype==c4d.DTYPE_GROUP
if isgroup:
continue
group = groupid[0].id
filtergroup = group!=c4d.Tbaselist2d and group!=c4d.FALLOFF_GROUPFALLOFF
idname = bc[c4d.DESC_IDENT]
if idname:
filtergroup = filtergroup and not idname.startswith("ID_BASEOBJECT")
if filtergroup:
if bc[c4d.DESC_NAME] and bc[c4d.DESC_IDENT]:
try:
#val = tn+"[c4d."+str(idname)+"]"
print tn + "\t" + bc[c4d.DESC_NAME] + "\t" + str(t[paramid])
except:
print tn + "\t" + bc[c4d.DESC_NAME] + ": PARAMETER REQUIRES MANUAL EXTRACTION"
except:
print "--UNKNOWN PARAMETER--"
#Check for child object
d = obj.GetDown()
if d is not None:
recurse(d)
#Get next object
n = obj.GetNext()
if n is not None:
recurse(n)
else:
print "Error: Select one starting object first."
# Execute main()
if __name__=='__main__':
main()