4
$\begingroup$

Is it possible to export a program created with the animation node as a python script?

I would like to convert an animation node into a python script.

I am not familiar with Python script, so I would like to do it automatically if possible, but you can do it manually.

$\endgroup$

1 Answer 1

5
$\begingroup$

Animation Nodes provide operators that provides the execution code of the current node tree. You can find that operator under the Developer panel, by pressing the Write button, the execution code of the selected node tree is written to a text block called Execution Code. For instance, the following node tree:

Example Node Tree

Have an execution code:

import numpy, sys, bpy
import itertools
from time import perf_counter as getCurrentTime
from mathutils import Vector, Matrix, Quaternion, Euler
AN = animation_nodes = sys.modules.get('animation_nodes')
from animation_nodes.data_structures import *
from animation_nodes import algorithms

nodes = bpy.data.node_groups['NodeTree'].nodes
_y52bwsmno0e080h = nodes['Random Vector']
_csk7p8pg5vv2v5d = nodes['Vector Math']
_8aspl5k05rbhwxn = nodes['Separate Vector']
_seed_y520 = _y52bwsmno0e080h.inputs[0].getValue()
_scale_y521 = _y52bwsmno0e080h.inputs[1].getValue()



# Node: 'NodeTree' - 'Random Vector'
_seed = _seed_y520 + 25642 * _y52bwsmno0e080h.nodeSeed
_randomVector_y522 = algorithms.random.getRandom3DVector(_seed, _scale_y521)

# Node: 'NodeTree' - 'Vector Math'
_result_csk1 = Vector((abs(_randomVector_y522[0]), abs(_randomVector_y522[1]), abs(_randomVector_y522[2])))

# Node: 'NodeTree' - 'Separate Vector'
_x_8as1 = _result_csk1[0]

# Node: 'NodeTree' - 'Viewer'
_38xn88352kup1e3.execute(_x_8as1)

Notice that variables like _seed_y520 and _scale_y521 needs to be substituted with the seed and scale of the Random Vector node respectively.

Another example, a subprograms like this group:

Example Subprogram

Have an execution code:

import math, numpy, sys, bpy
import itertools
from time import perf_counter as getCurrentTime
from mathutils import Vector, Matrix, Quaternion, Euler
AN = animation_nodes = sys.modules.get('animation_nodes')
from animation_nodes.data_structures import *
from animation_nodes import algorithms

nodes = bpy.data.node_groups['NodeTree'].nodes
_o7ggcrgv1v0zeqz = nodes['Group Input']
_71b912e7wlqq8tj = nodes['Float Math']
_uyl54rvlbgh0b0p = nodes['Group Output']
_b_71b1 = _71b912e7wlqq8tj.inputs[1].getValue()
__socket_False_1_uyl = None



def main(group_input_0):
    global _b_71b1

    # Node: 'NodeTree' - 'Float Math'
    _result_71b2 = group_input_0 + _b_71b1


    return _result_71b2

The output code will not work out of the box as you might expect it, it depends on the animation_nodes module, functions defined by subprograms as well as values defined in the node tree interface.

$\endgroup$

You must log in to answer this question.

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