Animation export images and correlating values of component

Hi All,

Is there a way to record values for a specific component and generate a file whilst animating a slider and exporting images so to have a list of images with correlating values exported from a certain component at the time the image was taken? Thank you for your help in advance!


Jonas Blazinskas

You can write your own GhPython or C#
Here is a rough example in GhPy

import Rhino as rh
import Rhino.Display as rhd
import System.Drawing as drawing
import scriptcontext as sc

sc.doc = rh.RhinoDoc.ActiveDoc
view = rh.RhinoDoc.ActiveDoc.Views.Find('Perspective',True)
vs = rhd.ViewCaptureSettings(view, drawing.Size(500,500), 300)
sc.doc = ghdoc

pth = 'C:\\Users\\YOURNAME\\Downloads\\{0}.png'.format(V)
img = rhd.ViewCapture.CaptureToBitmap(vs)
if R: img.Save(pth)



Where is the component data output too? Is it stored in image data? How would I go about inputing multiple parameters that I want to record e.g. Area, Length etc. Thank you for your help!

My example only saves the image to disk.

The GhPy component can take multiple inputs. In my example, only one is used to dynamically name the image output. You can collect as many parameters as you want and output a separate CSV or the like for record keeping.

Would you be so kind and show an example where additionally to image there would be an input competent (A) which would export to .csv . Only asking this because I have never used python before and it would be a great starting point for me to have a working script which I could then reverse engineer to learn my basic python skills. Thank you for your help in advance!

Take a look at this. I put it together rather quickly so you’ll have to tinker a little bit.
Make sure you double click the GhPy component and change the file paths to your correct directory. Like below. (15.6 KB)
This takes a screenshot each time a parameter changes. The PNG is named by a combination of the three parameters. The three parameters are recorded in a single CSV.

1 Like

This definition is very helpful, thank you! How can i save frames rendered with custom preview?

By animating a slider!

Hi Will,

Thank you for your help I have been playing around with this script and have managed to add additional values and started to understand how it all works.

I found that the output image sometimes doesn’t match the slider values. I think it reads the value and takes an image at incorrect time for some reason, this is noticeable at the start and end of value slider. Is there a way to get around this?

Additionally I found a way to read GH file name with:
GHFilename = ghenv.LocalScope.ghdoc.Name

And now I would love to create and save the outputs to the directory that is named according to GHFilename with the following:

import os
if not os.path.exists(‘my_folder’):

But it seems that I am doing something incorrectly where I am linking {GHFilename}.

And as a last thing I would love to have a check if there is a duplicate value before writing the data. I found this piece of code:

with open(‘filename.csv’, ‘a’) as f:
writer = csv.writer(f,delimiter=",")
seen = set()
for row in data:
if row in seen:

But at the moment it feels completely over my head if I can’t even handle the variable directory creation and access.

Please find attached the current version of python code that I am using:Box Coffee (17.2 KB)

As always thank you so much for your help, this topic and your help has encouraged me to finally get into python after years of avoiding it! (22.3 KB)

Take a look at this file. A few things I’ve changed are:

  • use double back slash in strings when it’s a path (single back slash is an escape char)
  • use string method .format() with {}, seen on line 30,31,34,35
  • get rid of the * in the ghdoc.Name value because it’s an illegal character for folder names (line 29)

This is probably because the script is running ahead of the viewport refresh. I’m not sure if @piac or @dale can weigh in on this. There might be an event you can listen to.
My lazy solution is to add a time.sleep() method in the script, seen on line 39. Seems to work if you don’t mind a little performance sacrifice.

Hi Will,

Thank you so much for your help! It all seems to run good now!

I am trying to form gifs from output folders therefore I find the naming to be a vital part, at the moment it falls down and required manual input when a series of images naming values go over a 1000 so for e.g. 1000, 300, 400, 500… Where a lack of leading zero makes values with more digits go to the front. I am trying to input the following:

A = print(’{:04}’.format(A))

But I receive this error:

Any idea on what I am doing wrong, or is this a completely incorrect way to format a leading zero?


Jonas Blazinskas

you just gotta get rid of the print statement

A = '{:04}'.format(A)
B = '{:04}'.format(B)
C = '{:04}'.format(C)
D = '{:04}'.format(D)

IronPython 2.7 recognizes print as a statement and there is no return value, as I understand.

Thanks Will!

I have additionally added headers for data with component nickname and have converted the data into json file. I am now realising that with now what is becoming an extensive code if I have to input different parameter amount I have to constantly adjust the code for input parameters A B C D E F G etc. is there a way to somehow draw the inputs without specified the exact amount and be that generated by the plugged inputs? Please see attached.Box Coffee (36.7 KB) Thank you for your help in advance and Merry Christmas!

I’d actually recommend this

Hi Will,

Problem with this solution is that I need the original sliders to be directly pluged in into the python component because that where the headers are being read from the component nickname. Is there a way to achieve the same with out merging the data into one input? Thank you for your help!


Jonas Blazinskas

You can try something like this but you may have to straighten out the kinks further along…


1 Like

Hey Will,

It seems that it is extracting the input names and not the parameter nicknames.

P.S i think it can be fixed wit this

for input in ghenv.Component.Params.Input:
for i in input.Sources:


Jonas Blazinskas