Export script to recreate the object in a layer


I would like to get the script that recreates the objects on a given layer, is this possible?

For example, I created a cylinder and a box on layer 1, than I want to get the script that
recreates the objects

Kind regards


A. On layer 1:

  1. create cylinder
  2. move cylinder
  3. create box
  4. resize box
  5. union cylinder and box

B. generate script:

  1. create cylinder
  2. create box
  3. union

As you can see the move and resize commands do not show in the script

C. Run script on Layer 2
Layer 1 and Layer 2 must look the same

Is this possible using python?

I have a Rhino5 on Mac


Can I summarise by stating you want to copy objects from one layer to another?



Thank you for replying

I would like to create a script with the commands, then I would like to
modify some
parameters (ie. dimensions of a box) before recreating the objects in
another layer

Kind regards

I think in some way it’s possible what you want but you would need to explicitly define and set all parameters of the objects. Do you know grasshopper? It seems this might be a better tool for your need?



I am using Rhino5 on Mac, and I think that grasshopper does not work on Mac

Is there a way to access to the commands history? do the commands contain
all the parameters of the command (ie. center of circle, radius, …)?

Kind regards

Indeed you are right…:unamused:

No unfortunately not.

So a script would have to set all parameters, there is not really a way to record the actions from regular commands.



I do not understand why the command history do not contain all the parameters for each command
executed. is it possible for Rhino to add such thing (this should be easy for Rhino developers)?

The issue, is that when I want to modify a tiny thing in the whole design, I have to redraw everything

Starting from a python script is more difficult, I prefer to draw under Rhino using modifiable
parameters (all numerical values could be replaced by expressions using variables).

I wish I could do the following:

base of cylinder: x=0,y=0,0
Diameter: d=10
end of cylinder: 10

Then when I set x=1, all objects that depend on x are redrawn using the new x value

Kind regards

Because Rhino is not a parametric modeler… Objects do not “remember” how/where they are originally created. The command history is just a collected “printout” of what the command line has had in it for the last n lines.

No, not really. It would actually require a complete restructuring of how objects are created and stored in memory.

However, as Willem already said, it is possible to create a script that would ask for certain parameters and create a specific set of objects based on those parameters.


How do I do that? could you please give me an example?

Kind regards

Below is a rather dumb example… Adds a cube with spheres in all corners to the file. User specifies cube side length, sphere diameter, placement of the center of the object, and a layer for the new object to go to. Run it several times to create different sized objects.

The code is posted below for reading, to test, download the .py file below and save it to your desktop, then type RunPythonScript and brose to the file on the desktop and run.

CreateCubeSphereCorners.py (1.6 KB)

import rhinoscriptsyntax as rs

def CreateCubeSphereCorners():
    #for minimum sizes bigger than file tolerance
    #get user input
    cub_side=rs.GetReal("Cube side length?",10,tol)
    if cub_side is None: return
    sph_dia=rs.GetReal("sphere diameter?",cr,minimum=tol,maximum=(2*cr)-tol)
    if sph_dia is None: return
    bc=rs.GetPoint("Pick point for center of cube")
    if not bc: return
    #ask user for a layer (possible to create new one)
    #also possible to automatically create a new layer
    layer=rs.GetLayer("Layer for object?",rs.CurrentLayer(),True)
    if not layer: return
    #cut screen redraw to go faster
    #calculate box corner points
    #add box
    #add spheres at corner points
    spheres=[rs.AddSphere(pt,sph_dia/2) for pt in corners]
    #Boolean union all
    #move object to desired layer