Animate Sweep Script



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 28/04/2011 at 11:49, xxxxxxxx wrote:

    Hi Everyone
    Please be gentle i'm a newbie to any sort of scripting...

    I have the need to create a script that will take an existing sweep nurb and animate is so that at time0 the sweep is not visible and at time100 the sweep with have animated the full length of the spline.
    I've watched a few tutorials and tried this

    CallCommand(12501); // Goto Start
    CallCommand(12425); // Autokeying
    CallCommand(12410); // Record Active Objects
    object()#SWEEPOBJECT_STARTGROWTH=0;
    object()#SWEEPOBJECT_GROWTH=1;
    CallCommand(12502); // Goto End
    CallCommand(12410); // Record Active Objects
    object()#SWEEPOBJECT_STARTGROWTH=1;
    object()#SWEEPOBJECT_GROWTH=1;
    CallCommand(12425); // Autokeying
    CallCommand(12501); // Goto Start

    If doesn't seem to be animating the action as the object retains the last settings.
    Any help very much appreciated and if i just need to read a manual, fair enough, but can i have a clue as to which bit to read...
    thanks
    Hammondchips



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/04/2011 at 09:52, xxxxxxxx wrote:

    Assigning values to attributes is not handled as an action like when the user changes the value by hand.
    You must set the keys yourself, there are functions for this, It think. I'm no more familiar with Coffee so I'm not sure if it can set keys.

    Cheers,
    Nux



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/04/2011 at 12:23, xxxxxxxx wrote:

    If you have a recent enough version to use python.
    Here's a python script that will do it using keyframe selections which Coffee doesn't have:

    import c4d  
    from c4d import gui  
      
    def main() :  
      
      fps = doc.GetFps()# Gets the frames per second setting  
      frame = doc.GetMinTime().GetFrame(fps) #set min time  
      doc.SetTime(c4d.BaseTime(frame, fps)) #sets time slider to frame 0  
      obj = doc.GetActiveObject() #Gets the selected SweepNurbs object  
      obj[c4d.SWEEPOBJECT_STARTGROWTH]=0; #Sets the growth value to zero    
      id = c4d.DescID(c4d.SWEEPOBJECT_STARTGROWTH) #Assigns a variable to sweep growth      
      obj.SetKeyframeSelection(id, 1) #Adds a Keyframe Selection to the growth    
      c4d.CallCommand(12410) #Execute the Record Button    
      
      doc.SetTime(c4d.BaseTime(frame +20, fps)) #sets time slider to frame 20  
      obj[c4d.SWEEPOBJECT_STARTGROWTH]=1; #Sets the growth value to 100  
      obj.SetKeyframeSelection(id, 1) #Adds a Keyframe Selection to the growth  
      c4d.CallCommand(12410) #Execute the Record Button  
      
      obj.SetKeyframeSelection(id, 0) #Removes the Keyframe Selection option  
      obj.ClearKeyframeSelection() #Clears the Keyframe Selections   
      c4d.EventAdd()  
      
    if __name__=='__main__':  
      main()
    

    Using BaseTime() is more versatile than using CallCommand() because it lets you specify a specific frame to move to.

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/05/2011 at 11:29, xxxxxxxx wrote:

    Hi Scott
    Thanks so much, a lot to learn but i'm gonna take your script and try applying it.  I'll let you know how i get on...
    Regards
    Hammondchips



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/05/2011 at 13:22, xxxxxxxx wrote:

    Yeah.
    I know how hard it is to brake away from those simple CallCommands and use regular scripting methods. I've only been writing code for about a year myself. So i still know what it's like to be new and overwhelmed by it all.

    I have some very easy Coffee scripting videos here: https://sites.google.com/site/scottayersmedia/scripting

    They might help you to brake away from relying on those CallCommands for everything.

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/05/2011 at 02:27, xxxxxxxx wrote:

    Wow - pretty good progress within a year!
    As i understand it ... COFFEE is the inbuild C4D scripting, Python is a 3rd party script which has been adapted to fit nicely with C4D.  Is there any advantage in using COFFEE or should i focus my energy on getting to grips with Python?
    Thanks
    A



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/05/2011 at 08:24, xxxxxxxx wrote:

    About a year ago I decided to stop putting off learning how to write code. So I decided to learn everything all at once(ActionScript, javascript, PHP, ASP, WinForms,  MVC, Coffee, C#, C++,python...).
    I'm still very much a beginner. But I have a pretty good grasp of the basics in a lot of different languages now. So I can write code in a variety of software. Not just inside of C4D.

    Python is far more powerful than Coffee. And that's the scripting language that you should learn
    to get the most out of C4D.
    BUT...
    Python is a very strangely written language compared to almost everything else in the coding world. So if you learn Python as your first language. And you become attached to it. You won't be able to write code in anything else like Flash or Unity for example.
    THIS IS DANGEROUS!

    While python is very powerful, and the best choice inside of C4D. Don't become a one trick pony with it. I see that happen all too often.
    Learning Coffee is a great way to learn how to write standard bracketed code that other software uses. While staying inside of C4D.
    I can almost guarantee that if you learn one language(whatever it is) you'll want to code in something else eventually. And if you know the basics of Coffee. You'll be able to jump out of C4D and write code in C#, Javascript , and Flash fairly comfortably.

    In short:
    Learn and use Python is C4D. It's a wonderful language. But don't become overly attached to it.
    Try to also learn a standard language like Coffee or javascript. So you won't be totally lost outside of C4D.

    -ScottA



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/05/2011 at 11:09, xxxxxxxx wrote:

    Hi
    Note taken!

    As for the original script you helped me with - SUCCESS!

    Your script work wonderfully, although some of the 'sweeps' had origins which cause the animated sweep to begin at different ends.
    I simply added a couple of lines to one code and created another almost identical code called 'reverse' which had opposite STARTGROWTH & GROW values. Meaning shortcut 1 or 2 was applied depending which end the line 'grew' from.
    Anyway even if that didn't make sense, challenge number 1 is done.
    Gonna go through your handy COFFEE tuts and then come back to the next challenge when i know more.
    Very grateful for your help, i would buy you a drink but i think you're a long way from London, UK based on you're timezone!!
    Regards
    Hammondchips

    import c4d
    from c4d import gui

    def main() :

    fps = doc.GetFps()# Gets the frames per second setting
      frame = doc.GetMinTime().GetFrame(fps) #set min time
      doc.SetTime(c4d.BaseTime(frame, fps)) #sets time slider to frame 0
      obj = doc.GetActiveObject() #Gets the selected SweepNurbs object
      obj[c4d.SWEEPOBJECT_STARTGROWTH]=0;
      obj[c4d.SWEEPOBJECT_GROWTH]=1;
      id = c4d.DescID(c4d.SWEEPOBJECT_STARTGROWTH) #Assigns a variable to sweep growth   
      obj.SetKeyframeSelection(id, 1) #Adds a Keyframe Selection to the growth 
      c4d.CallCommand(12410) #Execute the Record Button

    doc.SetTime(c4d.BaseTime(frame +100, fps)) #sets time slider to frame 20
      obj[c4d.SWEEPOBJECT_STARTGROWTH]=1;
      obj[c4d.SWEEPOBJECT_GROWTH]=0;
      obj.SetKeyframeSelection(id, 1) #Adds a Keyframe Selection to the growth
      c4d.CallCommand(12410) #Execute the Record Button

    obj.SetKeyframeSelection(id, 0) #Removes the Keyframe Selection option
      obj.ClearKeyframeSelection() #Clears the Keyframe Selections
      c4d.EventAdd()

    if __name__=='__main__':
      main()


Log in to reply