Iterate Attributes
-
On 16/08/2017 at 04:30, xxxxxxxx wrote:
Hello,
I am trying to iterate trough tag attributes with a script:
import c4d
def main() :
if op is None: return
for tag in op.GetTags() :
bc = tag.GetDataInstance()
for value in bc:
print valueif __name__=='__main__':
main()It all goes well until it comes to some "unsupported" attributes, likes of Weight tag, Visual Selector tag...
It gives an error with such tags stating:
"AttributeError: Parameter value not accessible (object unknown in Python)"I really have no idea how to bypass this. Is there a better way of doing this? Or am I missing something obvious?
Thanks,
Sandi -
On 16/08/2017 at 05:09, xxxxxxxx wrote:
I guess this thread will answerd your ask https://developers.maxon.net/forum/topic/5936/6027_how-to-list-keys-for-a-basecontainer&PID;=25407#25407
-
On 16/08/2017 at 08:13, xxxxxxxx wrote:
That did it, thank you!
-
On 17/08/2017 at 03:15, xxxxxxxx wrote:
The AttributeError stating "Parameter value not accessible (object unknown in Python)" means the Python API doesn't support the data type for the parameter.
So no data value can be given for such parameter.To bypass this error you can catch and process it like this:
def main() : if op is None: return for tag in op.GetTags() : bc = tag.GetDataInstance() print tag # Loops through parameters dataLen = len(bc) for dataIdx in xrange(dataLen) : dataID = bc.GetIndexId(dataIdx) # Retrieves parameter ID for the given index dataType = bc.GetType(dataID) # Retrieves parameter data type try: data = bc[dataID] # Tries tro get parameter data except AttributeError: print dataID, dataType, "Data not supported" continue # Prints information on parameter data print dataID, dataType, data
-
On 17/08/2017 at 05:59, xxxxxxxx wrote:
That's even more elegant, thank you Yannick!