1
$\begingroup$

I have a Dictionary that is created by a script running in a subprogram node. I want to output the dict from the node, but it seems Animation Nodes doesn't support regular python dictionaries. Apparently it uses its own ANstruct and various struct nodes instead? So I am trying to output my dict as an anstruct. I set the script node to output a struct type with the same name as the dict, but it is empty.

What do I do to get my dict to be a struct? Or is there any other method to handle this problem?

$\endgroup$

1 Answer 1

2
$\begingroup$

Looks like you can use ANStruct() in place of a normal dictionary and add to it with the usual commands. So instead of dict = {}, do dict = ANStruct().

But there is a big caveat that doesn't seem to be documented anywhere. When working with a regular dict, you'd add to it with: dict['key'] = value. But ANStruct actually has a 2 part key, with the first part of the key being the Animation Nodes Type (ie, Text, Integer, Text List, etc). So you actually need dict[('Type', 'key')] = value

If you don't have the two part key, you'll get errors when trying to use the outputted Struct with the various Struct nodes, or when trying to Print it.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .