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;
doc.Views.Redraw[];
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:
Get the object
Get the object’s geometry
Make a copy of the geometry
Replace the object’s geometry by calling doc.Objects.Replace
By following these rules, undo and redo work for the end user.
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.
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?
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.