How to Merge or Join Closed Curve into one Onject in Pythonscript?

Hi All,
Happy new year!
I am dealing with a problem to merge multi- closed curves(green curves) into one object.
Then I can use it in my following iteration.
Wondering how can I Join them into an object, instead of a list of curves.

What type of object would you like to join them into? A surface? mesh? polyline?
Happy New Year,

1 Like

I think it might work with polyline ,but don’t know how to do it.
Thanks for your reply. :slight_smile:

To make a polyline you need all the lines to be continuous with no jumps. If you have the points in order then you can use this:

Alternatively you could group the objects:

1 Like

Thanks!!! I’ll give it a try.
I have another question about when I was using the function “AddGroup” in rhinoscripts in grasshopper UI. It said something like “AddGroup” did not be allowed to use in ghdoc. Just to make sure why this happened.
Thanks again!!!

Ahh I don’t know I’m afraid - I do my python programming in Rhino (v5), not Grasshopper…

1 Like

Thanks! Although I just started my study in this field, but I think using scripts in grasshopper has some benefits, like I finished my work by using loop in gh and python scripts haha…

1 Like

That’s great - keep up the good work! It’s really nice that Python skills are so generally applicable so you can use the same techniques for automation and calculation generally in your work, not just in Rhino.
I want to try out the python 3 components in GH so I can get access to numpy and pandas as I am starting to use them for general file handling and data analysis.

As far as I know, you may not have much success getting numpy to work in ghpython components.

1 Like

hmm :cry:
I was thinking of this module but havent tried it out yet

I would guess that you are running into a scriptcontext issue. When using rhinoscriptsyntax from within a ghpython component, you need to set the “focus”. (search forum for scriptscontext, ghdoc, etc…lots of info).

In the ghpython component in Rhino 6, (not sure if this error said the same thing in Rhino 5), the error message gives you a pretty clear hint as to what is going wrong, when you call a rhinoscriptsyntax function, and haven’t set the “focus” correctly.

for example, the following code

import rhinoscriptsyntax as rs

rs.AddGroup("some group name")

will yield the following error:

Runtime error (NotSupportedException): This type of object is not supported in Grasshopper, 
so this Python script cannot create it. 
You might want to use 'scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc' 
to use the Rhino doc, instead?
 If you do, remember to restore it: 'scriptcontext.doc = ghdoc'.

Using the information from the above error, The correct setup would be to use this:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

sc.doc = Rhino.RhinoDoc.ActiveDoc #change focus to active rhino doc

rs.AddGroup("some group name") #do something in the rhino doc
print "group added successfully"

sc.doc = ghdoc #change focus back to the grasshopper document.

Lastly, (and this is perhaps a bit beyond the scope of your question), this is only required when using rhinoscriptsyntax. If you were to use Rhinocommon, you would not need to use script context.

for example, if you added some groups with the sample code below, (which does not take into account if the name already exists in the group table), you would only need to import Rhino, and not have to use scriptcontext:

import Rhino

Rhino.RhinoDoc.ActiveDoc.Groups.Add("some group name")
Rhino.RhinoDoc.ActiveDoc.Groups.Add("some group name01")
Rhino.RhinoDoc.ActiveDoc.Groups.Add("some group name02")
for gr in Rhino.RhinoDoc.ActiveDoc.Groups:
    if gr.Name != None:
        print gr.Name

note, all this does is add a group to the active rhino document’s group table, it didn’t add any geometry to the group.

1 Like

I don’t have any experience with that plugin. Might want to ask around and see if you get any feedback from other forum members.

Hey cool work!

One question though, why are using anemone and python at the same time? Can’t you include the looping nature inside the python code?

1 Like

Thank you. Good question!
Because in my python code, I made a loop that only allows one polyline object to be the input and expect the output must be one polyline as well. It worked well when my input is a single curve(you can see them in my first picture ,those red lines), but I certainly want to make a much complex version which obviously the original python loop can not deal with.
And the key point is that cause the complex one is not a single polyline, so it failed when I want to join or group them to be the next iteration input.
That’s why in the end I choose to use anemone because I can use ‘merge’ in gh and make it to be the input of the next step.

1 Like