Forgot password?

Create an account!

Forum

« back

RhinoScript – Find Area centroid

Messages

Please log in to write a message.

  • 11. Hanno (Nov 12, 2013 12.23):

    Hi,

    if you still need help with this one: You need to put your curves into an array, like this:

    rhino.AddLoftSrf Array(crvAbove1, crvBelow1)

    AddLoftSrf can take any number of curves, therefore the array.

    Hanno

  • 10. deriva (Oct 30, 2013 03.00):

    sorry, in the post below I left the '(quote) in front AddLoftSrf, otherwise wouldn't even run...

  • 9. deriva (Oct 30, 2013 02.54):

    Thanks Hanno, it's funny...I was writing you that it didn't work when I realized what I was missing and eventually fixed it. Thanks again, you pointed me in the right direction! babysteps...now it's the Loft that doesn't work:

    If IsArray(arrMP1) Then
                                           
                                            ' Add point in centroid
                                            Rhino.AddPoint arrMP1(0)
                                            Rhino.AddPoint arrMP2(0)
                                            Rhino.AddPoint arrMP3(0)
                                            Rhino.AddPoint arrMP4(0)
                                           
                                            ' Draw circles
                                            crvAbove1 = Rhino.AddCircle(arrPlane1, 0.5)
                                            crvAbove2 = Rhino.AddCircle(arrPlane2, 0.7)
                                            crvBelow1 = Rhino.AddCircle(arrPlane3, 0.4)
                                            crvBelow2 = Rhino.AddCircle(arrPlane4, 0.6)
                                           
                                            'rhino.AddLoftSrf crvAbove1, crvBelow1
                                           
                                    End If

    loft asks for an array...I also tried something like this:
    crvAbove1 = Rhino.AddCircle(Array(arrPlane1, 0.5), (arrPlane3, 0.4))

    now I'm confused. best
    deriva

  • 8. Hanno (Oct 28, 2013 08.50):

    Hi,

    that's the same problem, opposite direction... AddCircle() requires a geometric plane (i.e. origin + 2 vectors), not a surface object. You could for exampe use Rhino.PlaneFromPoints to create a plane for each triangle with the centroid as origin and any two of the triangle points as the other points.

    Hanno

  • 7. deriva (Oct 27, 2013 22.04):

    Hi Johannes,
    thank you, it worked. Actually I had to create multiples arrays because I need all the centroids, see attached image.

    Now I am stuck on the 'addCircle' command, it says it requires an arrays of planes and the diameter...i tried to use 'idSrf', but didn't work; I tried to put that into and array 'arrSrf' and call the latter into the addCircle function but nothing. My goal is to create different size circles on the faces and then loft them...like i did manually in the capture. ;)

    What am I doing wrong now?
    Thanks

    ' Draw panels
                                    idSrf1 = Rhino.AddSrfPt(Array(topPts(0), topPts(1), topPts(2)))
                                    idSrf2 = Rhino.AddSrfPt(Array(topPts(2), topPts(3), topPts(0)))
                                    idSrf3 = Rhino.AddSrfPt(Array(botPts(0), botPts(1), botPts(2)))
                                    idSrf4 = Rhino.AddSrfPt(Array(botPts(0), botPts(2), botPts(3)))
                                   
                                    'Find centroid
                                    arrMP1 = Rhino.SurfaceAreaCentroid(idSrf1)
                                    arrMP2 = Rhino.SurfaceAreaCentroid(idSrf2)
                                    arrMP3 = Rhino.SurfaceAreaCentroid(idSrf3)
                                    arrMP4 = Rhino.SurfaceAreaCentroid(idSrf4)
                                   
                                    arrSrf = Array(idSrf1, idSrf2, idSrf3, idSrf4)         
                                   
                                   
                                    If IsArray(arrMP1) Then

                                            Rhino.AddPoint arrMP1(0)
                                            Rhino.AddPoint arrMP2(0)
                                            Rhino.AddPoint arrMP3(0)
                                            Rhino.AddPoint arrMP4(0)
                                           
                                            Rhino.AddCircle arrSrf(0), 0.5
                                            Rhino.AddCircle arrSrf(1), 0.3
                                            Rhino.AddCircle arrSrf(2), 0.4
                                            Rhino.AddCircle arrSrf(3), 0.2
                                           

                                    End If
  • 6. Johannes (Oct 27, 2013 19.41):

    Hi, that's because the output of the function Rhino.SurfaceAreaCentroid() is an array with two informations in it. (Nested array)

    0: Array (3-D Point)
    The centroid point.

    1: Array (X,Y,Z)
    The absolute (+/-) error bound for the area centroid.

    That should work:

    If IsArray(arrMP) Then
       Rhino.AddPoint arrMP(0)
    End If

    And:

    arrMP() = Rhino.SurfaceAreaCentroid(idSurf)

    should look like:

    arrMP = Rhino.SurfaceAreaCentroid(idSurf)

    It's an array not a function.

    And i see two times "Rhino.AddSrfPt()" without return value. So only the first one is used for idSurf.

    Johannes

  • 5. deriva (Oct 27, 2013 16.51):

    oops, didn't notice that just JPGs can be uploaded.

                                    ' Set current layer
                                    Rhino.CurrentLayer "panelLayer"
           
                                    ' Draw panels
                                    idSurf = Rhino.AddSrfPt(Array(topPts(0), topPts(1), topPts(2)))
                                    'idSurf() = Rhino.AddSrfPt(Array(topPts(2), topPts(3), topPts(0)))
                                    Rhino.AddSrfPt(Array(botPts(0), botPts(1), botPts(2)))
                                    Rhino.AddSrfPt(Array(botPts(0), botPts(2), botPts(3)))
                                   
                                    'Find centroid
                                    arrMP() = Rhino.SurfaceAreaCentroid(idSurf)
                                   
                                    If IsArray(arrMP) Then

                                            Rhino.AddPoint arrMP()

                                    End If

  • 4. deriva (Oct 27, 2013 16.42):

    Hi Hanno,
    thank you, I get your point, it makes sense of course; but I can't make it work yet. Now the array 'arrMP' or 'idSurf' are 'out of range'. I am a beginner, as you probably figured out, I have read the primer and much more other stuff, I do not understand why I have to declare the size of an array before hand...I might not even know the Ubound upfront, right?

    attached the rhinoscript file.

    Thanks,
    Deriva

  • 3. Hanno (Oct 27, 2013 08.47):

    Hi,

    SurfaceAreaCentroid expects a surface object as parameter (i.e. a string). You are feeding it a list of 3 points instead. This is how it should work:

    idSrf = Rhino.AddSrfPt Array(topPts(0), topPts(1), topPts(2))
    arrMP() = Rhino.SurfaceAreaCentroid(idSrf)

    Best

    Hanno

  • 2. deriva (Oct 26, 2013 20.00):

    this is the area that is crating the problem...

  • 1. deriva (Oct 26, 2013 19.02):

    Hi all,
    I made a script that creates triangular faces and spaceframe structure between two surfaces...it's working fine, but now I want to find centroid areas of all the triangles and draw circles on them using the centroid as center of the circle.

    But I got stuck: it says "string required", but I'm not dealing with arrays?

    Option Explicit

    Call Main

    Sub Main()
     
            Const rhObjectSurface = 8
     
            Dim topSurf, botSurf
            Dim numU, numV
            Dim i, j
            Dim dist, rad
            Dim dirVect
            Dim myPlane
            Dim Fast, FlipSurf
            Dim topPts(), botPts()
            Dim arrParam(1)
            Dim Param
            Dim topDomainU, topDomainV
            Dim botDomainU, botDomainV
            Dim arrMP()
     
            ' Define Parameters
            numU = 7
            numV = 7
            Fast = True
     
            ' Dimension Arrays
            ReDim topPts(3)
            ReDim botPts(3)
            ReDim arrMP(98)
     
    'more stuff here about all the points then

            ' Draw Bottom Structure
                                   
                                    If i < (numU ) Then Call DrawCylinder(botPts(0), botPts(1))
                                    If j < (numV) Then Call DrawCylinder(botPts(0), botPts(2))
                                   
           
                                    ' Set current layer
                                    Rhino.CurrentLayer "panelLayer"
           
                                    ' Draw panels
                                    Rhino.AddSrfPt Array(topPts(0), topPts(1), topPts(2))
                                    Rhino.AddSrfPt Array(topPts(2), topPts(3), topPts(0))
                                    Rhino.AddSrfPt Array(botPts(0), botPts(1), botPts(2))
                                    Rhino.AddSrfPt Array(botPts(0), botPts(2), botPts(3))
                                   
                                    'Find centroid
                                    arrMP() = Rhino.SurfaceAreaCentroid(Array(topPts(0), topPts(1), topPts(2)))
                                   
                                    If IsArray(arrMP) Then

                                            Rhino.AddPoint arrMP(0)

                                    End If


                            Next
         
                    Next
     
            End If

    any idea what's wrong?

    Thanks

Recommend

Why are these buttons gray?