Jump to content

pdeb

Clones inherit pos vals fr specific fram

Recommended Posts

Hi all,

 

Python novice trying to solve a mograph puzzle, thanks in advance for pointers.

 

I'm trying to create an infographic similar to a runner's path elevation over time, where each cloner inherits the Y-value of the Null following a path over terrain, on that specific frame.

 

The cloner has an Xpresso tag where Time generates clone count, so on each frame a new clone in the line appears, and a Tracer creates a growing elevation profile.

 

I've tried the following code, and to no one's surprise, each cloner has the same value on each frame, so they all rise and fall in unison.

 

import c4d
from c4d.modules import mograph as mo
#Welcome to the world of Python

def main():
    md = mo.GeGetMoData(op)
    if md is None: return False
    
    cnt = md.GetCount()
    marr = md.GetArray(c4d.MODATA_MATRIX)
    fall = md.GetFalloffs()
    
    Traveler = op[c4d.ID_USERDATA, 1]
    TravPos = Traveler.GetRelPos()
    TravPosY = TravPos[1]
    print TravPos
    
    for i in (xrange(0, cnt)):
        marr[i].off = c4d.Vector(marr[i].off.x,marr[i].off.y+TravPosY,marr[i].off.z)
    
    md.SetArray(c4d.MODATA_MATRIX, marr, True)
    return True

 

Can someone point me to a way for each clone to take on the value on the frame it was generated, and then freeze in position? Is it a matter of a BaseContainer and storing values? I can't seem to find a way in the SDK to feed the Null's position a time or frame argument.

 

thanks muchly, pdeb

Share this post


Link to post
Share on other sites

Yes, you would need to store the previous positions somewhere. Currently you are iterating over all matrices in the for loop setting all off them to the same value. Do you want to solve it via python? If its just about achieving the effect you can probably do this without scripting. You could for example use a tracer the traces a null (the runner) and clone on the spline points. That should place a clone at each position the runner without even having to adjust the clone count via Xpresso. 

Share this post


Link to post
Share on other sites
  • Topic Author
  • Thanks for the reply Havealot,

     

    The attached will help describe what I'm trying to do. The clones would form the top of the elevation profile (reds/oranges/yellows).

     

    I hacked it by having 1 clone take the Y-value of the null traveling along the red path on the terrain, and moving it along x with a Time Effector.

     

    I tried embedding a conditional in the loop, telling Python to ignore any clone index which wasn't == current frame, but that didn't seem to do anything despite passing back no errors.

     

    It was more an exercise in going deeper into Python, so I'll read up on the BaseContainer and storing values, as it looks quite powerful.

     

     

    Screen Shot 2019-11-06 at 11.08.07 AM.png

    Share this post


    Link to post
    Share on other sites

    This file is a bit basic - I just made the cloner editable and iterated the clones.

     

    scrnshot.png.68ad7657ad41e51c0658db103328cd72.png

     

    track me.c4d

     

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Thanks very much Jed!

    Share this post


    Link to post
    Share on other sites

    @pdeb Just noticed that due to the math starting at F1, the 1st cylinder gets ignored. You could edit line 21 to

     

    cyl = cyls[frame - 1]

     

    to fix that.

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Thanks Jed.

     

    Until I get my python chops I decided to go a different route, albeit hacky.

     

    I used a python script to export the runner's Y-position values to a CSV, then used Niklas Rosenstein's CSV effector to give each of my clones (as each appears on its own frame) the Y-value from the CSV.

     

    It works fine. it just means spitting out values to the CSV if I decide to change the path.

     

    But for now it will do the trick, thanks for your help, p

    Screen Shot 2019-11-08 at 11.53.30 AM.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.


    • Recently Browsing   0 members

      No registered users viewing this page.

    Latest Topics

    Latest Comments

    ×
    ×
    • Create New...