How to remove a part of a curve with Python?

grasshopper
python
unhandled

(Edward) #1

How to remove a part of the curve or the whole curve according to these rules?

if distance of points of green line <= 2:
    if lenght from start to point >= 2:
        cut curve from start to first point that has distance of >=2
    else:
        remove curve 

python remove curve part 01.gh (9.7 KB)


#2

You’re probably looking for Curve.Trim:

http://developer.rhino3d.com/5/api/RhinoCommonWin/html/M_Rhino_Geometry_Curve_Trim_2.htm


(Edward) #3

Thank you Anders.

Do you also know how to Python this?

I can do some things by myself within this context, however, I am searching for an example script that bridge something like this. With that, I think I am able to work around a lot more similar cases.


(Tim Stark) #4

In the sdk he linked you is the python part:
Curve Trim(
double t0,
double t1
)


#5

There you go:

TrimCurve_GHPy.gh (4.5 KB)


(Edward) #6

Thank you both.

Do you also know how to use a component inside Python?


(Tim Stark) #7

No sorry, but looking back at this thread, I assume you don‘t know any basics of python. May try to learn them first before creating a script, where you have to ask for every line. Don‘t get me wrong, it’s not meant to be offensive or something like this. Surely someone will help you. But I don‘t think this is effective if you don‘t understand anything what’s written there.


(Edward) #8

Well, actually, I learned something about Python. But, I am not familiar with any Python wherein somebody imports a component and knows how to fill in the rest (not a thing of Rhino, but a component of Grasshopper).

I cannot find an example.


(Tim Stark) #9

Same with the problem at this thread. That you can‘t import a line from the sdk into your phyton component on your own, I would recommend learning more than „something“. But as I said this is not meant to be offensive, just a recommendation :slight_smile:

BTW: why do you want to import shortest walk into phyton? Can‘t you just use the component before and use its output?


(Edward) #10

Yes I am familiar with that and understand that.
However, there is nothing I can find to learn to import such thing. It should be possible, I want to find a clear example that demonstrate it from which I can learn from.

About your BTW: Well, I can use code from the internet, but it would be more easy to shortcut all those scroll of codes by implementing and adjusting some way the components.
But, if not possible, is it possible to open the component and dig into it to rewire things or better, make an adjustment on them to make them comply with what I want?

Other BTW: I want to make an aggregation. I am now done with looping things and want to Python it. I want to include parts of components or learn how existing components work.


(Tim Stark) #11

There are c# to phyton Converter on google.


How to import a grasshopper component into Python?
(qythium) #12

That looks like pretty complex code (the logic is spread out over several files) , and I wouldn’t trust an auto C# to Python transpiler to make much sense of it.

@Edward are you not able to simply use the outputs from the Python component as inputs to the Gh ShortestWalk component? Any particular reason for having to integrate it into the script itself?


(Edward) #13

Thank you Qythium, Stark and Deleuran,

Now I know these things more clearly, I have to rethink my strategy for my aggregation. Thanks for your help, without your I would probably be stuck for a week.

This all really explained a lot to me. Finally, I understand the whole picture a lot better.