How to copy objects from one layout to another with rhinocommon?

I need a perfect clone. Can’t seem to figure it out.

Hi @Asterisk,

The CopyToClipboard and Paste commands are scriptable. You might start there.

– Dale

That’ll do, but I’m not gonna learn anything out of it. I’m trying to understand how Space works in Rhino.

Are you talking about ActiveSpace @Asterisk ?

This should work nicely if you know the old and the new Viewports.

var oldView; // Viewport to Copy from
var newView; // Viewport to Copy to

// Get old objects
var doc = Rhino.RhinoDoc.ActiveDoc;
var enumerSettings = new ObjectEnumeratorSettings()
  ViewportFilter = oldView;
RhinoObject[] oldItems = doc.Objects.Find(enumerSettings);

// Add new objects
var attribs = new ObjectAttributes()
  Space = ActiveSpace.PageSpace,
  ViewportId = newView.Id
foreach(RhinoObject obj in oldItems)
  var geom = obj.Geometry.Duplicate();
  doc.Objects.Add(geom, attribs);