Jump to content

Hey, you need a renderfarm? If that's the case, make sure you check this topic for more info! 



Recommended Posts

borg    24

Hi All,

 

I am trying to convert some of my COFFEE xpresso nodes into PYTHON expresso nodes.

 

How would i go about rewriting following coffee script into Python script.   sorry for this NOOB question!!

 

//

if (Input1 ==0)
Output1=TRUE, Output2=FALSE, Output3=FALSE, Output4=FALSE, Output5=FALSE, Output6=FALSE, Output7=FALSE ; 

//

 

any help would be greatly apreciated

Share this post


Link to post
Share on other sites

jed    320
def main():
    global Output1 # and the rest
    
    if Input1 == 0:
        Output1 = True
        Output2 = False
        Output3 = False
        Output4 = False
        Output5 = False
        Output6 = False
        Output7 = False
        
    else:
        Output1 = False # etc

note it's case sensitive, indent and colons. Outputs must be global, but can be declared on one line separated with commas

 

true.c4d

  • Like 2

Share this post


Link to post
Share on other sites
borg    24
  • Topic Author
  • Hi Jed, and thank you very much for this...   Have to rewrite a lot of xpresso coffee nodes to Python for upcoming new version of C4D.

    So i might have a few more questions like this one in the near future.

     

    Also tried this script

     

    def main():
        global Output1 ,Output2 # and the rest
        
        if Input1==0 and Input2==4:
            Output1 = 5
            Output2 = 6
            
            
        else:
            Output1 = 1
            Output2 = 8  # etc

     

    works to  :)    very happy over here. Thanks again...

     

    Any chance you could also tell me how to add a new "real" input and output to a xpresso python node, 'integer' and ' float' are there, but i do not see the 'real'

     

    Share this post


    Link to post
    Share on other sites
    jed    320

    Real and float are the same.

     

    One thing to remember with numbers is the way Python 2.7 (cinema uses an old version) treats integers different to reals esp in division. Integer division gives an integer result eg

     

    3 / 2 = 1.5 in Python 3.5 (and IRL)

     

    3 / 2 = 1 in Python 2.7

     

    this can trip you up if you use current frame (an integer) in a calculation, but can be fixed by using 3.0 etc.

     

    I use the free Pycharm to develop script ideas - you have to install Python first.

     

    http://www.jetbrains.com/pycharm/

     

    https://www.python.org/

    • Like 1

    Share this post


    Link to post
    Share on other sites
    borg    24
  • Topic Author
  • Hi Jed,

     

    Ok , clear, defenitly one to remember..fairly new to me this python scripting, so again many thanks for your answers.  

    Share this post


    Link to post
    Share on other sites
    jed    320

    @borg here's one of the first scripts I wrote. It generates 6 lottery numbers, and sorts lo-hi. Note the 'import random'.

     

    lottery.c4d

    • Like 1

    Share this post


    Link to post
    Share on other sites
    borg    24
  • Topic Author
  • wow, very cool.. keep m coming cause,  these snippets, i think you cannot have enough of them...  thanks mate.

     

    Share this post


    Link to post
    Share on other sites
    ABMotion    238

    Here are some Python for Cinema 4D learning resources I've used that hopefully you find useful as well:

    http://blog.grooff.eu/

    http://creativmotion.portfoliobox.me/training

    https://developers.MAXON.net/?p=2985 (Public Resources for Cinema 4D Plugin Development in Python)

    https://www.cineversity.com/vidplaylist/introduction_to_python_in_c4d (Requires membership that comes with MSA or paid)

    http://www.plugincafe.com/forum/forum_topics.asp?FID=7 (MAXON Python Development forum)

    https://github.com/NiklasRosenstein?tab=repositories (Github code snippets, Note: not just Python)

    • Like 1

    Share this post


    Link to post
    Share on other sites
    borg    24
  • Topic Author
  • Great,   thank you very much.  Niklas and Pim i already know...will sure check out the others..

     

    Share this post


    Link to post
    Share on other sites
    jed    320
    49 minutes ago, borg said:

    wow, very cool.. keep m coming

    One of my on-going projects is python helicopters. In this file, start the timeline, then in the control panel adjust rotors, altitude, speed then steer. Might fly a bit slow if you haven't got a reasonable gfx card.

     

    https://www.dropbox.com/s/3fhnianc9jm4rx6/legohelicopter.zip?dl=1

     

    it's not designed for making movies - just for fun in the viewport.

    • Like 1

    Share this post


    Link to post
    Share on other sites
    ABMotion    238

    To add to your knowledge, an alternative to @jed code block above is to create less lines by combining like values exactly as follows:

    import c4d
    
    def main():
        global Output1, Output2, Output3, Output4, Output5, Output6, Output7
        
        if Input1 == 0:
            Output1 = True
            Output2 = Output3 = Output4 = Output5 = Output6 = Output7 = False
    
        else:
            Output1 = False
            Output2 = Output3 = Output4 = Output5 = Output6 = Output7 = True

     

    • Like 1

    Share this post


    Link to post
    Share on other sites
    jed    320

    I also use this method

     

    def main():
        global Output1, Output2, Output3, Output4
        
        if Input1 == 0:
            Output1, Output2, Output3, Output4 = True, False, True, False
            
        else:
            Output1, Output2, Output3, Output4 = False, True, False, False

     

    • Like 1

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×