Rectangle On Planar Srf

Hello there,

so this is a maybe a newbie question, but is there a way to place or construct a rectangle on a planar but twisted in space srf?
I mean without align the cplane because I need it for a makro.
something like _InterpRectangleOnSrf

Thanks in advance

from Rhino import *
from Rhino.Geometry import *
from Rhino.Commands import *
from Rhino.Input.Custom import *
from scriptcontext import doc
from System.Drawing import *

def Rectangle(surface, x1,y1,x2,y2):
    e1 = surface.ShortPath(Point2d(x1,y1), Point2d(x2,y1),doc.ModelAbsoluteTolerance)
    e2 = surface.ShortPath(Point2d(x2,y1), Point2d(x2,y2),doc.ModelAbsoluteTolerance) 
    e3 = surface.ShortPath(Point2d(x2,y2), Point2d(x1,y2),doc.ModelAbsoluteTolerance)
    e4 = surface.ShortPath(Point2d(x1,y2), Point2d(x1,y1),doc.ModelAbsoluteTolerance)
    return Curve.JoinCurves([e1,e2,e3,e4])[0]

def RunCommand():
    filter = DocObjects.ObjectType.Surface
    rc, objref = Input.RhinoGet.GetOneObject("Select Surface to draw rectangle on", False, filter)
    if rc != Commands.Result.Success: return rc

    surface = objref.Surface()
    if not surface: return Commands.Result.Failure

    gp = GetPoint()
    gp.SetCommandPrompt("First corner")
    gp.Constrain(surface, False)
    if gp.CommandResult() <> Result.Success:
        return gp.CommandResult()
    c1 = gp.PointOnSurface()

    gsp = GetSecondPoint(surface, c1)
    gsp.SetCommandPrompt("Other corner")
    gsp.Constrain(surface, False)
    if gsp.CommandResult() <> Result.Success:
        return gsp.CommandResult()
    c2 = gsp.PointOnSurface()

    return Commands.Result.Success

class GetSecondPoint (GetPoint):
    def __init__(self, surface, c1):
        self.m_surface = surface
        self.m_c1 = c1

    def OnDynamicDraw(self, e):
        cp = self.m_surface.ClosestPoint(e.CurrentPoint)
        curve = Rectangle(self.m_surface, self.m_c1[1],self.m_c1[2],cp[1],cp[2])
        e.Display.DrawCurve(curve, Color.Black)

if __name__=="__main__":
    RunCommand() (1.9 KB)


You can make this with a 3 point rectangle and 3 “On surface” object snaps. In principle it should work with just one “Persistent On Surface” object snap at the beginning, but I see it doesn’t. This looks like a bug.

1 Like

Wow cool!
more than I expected, works flawlessly thanks a lot!

Hello - use CPlane > Object, set the plane to your surface, make the rectangle, and if needed CPlane > Undo to get back to the previous CPlane.


Ok this script runs perfekt! but how can I create a command out of this on Rhino for Mac? it is much easyer on a Windows I guess but I switch my operating system one month ago… is there a easy way like
creating a new command with a script like:
“” ?