Grasshopper

algorithmic modeling for Rhino

I have create several layers of points like this. However, when I try to output them from grasshopper they appeared to be several list of course. Is there anyway to output them as points while keeping them separate as layers?

Views: 1044

Attachments:

Replies to This Discussion

A quick and dirty way to handle this is to simply add a second python script with a single line script: A = x

The python script component is smart, and if you set A = to a single list, it will automatically give you back all the items of the list. However, if you give it a list of lists (as you are in this example) it doesn't know to extract the items in the internal lists. The script I suggest simply reinterprets each list as a single item, and relies on the component data processing to split out the items list by list. This also has the advantage (over 筑梦NARUTO's solution) of keeping each list in its own grasshopper data tree branch. 

If you'd rather avoid the clunkiness of a second script component, you'll have to compose a datatree yourself. That will look something like this:

 

import math as m

import Rhino

from Grasshopper.Kernel.Data import GH_Path

from Grasshopper import DataTree

pi = m.pi

angle =0

pts = DataTree[Rhino.Geometry.Point3d]()

c=0

for i in rs.frange(0,5,0.5):

    angle +=(pi/30)

    layer = []

    for j in rs.frange(0,2*pi,pi/15):

        x= 5*m.sin(j+angle)

        y= 5*m.cos(j+angle)

        layer.append( Rhino.Geometry.Point3d(x,y,i))

    pts.AddRange(layer,GH_Path(c))

    c = c+1

a = pts

Thank you Andrew, your advice is very, very helpful to me. I also tried to say pts = DataTree[object]() and llayer.append( rs.AddPoint(x,y,i)) and it still works.

May I ask why sometimes we are using Rhino.Geometry instead of just using Rhinoscriptsyntax??

I prefer RhinoCommon to rhinoscriptsyntax - just feels more direct. Really more of a personal taste thing. In the example above though I was just sidestepping the fact that rs.AddPoint returns a Guid instead of a point - but I see your approach with DataTree[object] works just fine.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service