There is a problem with the data structure of GhPython: when my input is a list, the tree data on the output is merged; When the input end is in a tree shape, this problem will not occur (ps: the following string of data is the correct data)
def temp(self, tuple):
curve, points = tuple
curves = self.split_curve(curve, points)
return curves
def split_curve(self, curve, points):
t = []
for p in points:
t.append(curve.ClosestPoint(p)[1])
return curve.Split(t)
def Find_Intersections(self, curves):
intersection_points_list = []
for curve in curves:
pts = []
for other_curve in curves:
if curve == other_curve:
continue
curve_intersections = rg.Intersect.Intersection.CurveCurve(curve, other_curve, self.tol, self.tol)
for i in curve_intersections:
if i.IsPoint:
pts.append(i.PointA)
intersection_points_list.append(pts)
return intersection_points_list
Hi Niko. I’m not sure this will solve your problem (I’m happy to be corrected, but I find mangling DataTrees and re-pathing them is normal in Grasshopper), but I was able to output DataTrees (from treehelpers) for my purposes, by setting the output param to: Grasshopper.Kernel.Parameters.Param_ScriptVariable . I just use that type by default, and try to let the GhPython ‘auto-magic’ handle as much as possible.
Adding params in code in general, I found to be quite intricate (i.e. brittle, and it took a lot of trial and error to figure out). Even if you put in an ‘idempotent’ condition into RunScript, to only add Params once on the first call (when the component is placed or the first time the worksheet is loaded), you can still easily end up creating weird bugs from a component’s previous state.
I still add Params that way, but I clear all the other Params first (so I alwauys start a component from a known state), and treat it more as ‘component builder’ / ‘Devops’ code, and use it to build other GhPython components from separate special builder or config GhPython components. I can still let the user add their own Params via the ZUI, and translate them into ‘kwargs’, parsing *args in RunScript, and matching them up to their names in self.Params.Input.
If adding Params is treated as normal component code, so the component can add Params to itself, no end of tricky problems could be created, not least of which infinite loops (as updating the Params, causes RunScript to be called again).
Thank you for your reply, but do you have any code snippets on your end? I find it difficult to understand your literal meaning, and I would like to combine it with the code to try to understand the techniques you told me
I can’t edit those jpegs / screen shots of code you posted. It’s easier to help you in future if you use the </> preformatted text block for code, or just put it inside triple back ticks.
So just change:
Grasshopper.Kernel.Parameters.Param_GenericObject
to: Grasshopper.Kernel.Parameters.Param_ScriptVariable