c#_OrientGeometry_PlaneToPlane

Hello,
Can some correct me where exactly I’m going wrong in this script. I am trying to orient a geometry from one plane to another. It does not give me any error but gives really weird output (always a rectangular surface as an output even if input surface is something else)

PFA images and script.

  private void RunScript(List<Surface> x, object y, ref object A, ref object B, ref object C)
  {
    Surface srf = x[0];
    Point3d pEval;
    Vector3d[] vecEval;
    Plane plnEval;
    srf.Evaluate(0.5, 0.5, 3, out pEval, out vecEval);
    srf.TryGetPlane(out plnEval);
    plnEval.Origin = pEval;
    
    Transform orient = Transform.PlaneToPlane(plnEval, new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)));
    srf.Transform(orient);
    
    A = pEval;
    B = vecEval;
    C = plnEval;
    D = srf;
  }

Hi @obhagwat29,

Can you provide a complete solution that we can run here?

– Dale

find attached solution
Orient_Geometry_omkar.gh (24.5 KB)

You can use Surface.FrameAt:

Plane plnEval;
srf.FrameAt(0.5, 0.5, out plnEval);
Transform orient = Transform.PlaneToPlane(plnEval, Plane.WorldXY);
srf.Transform(orient);
A = srf;
B = plnEval;

Omkar.gh (13.4 KB)

@Mahdiyar Thank you for your reply.
I think something is still wrong. Did you try giving input the surface I have in script?
I tried your script on the surface, still it is giving wrong geometry.
Find attached your script with geometry input that I want to orient, let me know if you get correct result

Thanks!
Orient_Revised.gh (42.9 KB)

  private void RunScript(Brep srf, ref object A)
  {
    Plane plnEval;
    srf.Faces[0].FrameAt(0.5, 0.5, out plnEval);
    Transform orient = Transform.PlaneToPlane(plnEval, Plane.WorldXY);
    srf.Transform(orient);
    A = srf;
  }

Omkar.gh (48.3 KB)

1 Like

Thanks! it works fine, but I didn’t get it clearly BrepFace class is inherited from Surface class then why using surface.FrameAt not working correctly in this case.

Because I’ve changed the input type from Surface to Brep. Using Brep type makes it easier to deal with trimmed surfaces.

1 Like