Forgot password?

Create an account!

Forum

« back

RhinoScript – type mismatch

Messages

Please log in to write a message.

  • 6. rolozamora (May 01, 2011 12.57):

    Hi clausneergaard,
    I was wondering if you managed to make your script work, even after Johannes addition it keeps coming back with:

    Typemismatch in parameter. String required.
    Line 56
    Char 16

    Thanks,

  • 5. Johannes (Nov 17, 2010 19.04):

    thats because all objects of your first bounds are still in your array and you add them also to the second group.

    you need to reset your array (arrObjsInside) at the end of your 'i' loop.

                    ReDim arrObjsInside(0)
                    countB = 0
  • 4. clausneergaard (Nov 17, 2010 17.26):

    So, I've now tried to rewrite the script, clean it up a bit ... and I've actually managed to get it to work.

    Now, it seems like it is grouping the curves in a weird way (curves inside a region gets grouped with curves inside outher regions, etc.) - does anyone have ane experience with that?

    thanks in advance.

    the code:

    Option Explicit
    ' script written by Claus Rytter Bruun de Neergaard, 17. november 2010

    ' description:
    ' <descriptive text>

    Call ScriptName()
    Sub ScriptName()

            Dim strBounds : strBounds = Rhino.GetObjects("select boundary curves", 4)
            If IsNull(strBounds) Then Exit Sub
            Dim strObjs : strObjs = Rhino.GetObjects("select other objects to test if inside or outside", 4)
            If IsNull(StrObjs) Then Exit Sub
           
            Dim i, j, countA, countB
            Dim strGroupName
            Dim arrCont, arrObjsInside
            Dim blnClosed, blnPlanar
           
            countA = 0
            countB = 0
            ReDim arrCont(countA)
            ReDim arrObjsInside(countB)
           
            For i = 0 To UBound(strBounds) Step 1
                   
                    blnClosed = Rhino.IsCurveClosed(strBounds(i))
                    If blnClosed = False Then
                            Rhino.Print("Curve " & CStr(i) & " is not a closed curve. Please correct this and run script again.")
                            Rhino.ObjectColor strBounds(i), RGB(255,0,0)
                    End If
                   
                    blnPlanar = Rhino.IsCurvePlanar(strBounds(i))
                    If blnPlanar = False Then
                            Rhino.Print("Curve " & CStr(i) & " is not planar. Please correct this and run script again.")
                            Rhino.ObjectColor strBounds(i), RGB(0,0,255)
                    End If
                   
                    For j = 0 To UBound(strObjs) Step 1
                           
                            ReDim Preserve arrCont(countA)
                            arrCont(countA) = Rhino.PlanarClosedCurveContainment(strBounds(i), strObjs(j))
                           
                            If arrCont(countA) = 3 Then
                                    ReDim Preserve arrObjsInside(countB)
                                    arrObjsInside(countB) = strObjs(j)
                                    countB = countB+1
                            End If
                   
                            countA = countA+1
                           
                    Next
                   
                    strGroupName = CStr(i)
                    Rhino.AddGroup strGroupName
                    Rhino.AddObjectToGroup strBounds(i), strGroupName
                    Rhino.AddObjectsToGroup arrObjsInside, strGroupName
                   
            Next
           
            Rhino.Print("Red curves are not closed curves.")
            Rhino.Print("Blue curves are not planar curves.")
           
    End Sub
  • 3. clausneergaard (Nov 17, 2010 16.16):

    Johannes,

    Thank you for the input. It still doesn't help out, though. It still says the same 'type mismatch' error. I had the ReDim arrObjsInside(0) written at some point, I've must have accidentaly deleted it while trying to figure out what the problem was.

    This is what I find weird about the error. I've been using the

    Dim variable
    ReDim variable(0)
    ReDim Preserve variable(count)

    a bunch of times before, but I've never had that error message before. Well, maybe I can find some other way to make it work.

    Again, thanks.

  • 2. Johannes (Nov 17, 2010 09.20):

    Try the following code at the beginning of your script:

    Dim arrObjsInside       : ReDim arrObjsInside(0)

    first you need to declare your array before you try to resize it (ReDim Preserve).

  • 1. clausneergaard (Nov 16, 2010 23.23):

    Hey,

    can anyone help me out here? I'm running in to problems with this script. It keeps telling me that there's a type mismatch in line 52.

    I'm not sure why it gives me that error?

    Any help would be very much appreciated.

    Thanks.
    /Claus

    Option Explicit
    ' script written by Claus Rytter Bruun de Neergaard, 16. november 2010

    ' description:
    ' script will determine if curves are inside boundary curves. curves inside curves will be grouped.

    Call ScriptName()
    Sub ScriptName()

            ' variables
            Dim i, j, count
            Dim strGroupName
            Dim arrObjsInside
            Dim blnClosed, blnPlanar, blnContainment
           
            ' user input
            Dim strBounds : strBounds = Rhino.GetObjects("select boundaries (closed curves)", 4)
            If IsNull(strBounds) Then Exit Sub
            Dim strContObjs : strContObjs = Rhino.GetObjects("select objects that script will check if is inside boundaries", 4)
            If IsNull(strContObjs) Then Exit Sub
           
            ' loop through all regions (boundary curves)
            For i = 0 To UBound(strBounds) Step 1
                   
                    count = 0
                   
                    ' check if crv is closed
                    blnClosed = Rhino.IsCurveClosed(strBounds(i))
                    If blnClosed = False Then
                            Rhino.Print("Curve " & CStr(i) & " is not a closed curve. Please correct this and run script again.")
                            Rhino.ObjectColor strBounds(i), RGB(255,0,0)
                    End If
                   
                    ' check if curve is planar
                    blnPlanar = Rhino.IsCurvePlanar(strBounds(i))
                    If blnPlanar = False Then
                            Rhino.Print("Curve " & CStr(i) & " is not planar. Please correct this and run script again.")
                            Rhino.ObjectColor strBounds(i), RGB(0,0,255)
                    End If
                   
                    ' for each region (boundary curve) loop through all objects, to see if inside region
                    For j = 0 To UBound(strContObjs) Step 1
                           
                            ' return values of Rhino.PlanarClosedCurveContainment
                            ' 0 : the regions bounded by the curves are disjoint
                            ' 1 : the two curves intersect
                            ' 2 : the region bounded by strCurve1 is inside of strCurve2
                            ' 3 : the region bounded by strCurve2 is inside of strCurve1
                            blnContainment = Rhino.PlanarClosedCurveContainment(strBounds(i), strContObjs(j))
                           
                            If blnContainment = 3 Then
                                    ReDim Preserve arrObjsInside(count)
                                    arrObjsInside(count) = strContObjs(j)
                                    count = count+1
                            End If
                           
                            blnContainment = Null
                           
                    Next
                   
                    ' group objects that are inside strBounds(i)
                    strGroupName = CStr(i)
                    Rhino.AddGroup(strGroupName)
                    Rhino.AddObjectToGroup strBounds(i), strGroupName
                    Rhino.AddObjectsToGroup arrObjsInside, strGroupName
                   
                    arrObjsInside = Null
                    count = Null
                   
            Next
           
            Rhino.Print("Red curves are not closed curves.")
            Rhino.Print("Blue curves are not planar curves.")
           
    End Sub
Recommend

Why are these buttons gray?