Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python API documentation #1898

Unanswered
ChristianRnD asked this question in Q&A
Jan 3, 2023 · 1 comments · 6 replies
Discussion options

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.

You must be logged in to vote

Replies: 1 comment 6 replies

Comment options

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.

You must be logged in to vote
6 replies
Comment options

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.

image

Comment options

@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")
Comment options

Thank you very much. It works.

Kind regards.

Comment options

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"

image

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.

Comment options

@MayconSilva7 Try loopNode.newIterator("Generic List", "Iterator Name")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /