 # Mirror transformation

As of now I have come across a command Rhino.Geometry.Transform.Mirror(point, normal) ,but I am clueless as to how I can actually use it in my code to mirror a curve.

below is one example which shows how to mirror an existing curve object over the y-axis:

``````import Rhino
import rhinoscriptsyntax as rs

def MirrorCurve():
"""Mirror existing curve over y-axis"""

id = rs.GetObject("Select curve to mirror", 4, True, False)
if not id: return

plane = Rhino.Geometry.Plane.WorldYZ
xform = Rhino.Geometry.Transform.Mirror(plane)
m_id = rs.TransformObject(id, xform, copy=False)

if __name__=="__main__":
MirrorCurve()
``````

c.

1 Like

Hi Clement!
That was helpful.Just one more question.How can we select a plane which is parallel to the XZ plane ?

Change WorldYZ to WorldXZ

1 Like

it has to be a plane PARALLEL to the XZ plane ,not XZ plane.

just create the ZX plane, then move the plane’s origin along the Y axis to get a parallel plane:

``````plane = Rhino.Geometry.Plane.WorldZX
plane.Origin = Rhino.Geometry.Point3d(0,20,0)
``````

`plane` is now your parallel plane.

c.

1 Like

Thanks Clement
That worked Just one more question I had.Usually when we mirror an curve/object using command line in Rhino we do not lose the original curve/object.But ,here in scripting we lose the original curve which is to be transformed,Is there a way to avoid the erasing of the original curve?

you can control the copy behaviour in this line of the script above. To make a copy use:

``````m_id = rs.TransformObject(id, xform, copy=True)
``````

c.

1 Like

That worked !
As a last question,can we somehow identify the object id from the curve/object instance without having to select the curve/object?As I have to make a huge number of curves ,so it becomes a little tedious to click the curve several times,so another level of automation would be great,if it is possible.

you can keep track of the id at he moment where you add the curve to the document, then mirror using the id:

``````import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

points = Rhino.Collections.Point3dList(5)

nc = Rhino.Geometry.NurbsCurve.Create(False, 3, points)
if nc and nc.IsValid:
if id:
# mirror using the id
plane = Rhino.Geometry.Plane.WorldYZ
xform = Rhino.Geometry.Transform.Mirror(plane)
m_id = rs.TransformObject(id, xform, copy=True)
scriptcontext.doc.Views.Redraw()

if __name__=="__main__":

``````

alternatively, you can duplicate and mirror your curve before adding it to the document:

``````import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

points = Rhino.Collections.Point3dList(5)

nc1 = Rhino.Geometry.NurbsCurve.Create(False, 3, points)
nc2 = Rhino.Geometry.NurbsCurve.Duplicate(nc1)

plane = Rhino.Geometry.Plane.WorldYZ
xform = Rhino.Geometry.Transform.Mirror(plane)
Rhino.Geometry.NurbsCurve.Transform(nc2, xform)

if nc1 and nc1.IsValid and nc2 and nc2.IsValid:
scriptcontext.doc.Views.Redraw()

if __name__=="__main__":
``````

both examples do not require to select the curve.

c.

1 Like

I was looking out for this method of remembering IDS for so very long but wasn’t able to find it.So greatfull to you that you told me about this.Thanks a lot @clement ! BTW is there a way to save the files as IGES ? As of now I was saving the files as 3dm.

Script the “Save” command using `rs.Command`.

1 Like

you can script the `_-Export` command like below, the script first selects all objects except lights and grips then runs the regular Rhino command:

``````import rhinoscriptsyntax as rs

def ExportIGES():
# select all objects to export
objs = rs.AllObjects(select=True, include_lights=False, include_grips=False)
if not objs: return

# setup path and filename in quotes
file = chr(34) + "D:\Temp\MyTestFileName.iges" + chr(34)

# set iges export type in quotes
iges_type = chr(34) + "Default" + chr(34)

# create export command
cmd = "_-Export " + file + " " + iges_type + " _Enter"

# run the command
rc = rs.Command(cmd, False)
if not rc:
print "Error exporting file {}".format(path)

if __name__=="__main__":
ExportIGES()
``````

## It should work the same using the `_-Save` command.

c.

1 Like

That worked well .

When we use the rs.Getobject() function it returns a GUID.So ,I tried substituting it by the curve ID ,in the way u had described above.But ,it is not working.To refine my question,is there a difference between curve id generated using the Rhino function u told earlier and the GUID which is returned by rs.Getobject(), and if Yes->is there a way to change the Rhino generated curve id to GUID ,to avoid picking up the object by clicking ,rather just using the IDs to further automate the process.

No. There must be an error in the script …
BTW … for info about RhinoCommon classes you can browse the RhinoCommon docs here:
http://4.rhino3d.com/5/rhinocommon/

If we want to rotate the XZ plane and then do the mirror process. how we can do this?
Reza

You are responding to a 4 year old topic. Can you be more precise and post an example of what you are trying to do?

I want to mirror some curves(lines) by method introduced here. but my mirror plane have an angle with XZ Plane. thus its necessary to rotate the main plane XZ according angle. my question is that how I can rotate the XZ plane for using in mirror process?
Reza