-
Notifications
You must be signed in to change notification settings - Fork 347
Python API documentation #1898
-
Hey guys,
New user and new python user here.
I'm looking to bring in some animation nodes with python. so far I've cobbled together something that brings them in but they are all coming in on top of each other so I'm trying to set the location so that I can just see them better. I have not got onto linking them together. does anyone know a good resource to use regarding the API for AN or if anyone has done any python scripting id be very grateful for help I'm on the second page of google here!
here is the code I'm running
`for p_num in phase:
collection = bpy.data.collections.new('phase ' + str( p_num ))
bpy.context.scene.collection.children.link(collection)
bpy.ops.screen.userpref_show("INVOKE_DEFAULT")
area = bpy.context.window_manager.windows[-1].screen.areas[0]
area.type = "NODE_EDITOR"
bpy.ops.node.new_node_tree(name='phase ' + str(p_num))
#bpy.data.node_groups["NodeTree " + str(p_num)].name = ("phase " + str(p_num))
nodes = bpy.ops.node
node = nodes.add_node(type="an_TimeInfoNode")
node.location = (100, 100)
time_node = nodes.add_node(type="an_FloatMathNode")
time_node.location = (200, 100)`
I'm just trying to do it the "normal" way I've done it but of course this doesn't work. I've hacked a way of getting the nodes in by opening a new window with the node area selected and that lets me insert the nodes that way but of course id rather not have 13 windows open in the final version but hopefully this gives you an idea of what I'm trying to do.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 6 replies
-
Don't use bpy.ops.* operators for those uses cases, as they are context sensitive. Use the data API as demonstrated in https://devtalk.blender.org/t/how-to-connect-nodes-using-script-commands/11567.
Beta Was this translation helpful? Give feedback.
All reactions
-
I want to do that, but using Python. Because I want to associate to other API. I am not a expert in Python, but I already use the Python API for Blender to add inputs and outputs in "Shader Editor". I tried to use the same logic but I could not it.
Beta Was this translation helpful? Give feedback.
All reactions
-
@MayconSilva7 bpy.context.scene.node_tree is the compositor node tree, add the node tree through the data API and assing the result to a variable:
test_node_tree = D.node_groups.new("Test", "an_AnimationNodeTree")
test_vector_node = test_node_tree.nodes.new("an_VectorMathNode")
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you very much. It works.
Kind regards.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi. Sorry, to disturb you again. I would like to know how can I change the settings of Loop Input for example as shown in the following code and image:
#Create Loop Input node
loop = test_node_tree.nodes.new("an_LoopInputNode", )
loop.outputs[2].text = "an_GenericSocket"
I want to add a Generic Interator and set it as Generic. I tried other ways but I did not get it.
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions
-
@MayconSilva7 Try loopNode.newIterator("Generic List", "Iterator Name")
Beta Was this translation helpful? Give feedback.