Duplicate different types of objects

Hi, I’m writing a code to make duplicates of the input objects (Rhino.Geometry) and apply transformations in Python.
I initially thought the code can be generic, but it seems like there are different object types that provide different ways of duplicating objects.

It seems like some object has Duplicate(), and some object only has copy constructor (e.g., newP=rg.Point3d(P)). Also, some object types such as surfaces have specific functions such as DuplicateSrf().
My question is,

  1. what is the difference between Duplicate() and DuplicateSrf()?
  2. if I wrote a code like
if isinstance(obj,rg....):
    newobj=rg.objtype(obj)
elif isinstance(obj,rg....):
    newobj=obj.Duplicate()

How many base object types there are? Do I need to write if-else block for all the object types that only have copy constructors? It seems like Point3d and Vector3d fall into this class. Why they don’t have Duplicate()? What’s the best way to write a universal code to make a copy of all the object types provided by Rhino.Geometry?

Thank you.

I´m struggling duplicating a Circle …

1 Like

Geometry structs generally lack explicit duplicate methods, likely because one can duplicate them by assignment in C#. In GHPython, one can either make a new struct that copies the properties, or use the Python copy module:


240114_DuplicateCircle_00.gh (5.9 KB)

Python copy module!

Hehe, indeed. It certainly can help :slight_smile:

While I understand why the Rhino.Geometry structs lack the Duplicate() method (i.e. C# struct duplication by assignment). It does seem pretty inconsistent that certain structs have copy constructors (e.g. Point3d , Vector3d, and Plane), while others do not (e.g. Point3f, Line, and Circle).

1 Like