Jump to content

Sign in to follow this  
LayKing

Iterator in Xpresso Python node

Recommended Posts

Hi guys! I need your help!
How to write an Iterator in Xpresso Python node that performs the same function as the Iterator node in Xpresso?

Share this post


Link to post
Share on other sites

Iteration is like a for loop

 

import c4d
#Welcome to the world of Python


def main():
    top = doc.SearchObject('top')
    
    my_list = top.GetChildren()
    
    for item in my_list:
        # do something eg
        name = item.GetName()
        print name
        

console.png.f5c7a5563895566e9db8b5b30f8a60e9.png

Share this post


Link to post
Share on other sites
15 hours ago, jed said:

Iteration is like a for loop

 

Yes, but what happens if the Python node has an output port? And this output port is changed within the loop?

 

In this case, the nodes connected to this output would need to be evaluated for each loop step. But how would the Python node tell the rest of the XPresso circuit that this is needed, or when to perform one evaluation step?

 

Share this post


Link to post
Share on other sites

Can you give an example of what you're trying to do.

Share this post


Link to post
Share on other sites
2 hours ago, jed said:

Can you give an example of what you're trying to do.

 

Who, the OP or me?

 

(I'm not trying to do anything, if needed I would just program something from scratch and not in XPresso. I don't believe an iterator with outports can be written in the way a native iterator is working, but maybe I'm wrong, that would be interesting and worth remembering!)

 

Share this post


Link to post
Share on other sites
2 hours ago, Cairyn said:

Who, the OP or me?

sorry - got my wires crossed

 

In general, I either use all Python or all XP. I have not had much success interfacing XP iteration and Python - instead of executing once per frame, the Python node sees every iteration step as an event and recalculates.

Share this post


Link to post
Share on other sites
8 minutes ago, jed said:

sorry - got my wires crossed

 

In general, I either use all Python or all XP. I have not had much success interfacing XP iteration and Python - instead of executing once per frame, the Python node sees every iteration step as an event and recalculates.

Well, any kind of tag that is executed during tree evaluation is calculated fairly often - for every redraw, especially in subframe calculations, but also for viewport changes. So, "once per frame" calls are probably in the minority.

Share this post


Link to post
Share on other sites
  • Topic Author
  •  

    Thank you guys for your feedback! Actually I tried to find out something different. In fact, I tried to figure it out by myself, but nothing comes of it, my knowledge of Python in Cinema4d is not good yet.

    I looked for how to rewrite this XPresso Iteration node in Python?

    Capture.PNG

    Share this post


    Link to post
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...