Forgot password?

Create an account!

Forum

« back

RhinoScript – Trying to make Fern Fractal, error in script

Messages

Please log in to write a message.

  • 1. azrieli-cole (Mar 10, 2016 21.54):

    Hi, I'm pretty new with RhinoScript and Python, but I am trying to write the code for a fern shaped fractal. I am running into an error which says,

    "Message: unsupported operand type(s) for -: 'list' and 'Point3d'

    Traceback:
    line 10, in Fern, "P:\Documents\Grasshopper\Rhinoscript Tutorials\Fern1.2.py"
    line 52, in Main, "P:\Documents\Grasshopper\Rhinoscript Tutorials\Fern1.2.py"
    line 54, in <module>, "P:\Documents\Grasshopper\Rhinoscript Tutorials\Fern1.2.py"

    I am not very good at interpreting what the issue is. Below is my script. Any help would be much appreciated!

    -Cole

    import rhinoscriptsyntax as rs

    def Fern(crv):
        if (rs.CurveLength(crv)) > 1:
            startPt = rs.CurveStartPoint(crv)
            endPt = rs.CurveEndPoint(crv)
           
            #rightbranch
            rightPt = MidPtLoaded(startPt, endPt, 1, 5)
            rightTrans = rightPt - startPt
            rightBranch = rs.CopyObject(crv, rightTrans)
            rightBranch = rs.RotateObject(rightBranch, rightPt, -60, None, False)
            rightEndPt = rs.CurveEndPoint(rightBranch)
            rightEndPt = MidPtLoaded(rightPt, rightEndPt, 4, 1)
            rs.DeleteObject(rightBranch)
            rightBranch = rs.AddLine(rightPt, rightEndPt)
           
            #leftbranch
            leftPt = MidPtLoaded(startPt, endPt, 1, 2)
            leftTrans = leftPt - startPt
            leftBranch = rs.CopyObject(crv, leftTrans)
            leftBranch = rs.RotateObject(leftBranch, leftPt, 60, None, False)
            leftEndPt = rs.CurveEndPoint(leftBranch)
            leftEndPt = MidPtLoaded(leftPt, leftEndPt, 4, 1)
            rs.DeleteObject(leftBranch)
            leftBranch = rs.AddLine(leftPt, leftEndPt)
           
            #trunk
            translation = endPt - startPt
            crvNew = rs.CopyObject(crv, translation)
            crvNew = rs.RotateObject(crvNew, endPt, -5, None, False)
            endPtNew = rs.CurveEndPoint (crvNew)
            point = MidPtLoaded(endPt, endPtNew, 1, 7)
            rs.DeleteObject(crvNew)
            crvNew = rs.AddLine(endPt, point)
            Fern(crvNew)
            Fern(rightBranch)
            Fern(leftBranch)

    def MidPtLoaded(aP1, aP2, load1, load2):

        MidPtLoaded = None
        MidPtLoaded = [(aP1[0]*load1 + aP2[0]*load2) / (load1+load2),
        (aP1[1]*load1 + aP2[1]*load2) / (load1+load2),
        (aP1[2]*load1 + aP2[2]*load2) / (load1+load2)]
        return MidPtLoaded

    def Main():
        #get object
        crv = rs.GetObject('Select Line', rs.filter.curve)
        #run Fern function
        Fern(crv)

    Main()
Recommend

Why are these buttons gray?