Brainstorm :To automatically create a data comparison animation by python



  • Hi~I recently notice a fatanstic bar chart data comparison video in youtube,below is the video link:
    link text
    animation.png

    i want to create a 3D version of this kind of data comparision video by python ,so that i can batch generate animation by easily input data

    For example i have a data named :Four companies profit from 2000 to 2010
    data1.png

    and i want to create 4 bar chart cubes respectively ,1th key represents 2000 year ,25th to 2001 year and so on ,each cube Y size key-value is the profit respectively ,in 1th key,A company Y size is 398 ,B 400 ,C 500,D 600, and in 25th ,each Y size value is the profit of 2001.

    data 2.png

    This is the simple demonstration i make in C4D by hand
    demos.png

    i am crazy to achieving it by python,easily input data ,automatically create cube or cylinder and generate key and value and changeable number ,this is a powerful tool,well,i know definitely it is not easy
    it is a big project !!!

    **so i just want to ask the possibility of this code
    if it can be achieve in C4D by python ?
    could you please tell me the probable direction or the python module i should to use ?
    if you can demonstrate with some basic code ,i would be grateful !
    Thanks ~
    **
    i



  • Hi @Joe132 welcome in the plugincafe community.

    So there is nothing in the Cinema 4D API that could help you to import this kind of data.
    However, python lets you the possibility to import natively CSV data which can be normally exported from any software. See How to read and write CSV files.

    Once you have done it you need to create an object. To do so you have to creates a new instance of BaseObject like so
    If you open the python console and drag a cube, press enter you will see the object is a BaseObject one. For more information see Python Console Manual then for a list of ID or object, either you write the ID that was given while drag and drop either you can look at this page Object Type.

    Something like:

    import c4d
    
    # Creates the object in memory
    cube = c4d.BaseObject(c4d.Ocube) 
    
    # Inserts the object into the document
    doc.InsertObject(cube)
    
    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
    

    Then for the animation, I suggest you read to this topic from yesterday where you can find valuable information Beginner:How can I set a key-frame and value to a cube by python?

    If you have any questions, do not hesitate.
    Cheers,
    Maxime.



  • @m_adam
    Thank you very much ! it is certainly helpful !!