Geometry change with imported module (scripting basics)

another boring nooby question from me :}
For example I have main script and imoprted module. Inside main script i create a Mesh with:


Then I pass Guid of this Mesh to module function, and select it with

My_Mesh_Ref = sc.doc.Objects.FindGeometry(My_Mesh_Guid)

Then this imported function makes some modifications with this Mesh Reference. I’m sure that they are because I perform an inspect for that.
After that while making just the exact same inspection but in the main script it turns out, that the original mesh remains the same.
I’m just missing something important… how do I update original Mesh with its modified reference?

I seem to have found a way to achieve the desired result: just create a new Mesh from this modified reference, and delete the old one.
But I’m not sure if this is the most graceful solution.
However, it works, so be it.

I am very sorry to bore you with ridiculous questions, and yet I would be very grateful if someone could explain to me such a simple thing:
When I select an object using sc.doc.Objects.FindGeometry and get its reference, it means that I get a kind of copy of the object, but not the object itself !? Therefore, I need to commit all changes through deleting the old object and creating a new one from this modified reference?
For example, if I changed coordinates of a vertex in a Mesh, is this the correct way, or there is another better and correct way to do it?

Not really, you get the unique identifier of the object, which keeps track it, much like a memory address keeps track of objects in memory.

Can you post an example of what you try to do?

How do you currently do it? It’s important not to copy the vertex into a new variable and apply the changes there, but apply the changes directly to the mesh itself.

Heres my try:

Mesh_Ref = Rhino.DocObjects.ObjRef(Mesh_Guid)
Mesh_Itself = Mesh_Ref.Mesh()
print(Mesh_Itself.Vertices[1])  # prints 1,1,1
Mesh_Itself.Vertices.Item[1] = rhg.Point3f(100, 100, 100)
print(Mesh_Itself.Vertices[1])  # prints 100,100,100

but viewport Mesh remains. I also tried this kind of “direct surgery” variant, but without succes:

Rhino.DocObjects.ObjRef(Mesh_Guid).Mesh().Vertices.Item[1] = rhg.Point3f(100, 100, 100)
Mesh_Itself.Vertices.Item[1].X = 100  # does not SET
print(Mesh_Itself.Vertices.Item[1].X)   # but gets fine, prints 1

though it says “Gets or sets the X (first) component of the vector” here

This function makes a copy of the input mesh.

Does this help?

– Dale

Thank you @Dale,
so, adding new Mesh anyway, as I understand, no way to modify existing one!? If I would like to make some simple animation with mesh vertices moving, it means that I need to delete the previous mesh and AddMesh for each iteration…, am I right? Basically, thats ok, I’ll live with that.
I got another question, please help: how do I make an independent copy of Mesh.Vertices?
for example:

this_mesh = objref.Mesh()
now_meshVerts = this_mesh.Vertices

NewVertsPos = rhg.Point3f(9,9,9)
now_meshVerts.Item[3] = NewVertsPos


I got:
while I need
copy.deepcopy doesnt work with mesh.vertices… I also found MemberwiseClone in MeshVertexList class, but I dont uderstand how it works :frowning:
Of course I can iterate through each vertex and append it to some empty list, but I hoped theres some faster way…

You could use Mesh.Vertices.ToPoint3dArray()

1 Like

:)) Thank you @AndersDeleuran
it does work how intended. ToPoint3fArray to be exact
In my defense, I will say: on a MeshVertexList info page I searched for the word “copy” and there is no such word in a description of ToPoint3fArray method… it has “Copies” :slight_smile:
MemberwiseClone has… so Im only halfly dumb

1 Like