Grasshopper

algorithmic modeling for Rhino

I'm having a problem with pipes created with GhPython.

Here is the code of the problem.

pipes = []

pipe = rs.AddPipe(line, 0, 0.5)
pipes.append(pipe)

I wanted to output this list with pipes to grasshopper.

But the Srf Component says like this. 

1. Data conversion failed from Goo to Surface

And Panel Component says like this.

IronPython.Runtime.List...

Normally, I can output lists with points and curves just by using rs.Add~~~

I mean the code below

curves = []

curves.addCurve(curve)

I don't know why Pipe cannot do this though others can do.

Can somebody help me with this problem??

Views: 3573

Replies to This Discussion

Pipes are probably Breps. If they have more than one face, they can't be converted to a surface. Try using Brep instead of Surface.

--

David Rutten

david@mcneel.com

Look like this issue emerged before.
It seems some RhinoCommon methods (in this case Rhino.Geometry.Brep.CreatePipe(), which rs.AddPipe() function calls) return a list of lists, which grasshopper does not like. That's the point of: IronPython.Runtime.List.

So you either need to flatten the output (not sure I get this, but looks like it works):

flatten = lambda *n: (e for a in n
for e in (flatten(*a) if isinstance(a, (tuple, list)) else (a,)))
pipes2 = list(flatten(pipes))

or convert it into data tree:

import Rhino.Geometry as rg
from clr import AddReference as addr
addr("Grasshopper")

from System import Object
from Grasshopper import DataTree
from Grasshopper.Kernel.Data import GH_Path


def raggedListToDataTree(raggedList):
    rl = raggedList
    result = DataTree[object]()
    for i in range(len(rl)):
        temp = []
        for j in range(len(rl[i])):
            temp.append(rl[i][j])
        #print i, " - ",temp
        path = GH_Path(i)
        result.AddRange(temp, path)
    return result

pipes = raggedListToDataTree(pipes)

I am not familiar with Grasshopper's data trees so David will correct me if something was not right.

Thank you David and djordje!!

I could output the results with the code including lambda.

But I don't know why it works, because it includes left-parenthesis in the 1st line..

 

flatten = lambda *n: (e for a in n

What's that?

Anyway, thanks a lot!!!

Not sure, really. Lambda is a function, but other than that it looks a bit advanced for me.

Maybe somebody else could explain you how it works.
You can use any other solution from upper mentioned page, for flattening the list.

Or just google one.

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