Normal vector of plane always same even after rotation

Hi @all,

i would like to measure the normal-vector of a plane before and after rotation.

I only want those surfaces of a brep, which normal-vector in z-dir is -1 and lie at z=0:

for face in brep.Faces:
    plane_of_face = face.TryGetPlane()
    if int(plane_of_face[1].Normal[2]) == -1 and plane_of_face[1].OriginZ == 0:
      brepface_znormal1 = face

So my variable “brepface_znormal1” is the one which normal-vector I want to observe after rotation (user rotates and quits with “ESC”).
Therefore I defined a function which gets called when Rhino fires “EscapeKeyPressed”-Event:

def escape_key_pressed(a, b):
   znormal1_plane_of_face = brepface_znormal1.TryGetPlane()
   print "brepface_znormal1 normal-vector: %s"%znormal1_plane_of_face[1].Normal
rhi.RhinoApp.EscapeKeyPressed += escape_key_pressed

“znormal1_plane_of_face[1].Normal” should give me a new Normal-Vector (after rotation), but I get same values as before the rotation…!?
I even tried it over GUID to identify the plane I want to observe, but this doesnt work either.

Who finds the error?

Kind Regards
Mr Sinter

@Mr_Sinter, your first code snippet does not make sense to me. Starting with this line:

plane_of_face = face.TryGetPlane()

you should take care of that face.TryGetPlane() returns a tuple, so you can find out if the surface can be converted to a plane at all. You may use this instead:

rc, plane_of_face = face.TryGetPlane()

and only proceed with your code if the rc variable equals True. Then plane_of_face is a plane. The line below may be checked as well:

if int(plane_of_face[1].Normal[2]) == -1

to get the normal vector of the plane, and its z-coordinate, you may prefer using this:


…and do not convert that value to an integer using int as this would just convert every value to 1 if the normal points upwards. Note as well that a normal vector is a unit vector, so every normal vector starts at z = 0.

Does that help ?


Thanks clement for your reply,

especially your code snippet
is helpful to me.

Nevertheless i currently found a detour to my Problem.
I convert the plane to a NurbsSurface and back (after Rotation).
Then I get the normal vector before and after Rotation:

brepface_znormal1 = face_with_znormal_1_list[0]
brepface_znormal1_nurbs = brepface_znormal1.ToNurbsSurface()
guid_brepface_znormal1_nurbs = sc.doc.Objects.AddSurface(brepface_znormal1_nurbs)

object_reference_brepface_znormal1_nurbs = rhi.DocObjects.ObjRef(guid_brepface_znormal1_nurbs)
brepface_znormal1_reconverted = rhi.DocObjects.ObjRef.Face(object_reference_brepface_znormal1_nurbs)
brepface_znormal1_reconverted_plane = brepface_znormal1_reconverted.TryGetPlane()
print "downside normal of last letter after transformation = %s" %brepface_znormal1_reconverted_plane[1].Normal

Kind regards
Mr Sinter

Hi @Mr_Sinter,

does the first code snipped in your last reply create the nurbs surface or do you get an error ? My feeling is that you get no error because you´re running this code in a delegate (code which is only run if the esc key pressed event is fired). I´ve reported recently that errors in delegates sometimes do not fire exeptions, which can make error tracking real hard.

You might try your code first in a regular script routine, then if everything works as expected, add it to the event driven function. Btw. is the Esc event really required in this case ? Maybe there is a way to avoid it since Esc generally should serve a different purpose.


hi Clement,

it does create the NurbsSurface as I add it to sc.doc.Objects to get the GUID of it.
After Rotation of it I read again it`s normal vector when ESC key is pressed.

So in Rhino everything works somehow, but it’s sometimes hard to figure out why some ways don’t…

Kind regards