Python combine data of branches

@diff-arch,If you have access to Rhino 6, the list_to_tree and tree_to_list functions are builtin, so you don’t have to re-write the function. You can import them via:

import ghpythonlib.treehelpers as th

edit: this function is specifically in regards to tree/list functions. nothing to do with casting data types.

1 Like

@diff-arch Thank you!

@chanley so with this I can export goos, I will try that

Yeah, I know, but I’m still using Rhino 5. Also, this shows a little better how things behind the scenes work. :wink:

1 Like

Hey @ForestOwl,

Yesterday, I forgot to mention that if you need to output the empty branches of curves that don’t have any intersections with the other curves, you simply omit this line of code:

if len(crv_inters) > 0: # curve Regions[i] has intersections with other curves

Furthermore, you need to change the indentation of crvs_inters.append(crv_inters), so that it vertically aligns with for j in range(i+1, len(Regions)): .

38

Try it and you’ll see the difference! You could for instance use the empty branches to evaluate, which curves have intersections and which don’t in the continuation of your GH component script outside of GHPython.

2 Likes

Thank you again :smiley:

I am doing something wrong with this context, do you might know what I am doing wrong?

Instead of getting a part, I get the whole curve.

goose again.gh (18.4 KB)

You forgot to internalise your curves input. :wink:

internalised
goose again.gh (21.1 KB)

Into the rhinocommon GHPython component, you simply input all the curves in a flat list. It does all the comparing by itself. If you input a tree, it runs the script for each of its branches separately, which means in your case, that not all curves get compared to each other.
However, if you input a flat list, as mentioned above it works:

Now, you might notice that an entire input curve is returned as intersection curve (pink), which is weird right!? After taking a closer look, I noticed that this input curve is duplicate…

13

… which means that the script is in fact right. Duplicate curves are intersecting everywhere!
I’ve implemented a turn on and off button for this in the new script, as well as for the output of empty branches.

In your rhinoscriptsyntax script, this happens for the same reason!

goose_again_v2.gh (20.6 KB)

2 Likes

Do you know about a possible loop to difference bits out? I am trying to bit the snips off the original.
Sometime I have two snips per original.

goose again (1)2.gh (29.1 KB)

import rhinoscriptsyntax as rs
r=regcrv
differ=[]
for c in differsregcrvs:
    new=rs.CurveBooleanDifference(r,c)
    r=new
differ = (r)

I don’t get what you want to achieve? What do you mean by “to bit the snips off the original”?

I want to get the blue parts out of the red parts

I tried some things, but I cannot figure it out

You want the curves in blue subtracted from the red ones?

yess, I want to loop it, however the function it can only substract one, not many

rhinocommon is my true love, rhinoscriptsyntax is a mean :dog:
but everyone loves :dog:'s too, so…

however, only rhinoscriptsyntax seem to provide such function,
or did I miss it? does rhiniocommon has a ‘substract all from one’ function?

Hey, @ForestOwl,

Have you managed to come up with a solution?

No I have not yet. I have not find a logic to that. I cannot figure it out.

The following seems logic to me, but it does not work.
Trying other things were, not successful.

import rhinoscriptsyntax as rs
r=regcrv
differ=[]
for c in differsregcrvs:
    new=rs.CurveBooleanDifference(r,c)
    r=new
differ = (r)

hi :deciduous_tree::evergreen_tree::deciduous_tree::owl:,

Using:

import inspect
import rhinoscriptsyntax as rs

print inspect.getsource(rs.CurveBooleanDifference)

I get :

"""Calculates the difference between two closed, planar curves and
    adds the results to the document. Note, curves must be coplanar.
    Parameters:
      curve_id_0 = identifier of the first curve object.
      curve_id_1 = identifier of the second curve object.
    Returns:
      The identifiers of the new objects if successful, None on error.
    """
    curve0 = rhutil.coercecurve(curve_id_0, -1, True)
    curve1 = rhutil.coercecurve(curve_id_1, -1, True)
    out_curves = Rhino.Geometry.Curve.CreateBooleanDifference(curve0, curve1)
    curves = []
    if out_curves:
        for curve in out_curves:
            if curve and curve.IsValid:
                rc = scriptcontext.doc.Objects.AddCurve(curve)
                curve.Dispose()
                if rc==System.Guid.Empty: raise Exception("unable to add curve to document")
                curves.append(rc)
    scriptcontext.doc.Views.Redraw()
    return curves

so it seems you can use Rhino.Geometry.Curve.CreateBooleanDifference(curve0, curve1) to escape from the :dog:
:innocent:

hi mr :poodle: :meat_on_bone:,

(I meant this greeting as funny :slight_smile: too, grey and ham makes Graham)

When I test combination 0, it does not work. With all the other combinations, it does work. I am doing something wrong with test combination 0. Do you might know what I am doing wrong?

Of combination 0, all the curves are on the same height, everything seems to be correct.

goose again (1)2 (1)(3).gh (25.2 KB)

Yes, got it - that’s quite funny. For an owl :wink:
I can’t open your file unfortunately - my grasshopper is broken since I changed computer last week, and I am running Rhino 5 - don’t know if that is a problem. Currently awaiting tech support from the local guru… I need to get my :snake: Python scripts back from my old hard drive too !!! I feel naked without them. :blush:

1 Like

Hello everybody,

I’ve taken another look at the rhinocommon version of the script. It’s become a little complex, but works quite well with @ForestOwl’s example curves.


(blue: differences, pink: intersections, white: non-intersected)

The important thing is to feed it planar, closed polyline curves (or at least curves that are of the polyline type). Degree 1 NurbsCurves, PolylineCurves, and PolyCurves are acceptable.
The script converts the input curves at times to polylines, which are basically just collections of ordered points that represent line segments. I’ve implemented some security measures that raise errors, if this rule is violated. The can be read in the white panel.

Furthermore, the script works with duplicate curves, but it is recommended to use the CullDuplicates option, since feeding it duplicates produces lots of duplicate intersections and differences in return.

And as always, enjoy!

goose_revisited.gh (21.7 KB)

1 Like

Woow, that is a large script
Very thank you!
:smiley:

1 Like