[Bf-committers] Python Access to some properties of nodes

Lukas Tönne lukas.toenne at gmail.com
Thu Dec 20 11:10:05 CET 2012


In the bNodeSocket DNA we currently have a sock->link pointer which
directly points to a bNodeLink. However, this only works for input
links with the current connectivity model (input only has one possible
link, outputs can have many). Future nodes can use a different
connectivity model, then this pointer would be pretty useless. Also
this pointer is not totally reliable in all cases, e.g. can be invalid
during node updates. For this reason i would discourage using this
pointer and always use the nodetree->links list to find connections
from/to a specific socket. Eventually i'd like to remove the
sock->link pointer as well to make maintenance easier and remove a
potential error source.

For getting connections of a socket i would instead suggest to add a
number of python methods to the NodeSocket class (can be done in
bpy_types.py). With python this can be done very nicely:

class NodeSocket(StructRNA, metaclass=RNAMeta):
    __slots__ = ()

    # returns a list of links to or from this socket
    def get_links(self):
        return [link for link in self.id_data.links if
link.from_socket == self or link.to_socket == self]

If necessary such functions could also be added to the RNA directly.


On Thu, Dec 20, 2012 at 3:30 AM, Dan Eicher <dan at trollwerks.org> wrote:
> Assuming Campbell's OK with it it wouldn't be too terribly hard to add
> something like Socket.link to push the iterating over the links into C
> since IIRC that's how it works internally.
>
> I personally won't have time to mess with it until after New Years but if
> someone else wants to bang their head against makesrna and node tree
> structs it might turn out to be as simple as wrapping an existing function
> (though I do seem to recall that the node links were a little tricky to
> wrap originally).
>
> Dan
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers


More information about the Bf-committers mailing list