Grasshopper

algorithmic modeling for Rhino

Hi,

 

i am new to scripting and having trouble to run a function.

 

my code is:

 

 

    .....


      for(int k = 0; k < gridList.Count; k++)
      {
        List <Rectangle3d> newGrid = subdivide(gridList[k], densityList[k]);

      }

    .....

 

 

//Start of Function

 

  private List<Rectangle3d> subdivide (Rectangle3d startRectangle, int recursiveNum)
  {
    if (recursiveNum != 0)
    {
      List < Point3d > centreList = new List<Point3d>();
      List<Plane> subplaneList = new List<Plane>();
      List<Rectangle3d> subgridList = new List<Plane>();

 

           for(int j = 0; j < recursiveNum; j++)

        for(int i = 0; i < recursiveNum; i++)
        {
          // get the point for each plane
          Point3d centrePoint = startRectangle.PointAt((1 / recursiveNum * i), (1 / recursiveNum * j));
          centreList.Add(centrePoint);
        }

      for(int u = 0; u < centreList.Count; u++)
      {
        // construct the new plane
        Plane subplane = new Plane(centreList[u], startRectangle.Plane.Normal);
        subplaneList.Add(subplane);

        // add a new rectangle to the new subgrid
        Rectangle3d finalRectangle = new Rectangle3d(subplaneList[u], recursiveNum, recursiveNum);
        subgridList.Add(finalRectangle);

        return subgridList;
      }
    }
  }

 

 

My error is:

1. Error: Der Typ System.Collections.Generic.List<Rhino.Geometry.Plane> kann nicht implizit in System.Collections.Generic.List<Rhino.Geometry.Rectangle3d> konvertiert werden. (line 255)

 

It seams that there is some issue with the List of Planes, but i dont get it.

 



Any help would be appreciated. 

 

Cheers, Peter.

Views: 319

Replies to This Discussion

Sorry i did a mistake in posting a little syntax error.

 

    .....


      for(int k = 0; k < gridList.Count; k++)
      {
        List <Rectangle3d> newGrid = subdivide(gridList[k], densityList[k]);

      }

    .....

 

 

//Start of Function

 

  private List<Rectangle3d> subdivide (Rectangle3d startRectangle, int recursiveNum)
  {
    if (recursiveNum != 0)
    {
      List < Point3d > centreList = new List<Point3d>();
      List<Plane> subplaneList = new List<Plane>();
      List<Rectangle3d> subgridList = new Liststrong>Rectangle3d>();

 

           for(int j = 0; j < recursiveNum; j++)t

        for(int i = 0; i < recursiveNum; i++)
        {
          // get the point for each plane
          Point3d centrePoint = startRectangle.PointAt((1 / recursiveNum * i), (1 / recursiveNum * j));
          centreList.Add(centrePoint);
        }

      for(int u = 0; u < centreList.Count; u++)
      {
        // construct the new plane
        Plane subplane = new Plane(centreList[u], startRectangle.Plane.Normal);
        subplaneList.Add(subplane);

        // add a new rectangle to the new subgrid
        Rectangle3d finalRectangle = new Rectangle3d(subplaneList[u], recursiveNum, recursiveNum);
        subgridList.Add(finalRectangle);

        return subgridList;
      }
    }
  }

 

But i still get a error:

 

0. Warning: Unerreichbarer Code entdeckt. (line 268)
1. Error: Script_Instance.subdivide(Rhino.Geometry.Rectangle3d, int): Nicht alle Codepfade geben einen Wert zurück. (line 249)

 

Unaccessible Code detected.

Not all Codepath return a value

 

So that is the real error

 

thx Peter

 

if (recursiveNum != 0)
{

  ....

}

 

If recursiveNum equals Zero, then this function won't return any values. You should add a

 

return null;

 

or

 

throw new InvalidOperationException("blahblah");

 

to the end of your function.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you David,

 

that mistake was a kind of obiously, seams that i get a kind of tiered.

 

greetz Peter

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