Grasshopper

algorithmic modeling for Rhino

Hey there,

 

I'm working on splitting up a surface and then assigning surfaces to groups depending on their areas. In my case I have a list of 7 surfaces which then gets passed to BRep area and also returns a list of 7 areas.

 

I want to pass them into a loop which when the area is matched to an area limit, the 'Face' is then passed out into the correct group. I know there must be a way but I'm new to vbScript and I'm trying to learn off discussions here!

 

Hope you can help,

David

 

My script:

 

RunScript(ByVal Area As Integer, ByVal Face As OnBrep, ByVal BldgLimit As Integer, ByVal ResLimit As Integer, ByVal OffLimit As Integer, ByVal listLength As Integer, ByRef Open As Object, ByRef Resi As Object, ByRef Office As Object, ByRef Retail As Object)

 

    For i As int32=0 To (listLength.count - 1)

      If Area(i) < Bldg Limit Then
      Face(i) = Open
      Else If Area(i) > BldgLimit And < ResLimit Then
        Face(i) = Resi
      Else If Area(i) > ResLimit And < OffLimit
        Face(i) = Office
      Else If Area(i) > OffLimit Then
        Face(i) = Retail
      End If

    Next

Views: 781

Replies to This Discussion

Hi Dave,

you'll want to assign your inputs to your outputs, not the other way around. Since Open, Resi, Office and Retail are your outputs, the assignment looks like this:

Open = Face
Retail = Face

-----------------------

At the moment you are only importing a single Brep, thus calling Face(i) won't do you any good. If you really want to handle lists, you need to enable the List option on the Face input and then you can remove the listLength input. Your new loop will then look like this:

For i As Int32 = 0 To Faces.Count-1

Next


However, this also means you'll need to builds lists of output data, making the whole thing more complicated than it needs to be. May I suggest two alternatives:

1) Only operate on single Breps, don't loop inside your script. This will mean that your output lists will contain many null items, but you can remove those afterwards with a [Clean Tree] component.

2) Instead of outputting the Breps, output a single integer that you can then use to dispatch your Breps using a [Stream Gate] component.

If you're unhappy with these, I can show you how to build lists and assign them to outputs.
-----------------------

About the Area calculation, instead of calculating the Area inside the script, you could choose to use an [Area] component and add an extra input in your script. But I can see the point of doing it locally. This is how you compute the Area of a Brep:

Dim mp As New RMA.OpenNURBS.OnMassProperties()
Face.AreaMassProperties(mp)
Dim area As Double = mp.Area()

-----------------------

Your if-structure is a bit more complicated than it needs to be as well. You could get away with this:

If (area < BldgLimit) Then
'Assign to group 1
Else If (area < ResLimit) Then
'Assign to group 2
Else If (area < OffLimit) Then
'Assign to group 3
Else
'Assign to group 4
End If



--
David Rutten
david@mcneel.com
Poprad, Slovakia
David,

Thank you for your response, I did in fact have an external area function as I didn't know how to do it internally so thank you for this added gem. I've tried taking the loop out with my wording and have tried inputting yours as well but all I get is nulls!

I will try the approach returning integers but I'm also interested in nutting this approach out for my future benefit. I've attached my sample files this time so hopefully it helps.

Regards,
David
Attachments:
Well yes, the 'Assign to group 1 was only a placeholder I put in. You have to actually replace it with code that does something.

I was wrong about the Stream Gate component, it won't help you, it's basically useless for this kind of sorting.

I'll upload a file soon.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
File attached.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
Haha, for some reason I thought by matching the first conditional statement the simplified code would be assigned to the first output! I was amazed at the simplicity! ;)

Too good to be true... Thank you for your help David, I know understand your profile picture, but I'm learning!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service