Importing Science Data with Python in Cinema 4D
Posted: 08 November 2017 02:07 PM   [ Ignore ]  
Total Posts:  2
Joined  2017-11-07

Hi Everyone,

I am new to Cinema 4D in the last few months, so my apologies as I believe this is a relatively simple problem.  I have created an elevation model of a research watershed.  It is currently a polygon object in Cinema 4D.  What I would like to do is have shapes (cylinders) rise up from the elevation model to a height that corresponds to the amount of carbon in the soil at that particular point.  I have set up my data in Excel (in preparation for creating a CSV for Cinema 4D) as follows.  This is purely sample data

X (cm)  Z(cm)  Carbon
10         20         3
-10         5         5


The X and Z columns are the X, Z coordinates where the center of the shape needs to be located in Cinema 4D.  I have already transformed all the data for X and Z to match Cinema 4D’s coordinate system.  The Carbon Column is the height or Y value.  Here is what I would like to have happen:

Cinema 4D places a shape (again I am thinking a cylinder) at the center of each X,Z location (40 total in my spreadsheet).  The base (bottom) of that shape is clamped to the surface of my elevation model polygon.  The shape then rises (in the Y direction) to the value of the carbon column over time.  I would like the 40 different shapes to rise randomly across the elevation model landscape.  Also, I would like all the shapes to have the same material.

While I could program this manually, I will be doing more of this in the future, and I know Cinema has the capability to do it with Xpresso/Python.  Unfortunately, I haven’t done much programming since high school.  I have been watching tutorials on Python/Xpresso, but it is a bit overwhelming with all the different options. I learn best from examples, so if someone can get my started with the right syntax and commands - I would sure appreciate it.

Thanks for any help you can provide!

Profile
 
 
Posted: 08 November 2017 03:29 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
Total Posts:  4710
Joined  2011-03-03

Hi rsths13,

The way with Python seems to go into the direction of a plug-in development, with that it should be in the Maxon’s Developer Cafè.
https://developers.maxon.net
In short, there are some parts with standard Python that needs to be clear before going to the developer forum.
How to open a file from the disk, and get the content read out into a list or tuple, etc.
Anything from there is a “generative loop”, which means applying data to generated objects, or delete them, if less are needed later on. Not my place here to go into that, but please feel free to suggest this as a tutorial.

=====

To use XPress and C4D as it is, I would create the list like an ASCII code based list. To see the structure, create an object, make it editable, and in the Structure Manager>>File>Export ASCII, to get an sample file.

If you have your data converted in the same way, go to Main Menu>>Create>Object>Empty Polygon. With this empty polygon, you can load a ASCII list into and use the data as mentioned in your question.

The X and Z value will be applied to the position and the Y position of that point is converted to the scale. The Cylinder in this case was made editable, and the Axis set to the lowest point of the Cylinder, so a Scale value can create the value accordingly to your data. See file “_…01.c4d”

If it needs to grow, many options come to mind, to place a Falloff node into the scale calculation might help.  See file “…_11.c4d”

Both files use the Iteration node with a Link and Point node.

Note that a reload of the ASCII data will add only points, it doesn’t replace the old one. A new Empty Polygon Object is needed. (If you have several, you could blend (Mix Node) among those.


Scene file:
https://www.amazon.com/clouddrive/share/V9AMJjSU5vmlbgPKp7k1KM3tXFT6GufFgSQj7XFzYWL

How to swap data: one minute clip
https://www.amazon.com/clouddrive/share/k5CBFgqmmceL9SzPX8ebkTE4HHEr4zZFTuK3Ye1bPjW

All the best

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.

Photography For C4D Artists: 200 Free Tutorials: Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile
 
 
Posted: 16 November 2017 01:22 PM   [ Ignore ]   [ # 2 ]  
Total Posts:  2
Joined  2017-11-07

Dr. Sassi, thanks for the examples!  They are a big help! I am using them to work through my animation with my data.

Profile
 
 
Posted: 16 November 2017 01:23 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
Total Posts:  4710
Joined  2011-03-03

Thanks a lot for taking the time to reply, rsths13, very nice of you.

My best wishes for your project.

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.

Photography For C4D Artists: 200 Free Tutorials: Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile