Jump to content

Sign in to follow this  
greasemonkey

COFFEE Script to Python

Recommended Posts

Hey hey, very long time & no posting from me, hoping the community can be it's usual wonderfully helpful self!

I've dug out an old project and need to convert a couple of COFFEE xpresso nodes to Python. Super simple, but I know next to nothing about this. 

The problem seems to be with the 'if' statements.

Here's the two COFFEE scipts:

------------------

main()
{
if(cframe <= int(initframe))
    out = 0.0;
else out = varitime;

-------------------

main()
{
if(ctime == ltime)
    ntime = stime;
else
   ntime = runtime;
}

Share this post


Link to post
def main():
    global out
    if cframe <= int(initframe) :
        out = 0.0
    else :
        out = varitime

 

def main():
    global ntime
    if ctime == ltime :
        ntime = stime
    else :
        ntime = runtime

 

...that is, if I interpret your ports and types correctly...

Share this post


Link to post
  • Topic Author
  • Thanks Cairyn.

    I've cut n pasted the code into the python nodes and it's compiling with no errors but the setup still isn't working.

    It's a rig for the time mechanism of a watch, cut, pasted and hacked together years ago from an example I can't remember where I found it.

    The xpresso tag functions, but the python nodes seem to be outputting a '0' result for the time node, which means the seconds hand isn't turning.

    I've attached the stripped down rig if you want to take a look.

    Thanks for your time!

    Nigel

     

    Capture.JPG

    WatchRig_01.rar

    Share this post


    Link to post
  • Topic Author
  • Interestingly, I notice that if you're playing the time line and click ahead to a spot, the seconds hand will jump to the correct point, but then remain there.

    So it looks like it needs a prompt to update? Unfortunately, activating the 'Frame Dependent' check box doesn't seem to make a difference.

    Share this post


    Link to post

    At first glance -

     

    some Python input and output ports not connected

    a Python node with global out, but port is called Output1

    a condition node with switch not connected

     

    BTW clicking compile is a syntax check - extensions, console is the place to look for errors.

    Share this post


    Link to post

    As Jed already said, in one of your Python nodes the port is called Output1, while the code requires the name out. Once you change that, the Python node errors are gone. Note that the output ports need to be defined as global in the Python code.

     

    No, the XPresso is still not working after that, but I'm not debugging that for free.

     

    Share this post


    Link to post

    If you post the original Coffee version, it would be easier for us to convert.

    Share this post


    Link to post
  • Topic Author
  • Thanks for the help so far, I've attached the original COFFEE version. 

    Cairyn, this is for a professional job and I certainly don't want to take the peeved (*edit, I see the cafe still has it's heavy swear censor in place!). Hit me up by PM if you want to talk $$

    WatchRig_02.rar

    Share this post


    Link to post

    I think I've done it - well, stuff moves 😀

     

    As I suspected, some ports that should be float were integer (or vice versa). XPresso is quite forgiving with data types, but Python is strict. Console shows no errors, but there's still some ports not connected (from the coffee version), not sure if this affects anything.

     

    watch 3.c4d

    Share this post


    Link to post
  • Topic Author
  • Thanks Jed, perfect 🙂

    To share the love I might re-post the set up in the xpresso channel as a free download for anyone wanting a watch rig.

    Share this post


    Link to post

    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...