You can make a new object and then “replace” it:
import scriptcontext as sc
— do you thang—
sc.doc.Objects.Replace(oldOBJ, newOBJ)
Does that help?
By the way, the new object shall not be an object in the document, just a newly defined object (use rhino commn to make a new one or coerce a mesh, or make a new mesh or coerce something else or something)
Read more here: