Modifying the geometry of an object and maintain all other information

Hi,

I’m trying to modify the underlying geometry of a referenced Rhino Geometry.
In this case a polyline, where I want the points of the polyline to move to new location.

I want to keep this simple, and I want the object to maintain all information (including ID if possible).

Now the code below is wrong, as I’m aware that the polyline I’m extracting is a new instance and not actually a reference the geometry of obj. But I hope it kind of shows what I want to do.

import Rhino

obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(x)
polyline= obj.Geometry.TryGetPolyline()[1]
polyline.SetAllX(5.0)
obj.Geometry = polyline
obj.CommitChanges()

obj.Geometry only allows me to get but not set.

I came across this comment from David, which, if I read it right, means that what I want to do is not directly possible, but what would be the best way around it?

Hi,
I’m not the python expert here, but as far as I know, you have to:

  1. create a new instance of your geometry (you’re already doing so with:

polyline= obj.Geometry.TryGetPolyline()[1]

  1. Use the ‘ObjectTable’ method ‘Replace’ (https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.tables.objecttable/replace), to assign the new geometry to the existing object.

It should just modify the geometry. Attributes of your RhinoObject should remain unchanged.

Something like this (not tested :grimacing:)

import Rhino

obj = Rhino.RhinoDoc.ActiveDoc.Objects.Find(objId)
polyline = obj.Geometry.TryGetPolyline()[1]
polyline.SetAllX(5.0)

Rhino.RhinoDoc.ActiveDoc.Objects.Replace(objId, polyline)
Rhino.RhinoDoc.ActiveDoc.Views.Redraw()
1 Like

This seems to be working!
Thank you.
Also it’s worth noting that ID, Attributes and everything remains with your method. Exactly what I was after!

Glad you achieved what you wanted! :slight_smile: