Forgot password?

Create an account!


« back

RhinoScript – orient mesh / blockinstance to curve


Please log in to write a message.

  • 7. atac (Jun 10, 2011 20.02):

    I think I have to make some redesigns. So its good to have the script. And the script is also usefull for other objects for example light, rails, or the structure (I am moddeling a sports stadium.) I'm just at the beginning and I think the design will change during the progress.

    I don't know exactly how much curves I need, but I know I have to orient 10.000 seats. I think I need some curves for this number.

    It took me 10-20 minuets to write the script, but I tried 2-3 hours to find out how to get the normal vector... Thank you very much for your help!!

    Have a nice weekend,

  • 6. ledisnomad (Jun 10, 2011 17.40):

    Oops, here's the code:

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version Friday, 10 June 2011 01:45:05

    Call ArrayAlongCurves()
    Sub ArrayAlongCurves()
            Dim strObj, arrbbox, arrRef, arrTarget
            Dim arrCurve, length
            Dim arrDivPoint
            Dim i, j, dblCrvPara, arrCurvePerpFrame, arrNormal
            Dim line1, line2, mid1, mid2
            strObj = Rhino.GetObject("Select Object to orient")
            If IsNull(strObj) Then Exit Sub
            arrCurve = Rhino.GetObjects("Pick Curves to orient object to",4)
            If IsNull(arrCurve) Then Exit Sub
            length = Rhino.GetReal("Division length")
            If IsNull(length) Then Exit Sub
            Call Rhino.EnableRedraw(False)
            arrbbox = Rhino.BoundingBox(strObj,,True)
            'line1 = Rhino.AddLine(arrbbox(0),arrbbox(3))
            'line2 = Rhino.AddLine(arrbbox(1),arrbbox(2))
            'mid1 = Rhino.CurveMidPoint(line1)
            'mid2 = Rhino.CurveMidPoint(line2)
            'arrRef = array(mid1,mid2)
            arrRef = array(arrbbox(0), arrbbox(1))
            For j=0 To UBound(arrCurve)

                    arrdivPoint = Rhino.DivideCurveLength(arrCurve(j),length)

                    For i=0 To ubound(arrdivpoint)
                            dblCrvPara = Rhino.CurveClosestPoint(arrCurve(j),arrDivPoint(i))                
                            arrCurvePerpFrame = Rhino.CurvePerpFrame(arrCurve(j),dblCrvPara)               
                            arrNormal = Rhino.PointAdd(arrCurvePerpFrame(3),arrCurvePerpFrame(0))
                            Call Rhino.OrientObject(strObj,arrRef,arrTarget,1)
            Call Rhino.EnableRedraw(True)

    End Sub
  • 5. ledisnomad (Jun 10, 2011 17.39):

    Having said all that... I took a look at your script and modified it to work. You can edit lines 27-32 to choose a different reference vector so that the object is oriented along the centerline of the object.

  • 4. ledisnomad (Jun 10, 2011 16.55):

    I'm all for writing tools to automate repetitive tasks, but sometimes these tools take longer to script than to do the task. So my questions to you are:

    How many curves are we talking about?
    Are you going to have to repeat the whole process again (for a redesign, for example)?

    I'd say only finish the script if there are a lot of curves and you'll have to do it over and over again for redesigns. I just did a test: I had 8 curves and an object. It took me ~32 seconds to copy the object to the start of each curve then array-along-curve. That's ~4 seconds/curve. If you have 100 curves, that's about 8.3 minutes. How long have you spent on your script, so far?

  • 3. atac (Jun 10, 2011 15.22):

    thank you ledisnomad. good idea to use the arrayCrv command. with the roadlink orientation, it does exactly what I am looking for.

    But I want to do this orientation to more than one curve. Later, I will have an array of curves where the seat should oriented to.

    All I need to do this is the End Point of a Normal Vector on the Curve at a specific parameter.

  • 2. ledisnomad (Jun 10, 2011 14.33):

    hi, atac.

    i haven't looked at your script, yet, but I think there is an easier way... have you tried the ArrayCrv command? If you orient your seat perpendicular to the curve, then choose a Roadlike orientation, it will keep the chair perpendicular all the way along the curve. Unless I'm missing something that you'd like to do. What do you think?

  • 1. atac (Jun 10, 2011 12.36):

    Hi all!

    I want to orient a mesh or blockinstance to a curve. In general I need this script to orient some spektator seats to a curve for a sports stadium. The objects should be oriented to the prependicluar vector at a division point form the curve.

    I have started with the script, but I don't know exactly how to get the two target points for the "orientObject" command.

    Here my script:

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version Friday, 10 June 2011 01:45:05

    Call Main()
    Sub Main()
            Dim strObj, arrbbox,arrRef, arrTarget
            Dim strCurve, length
            Dim arrBasePoint,arrDivPoint
            Dim i, dblCrvPara, arrCurvePerpFrame , b,c

            strObj = rhino.GetObject("Select Object to orient")
            '       arrBasePoint = rhino.GetPoint("Pick BasePoint")
            strCurve = rhino.GetObjects("Pick Curves to orient object to",4)
            length = rhino.GetReal("divide length:")
            arrbbox = rhino.BoundingBox(strObj,,True)       
            arrRef = array(arrbbox(0),arrbbox(1))
            '       Call rhino.AddPoint(arrbbox(0))
            '       Call rhino.AddPoint(arrbbox(1))
            arrdivPoint = rhino.DivideCurveLength(strCurve(0),length,True)

            For i=0 To ubound(arrdivpoint)
                    '########## look for target points
                    dblCrvPara = Rhino.CurveClosestPoint(strCurve(0),arrDivPoint(i))               
                    arrCurvePerpFrame =  rhino.CurvePerpFrame(strCurve(0),dblCrvPara)

                    Dim arrPlane
                    arrplane = arrCurvePerpFrame

                    b= Rhino.AddPlaneSurface(arrPlane,Rhino.Distance(arrPlane(0),arrPlane(1)),Rhino.Distance(arrPlane(0),arrPlane(2)))

                    '       Call rhino.AddPoint(arrCurvePerpFrame(0))
                    '       Call rhino.AddPoint(arrCurvePerpFrame(1))
                    Call rhino.OrientObject(strObj,arrRef,arrTarget,1)
    End Sub

    Thank you very much for help or any ideas!


Why are these buttons gray?