Grasshopper

algorithmic modeling for Rhino

Hi all, 

 

I'm a beginner so I think it will be a silly mistake but i'm fighting with it for a few days...

 

I want to create 4 copies of aBrep (created from a cylinder using .ToBrep) and 4 copies of a sphere.

 

I use the lines below and I get this result: movingBreps.jpg

 

List<Rhino.Geometry.Brep> lst_b = new List<Rhino.Geometry.Brep>();            List<Rhino.Geometry.Point3d> lst_p = new List<Rhino.Geometry.Point3d>();            List<Rhino.Geometry.Sphere> lst_s = new List<Rhino.Geometry.Sphere>();

 

//add the first elements with no translation           
lst_b.Add(brp); //brp is a defined Brep

lst_p.Add(center_point);//center_point is a point
lst_s.Add(sph); //sph is a sphere

//add the rest
for (int i = 0; i <= 2; i++)           
{               
center_point.Transform(movex);  //movex a Vector3D               
lst_p.Add(center_point);           
}

for (int i = 0; i <= 2; i++)           
{               
sph.Transform(movex);               
lst_s.Add(sph);           
}

for (int i = 0; i <= 2; i++)           
{               
brp.Transform(movex);               
lst_b.Add(brp);           
}

//outputs            

DA.SetDataList(0, lst_b);           
DA.SetDataList(1, lst_p);             
DA.SetDataList(2, lst_s);

 

 

I wonder....why does it work with spheres and points but it fails with Breps???

 

any help?

 

Thanks a lot!!!

 

Cheers

Views: 2977

Replies to This Discussion

Hi everyone again, 

 

Finally I could get it!

 

with this chunck of code...

 

Rhino.Geometry.Brep aux_brp = brp.DuplicateBrep();           

for (int i = 0; i <= 2; i++)           

{               

aux_brp = aux_brp.DuplicateBrep();               

aux_brp.Transform(movex);               

lst_b.Add(aux_brp);           

}

 

 

best,

Hi Ramon,

 

you've got an unnecessary duplication in your script. The following should also work:

 

for (int i = 0; i <= 2; i++)

{

  Brep aux_brp= brp.DuplicateBrep();

  aux_brp.Transform(movex);

  lst_b.Add(aux_brp);

}

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David,

 

but it seems it does not work with Brep behind aux_brp....do I need a specific namespace?

 

by the way, why Breps do not work as spheres or points in moving functions?

 

---

Ramon Rubio

rrubio@uniovi.es

University of Oviedo - Spain

"but it seems it does not work with Brep behind aux_brp....do I need a specific namespace?"

 

What is the exact error you get?

 

"by the way, why Breps do not work as spheres or points in moving functions?"

 

What moving functions? How do you feel they differ?

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

Hi David,

 

I got 4 breps in the last position (as shown in the image of the first post), but with the spheres worked fine, and the code is the same for both spheres and breps!!! So I guess the transform functions does not work in the same way with spheres and breps...

 

for (int i = 0; i <= 2; i++)           
{               
sph.Transform(movex);               
lst_s.Add(sph);           
}

for (int i = 0; i <= 2; i++)           
{               
brp.Transform(movex);               
lst_b.Add(brp);           
}

 


Ah, the difference you're seeing is because of reference and value types. A Point3d and a Sphere is a value type in the Rhino SDK, meaning that when you insert one into a list, it gets copied. A Brep is a reference type, which isn't copied. 

 

So when you move a point, then insert it into the list, then move it again, insert it again, you'll populate the list with different points. Not so for the brep. When you call brp.Transform(movex), you will also transform all the breps already in the list, because they all ultimately point to the same location in memory.

 

It's very important to understand the difference between value and reference types (also often called "structs" and "classes" respectively) or you will forever run into seemingly incomprehensible behaviour on the part of your code.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David!!!

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