MeshFace.Set -- how does it work?

Greetings.
For example, if I need to change in a mesh quad face one vertex to another by swaping their indeces?
I’m trying to use this method MeshFace.Set Method (Int32, Int32, Int32, Int32)
Heres my code:

Mesh_Faces_list = My_Mesh_Ref.Faces
    
this_face = Mesh_Faces_list.GetFace(1)
print("Before:")
print(this_face)

print("Trying:")
this_face.Set(1, 2, 3, 4)
print(this_face)

print("After:")
Mesh_Faces_list = My_Mesh_Ref.Faces
this_face = Mesh_Faces_list.GetFace(1)
print(this_face)

But I get this result:

Before:
Q(5, 3, 2, 4)
Trying:
Q(1, 2, 3, 4)
After:
Q(5, 3, 2, 4)

Theres also Item method which seems may do the same
https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Geometry_MeshFace_Item.htm

print("Trying:")
this_face.Item[1] = 11
print(this_face)

But the result is the same

Hi,

You’re currently copying the mesh face at index 1 into a variable this_face and changing it, which only changes the copy.

You can either set the relevant mesh face to the copy, after changing the copy:

Mesh_Faces_list = My_Mesh_Ref.Faces

print My_Mesh_Ref.Faces[1]

this_face = Mesh_Faces_list.GetFace(1)
this_face.Set(1, 2, 3, 4)

My_Mesh_Ref.Faces[1] = this_face

print My_Mesh_Ref.Faces[1]

Or you can change it directly for the mesh:

import Rhino

print My_Mesh_Ref.Faces[1]

My_Mesh_Ref.Faces[1] = Rhino.Geometry.MeshFace(1, 2, 3, 4)

print My_Mesh_Ref.Faces[1]

Thanks, it works… of course

diff-arch, just to make this topic quite clear to me, can you please explain such a behaviour:
If I place for example this MeshFase.Set modification function to the imported module,
and I pass mesh Guid to this module from the main script, so I get the mesh object inside this module like that:

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

So, when I check for this Mesh changes while calling inside module - they are done fine.
But when the same chek is done from the main script body, after calling module function of course,
theres no changes in Mesh geometry… why is that?

It’s probably the same issue as above. When you pass the mesh into your function, you need to pass it by reference, which can be tricky in Python. Otherwise, it gets copied when it’s passed in and everything you do is performed on the copy. Meanwhile, the original mesh remains the same.