Grasshopper

algorithmic modeling for Rhino

Hi.

I am trying to learn GH by recreating a Rhino-assignment we had at uni. The first steps of the assignment were to create a box and rotate 2 copies evenly spread on 360 degrees with the use of the _arraypolar command. The boxes should then be elevated so that the beginning corner of a box should be at the height of the end of the last.

In my attempt to re-create this in Grasshopper, I could not find an arraypolar-component, so I wrote one in c#. It works and places the boxes exactly where Rhino does, but as I am a newbie comments and improvements are welcome:

<code>
    // define params
    double numberOfCopies;

    try
    {
      numberOfCopies = System.Convert.ToDouble(x); //check if input x was a number
    }
    catch (Exception e)
    {
      return; //if not break off execution
    }

    // if no number of copies are requested, abort
    if(numberOfCopies <= 0)
      return;

    // create a list for the return of new angles
    List&#60;double&#62; radian = new List &#60;double&#62;();
    double divider; // use double in order to get double from division

    for(int i = 1; i <= numberOfCopies; i++)
    {
      divider = i / (numberOfCopies + 1); // add 1 to the copies, in order to divide the copies evenly on the 360 degrees
      radian.Add(divider * (2 * Math.PI)); // position along circle by 2pi to get radian
    }

    A = radian; // return list of radian

</code>

In the GH file I have set up an input that will set the number of copies and the return is a list of radian angles. This list is fed into a RotAx component which in turn creates an rotates the copies.
So far so good.

A problem I have is that I can't treat the output from the RotAx component individually. As you can see I want to elevate/move each copy of the box the height of the last. But as I have set it up it moves all copies to the same elevation. How can I set this up so that each copy is elevated higher?

Also, how can I delete the object that was moved, to avoid having the original and the elevated?

..

A further question is if this set-up is valid, or if there are better ways of achieving this?

Cheers,
Eirik

Views: 563

Attachments:

Replies to This Discussion

Hi,

got a bit further with scripting. Now I took the height of the box in a script and created new Vectors where the Z is multiplied by the instance, as this script output (list of vectors) is plugged into the move component I could elevate each box higher.

Here is the code:


// define params
int numberOfCopies;

try
{
numberOfCopies = System.Convert.ToInt32(x); //check if input x was a number
}
catch (Exception e)
{
return; //if not break off execution
}

// if no number of copies are requested, abort
if(numberOfCopies <= 0)
return;

// create a list for the return of new angles
List vectors<Vector3d> = new List<Vector3d>();

Point3d heightOfBox;
try
{
heightOfBox = (Point3d) z;
}
catch(Exception e)
{
return;
}

for(int i = 0; i < numberOfCopies; i++)
{
vectors.Add(new Vector3d(0, 0, heightOfBox.Z * (i + 1)));
}

A = vectors; // return list of vectors



I am very interested to know if I am completely on the wrong path here, being a newbie, or if what I do makes sense. In other words, is this stuff achievable only by use of components, or do I need to keep scripting.

Cheers,
Eirik
Attachments:
You cannot delete old data. Once created, data is always available. You can switch off the preview for data you do not want to see though.

--
David Rutten
david@mcneel.com
Seattle, WA
Hi Eirik, David.

Attached a file with and without scripting, the scripting component outputs the angle and heights. David has explain about the input types, this is a really good feature of the scripting components.

I've just noticed you are now using the heigh of the box as the unit for the translation vector, so you can extract it and plug it in accordingly.

Very interesting to see David's approach.

I hope this helps.

Cheers

Evert
Attachments:
Hi Eirik,

first, how to solve this without scripting.

--
David Rutten
david@mcneel.com
Seattle, WA
Attachments:
I made a few changes to your script in this one. You can specify types for script inputs, which means you won't have to cast data inside your code.

--
David Rutten
david@mcneel.com
Seattle, WA
Attachments:
Dear David and Evert.

Thank you so much for taking the time to go through my code and improve it, I really appreciate it : )

It was extremely interesting to see how the scripting could be avoided by just using the GH components. I will cloesly study the examples, there is much to learn here for me.

Cheers,
Eirik

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service