New to python-triangular prism “roof” command

Hey all, I’m very new to python and am trying to create a simple command that creates a triangular prism, basically a pitched roof.

It’s seems like it would be simple, i want to use getBox to define the volume with three point entry, the first line to define the direction of the pitch, then the base, finally the height.

But it keeps giving me an error when I try to set the mode parameter?

Also getBox always returns the points counter clockwise, and I want to be able to define the direction, so that doesn’t seem helpful.

Any ideas?

Well a sample of your code would be helpful for determining where exactly you go wrong. This can certainly be done.

Hi @barron.crawford,

Here is something to start with:

import Rhino
import scriptcontext as sc

def TriangularPrism():
    
    rc, origin = Rhino.Input.RhinoGet.GetPoint("Base point of triangular prism", False)
    if rc != Rhino.Commands.Result.Success:
        return
    
    mode = Rhino.Input.GetBoxMode.Corner
    rc, box = Rhino.Input.RhinoGet.GetBox(mode, origin, None, None, None)
    if rc != Rhino.Commands.Result.Success:
        return

    # TODO...

– Dale

Hey Dale! Thank you! That solves my question about setting modes! Below is just a simple modification of it. My next question is how can I determine the second point that’s set in a three point box? I want to use that to determine the direction, but because getBox returns points counterclockwise based on the cplane I don’t know how to make it consistent

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs


origin =rs.GetPoint("Base point of triangular     prism")


mode = Rhino.Input.GetBoxMode.ThreePoint
box = rs.GetBox(mode, origin, None, None, None)

rs.AddTextDot("0", box[0])
rs.AddTextDot("1", box[1])
rs.AddTextDot("2", box[2])
rs.AddTextDot("3", box[3])
rs.AddTextDot("4", box[4])
rs.AddTextDot("5", box[5])
rs.AddTextDot("6", box[6])
rs.AddTextDot("7", box[7])

Ah! I did some research and decided to go a different route! the GetBox method seemed unreliable.

This works!

One stylistic question though:
I would love for the dynamic draw to be more representative. But when I tried to draw line based off of the cursor but with transformations, everything hung. Is it possible to dynamically draw the object as I’m creating it?

import Rhino
import System
import rhinoscriptsyntax as rs
import scriptcontext as sc


clr = System.Drawing.Color.Gray

def pickPoint1(pt0):
    def dynamicDrawFunc( sender, args):
        pt = args.CurrentPoint
        args.Display.DrawLine(pt0, pt, clr, 1)

    gp = Rhino.Input.Custom.GetPoint()
    gp.DynamicDraw += dynamicDrawFunc
    gp.Get()
    if( gp.CommandResult() == Rhino.Commands.Result.Success ):
        pt1 = gp.Point()
        return (pt1)

def pickPoint2(pt1):

    def dynamicDrawFunc( sender, args):

        pt = args.CurrentPoint
        args.Display.DrawLine(pt0, pt1, clr, 1)
        args.Display.DrawLine(pt1, pt, clr, 1)

    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Offset point")
    gp.DrawLineFromPoint(pt1, True)
    plane = rs.PlaneFromPoints(pt0, pt1, [pt0.X, pt0.Y, pt0.Z+1])
    line = Rhino.Geometry.Line(pt1, pt1 + plane.Normal)
    gp.Constrain(line)
    gp.DynamicDraw += dynamicDrawFunc
    gp.Get()
    if( gp.CommandResult() == Rhino.Commands.Result.Success ):
        pt2 = gp.Point()
        return (pt2)

def pickPoint3(pt2):
    def dynamicDrawFunc( sender, args):
        pt = args.CurrentPoint
        args.Display.DrawLine(pt0, pt1, clr, 1)
        args.Display.DrawLine(pt1, pt2, clr, 1)
        args.Display.DrawLine(pt2, pt, clr, 1)

    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("Offset point")
    gp.DrawLineFromPoint(pt2, True)
    plane = sc.doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
    line = Rhino.Geometry.Line(pt2, pt2 + plane.Normal)
    gp.Constrain(line)
    gp.DynamicDraw += dynamicDrawFunc
    gp.Get()
    if( gp.CommandResult() == Rhino.Commands.Result.Success ):
        pt3 = gp.Point()
        return (pt3)



pt0 =rs.GetPoint("Base Point")
if pt0:
    pt1 = pickPoint1(pt0)
    if pt1:
        line = ([0,0,0], [30,2,0])
        pt2 = pickPoint2(pt1)
        if pt2:
            pt3 = pickPoint3(pt2)
            if pt3:
                vertex = [(pt1.X+pt2.X)/2, (pt1.Y+pt2.Y)/2, pt3.Z]
                triPts=[pt1, pt2, vertex, pt1]
                triangle = rs.AddPolyline(triPts)
                brep = rs.ExtrudeCurveStraight( triangle, pt1, pt0 )
                rs.CapPlanarHoles( brep )
                rs.DeleteObject(triangle)

@barron.crawford, see if this is helpful: PrismFrom4Points.py (3.1 KB)

_
c.