How do I update a sphere radius with RhinoCommon?

I’m completely new to the Rhino SDK and trying to figure out how things work. I want to change the radius of an existing sphere and see the change on the display. This adds the sphere:


Now I want to change its radius. This naive attempt doesn’t work, I suspect because the object in the document is not the sphere I supplied as an argument to AddSphere:

sphere.Radius = 2;

AddSphere returns a Guid, which I’d guess I can use to get at the object whose radius I want to change. Can anyone fill me in or point me to an example?


Rhino does not have a spherical surface object. When you add a Rhino.Geometry.Sphere to the document, a surface of revolution is created from the Sphere - Sphere.ToRevSurface() - and that surface is added to the document in for form of a single-faced Rhino.Geometry.Brep object.

To modify Rhino objects, you must:

  1. Get the object
  2. Get the object’s geometry
  3. Make a copy of the geometry
  4. Replace the object’s geometry by calling doc.Objects.Replace

By following these rules, undo and redo work for the end user.

Does this help?

1 Like

Yes, thanks, that helps a lot. Just one question: how do I retrieve the object from the Guid returned by AddSphere?

Try this:

Rhino.Geometry.Plane plane = Rhino.Geometry.Plane.WorldXY;
double radius = 5.0;
Rhino.Geometry.Sphere sphere = new Sphere(plane, radius);
System.Guid objectId = doc.Objects.AddSphere(sphere);

Thanks again, Dale. I’ve gotten that far, but I don’t know how to get from objectId to the object itself in step 1 in your first response. If I’m being very dense, don’t worry about it–I’ll figure it out.

Here is a full blown example you might want to review:

1 Like

Thanks for the detailed example! The geometry updating code will be very helpful. I had seen several examples of that sort, where the object to be updated is selected interactively. But I just wanted to update the radius of the sphere that I had just created via AddSphere—without any interaction. So my question remains, is there no way to get at the object that corresponds to a given Guid?

If you have an object’s GUID and want to retrieve the object that owns it, then you can do something like this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  Guid guid = <some GUID...>;

  RhinoObject rhino_object = doc.Objects.Find(guid);
  if (null != rhino_object)
    // TODO...
  return Result.Success;

Does this help?


RhinoObject rhino_object = new docobject.objref(Guid)

Yes! That’s what I’ve been looking for. Thanks so much for your help, Dale and Jordy.

I think I must be a bit slower in comprehension than Mr. Carlson.

What are the detailed differences between

RhinoObject rhino_object = doc.Objects.Find(guid);
RhinoObject rhino_object = new docobject.objref(Guid) ?


As in most cases, there is more than one way of doing things…

I would not suggest to use this one, as it makes the assumption that the document is always only one, which might not be the case (especially in the future). The first one is a much better option. This latter one does not work well with GhPython either, for example, because GhPython uses its own document, and I hope in general we will discourage its use.



Giulio Piacentino
for Robert McNeel & Associates