Grasshopper

algorithmic modeling for Rhino

Hi,

First of all let me just explain that I'm quite new to Python, so sorry if my question is dumb ;)

So here is what I'm trying to do:

I start with a list of four sided panels. I want to pick two longest edges of each panel and populate it with points in 0.2 and 0.8 of the length. 

To do so, I run a for loop, to get each surface per iteration. Than I'm using CurveLength to get the length of four sides - and here is the first problem - I am not able to measure the whole list of four curves. I can measure them separately but I guess it is not the smartest way (what if I have 1000 curves to measure?). How do I run it for multiple objects?

Than I get to another problem - sorting. How do I use the the CurveLength as a sorting key?

I know that I could do it easily using grasshopper components, but I want to learn Python. Any help will be appreciated! 

Views: 2776

Replies to This Discussion

Marc,

Can you upload a script you're using. Else it's very difficult to work out where it is breaking.

Here is a link to an article Steve Baer aurthored that looks specifically at the 'sorted' function built in to python. It might help.

https://stevebaer.wordpress.com/2011/10/18/python-goodies-the-sorte...

Hi,

Thank you Mat,

Sorry for a late response. I still haven't figured out the way to make it work. Here is the tiny bit of script that i have so far : 

import rhinoscriptsyntax as rs
for x in obj:
    Edges = rs.DuplicateEdgeCurves(x)
        for i in Edges:
            CrvLen= rs.CurveLength(i)
print CrvLen

The thing is that I don't know how to get the list of lengths of each set of curves. I can get only one curve a time. 

Marc,

It's much easier if you attach your grasshopper definition as well as then people can see how your connecting your components together as well as what your code is meant to be doing.

To get a list of objects you first need to tell the python component that is what you're after (right click on the input and select list).

You will also need to set up a list to print your lengths to otherwise it will overwrite the last length it calculated. See below:

import rhinoscriptsyntax as rs

#Setup output lists.
sorted_curves = [] #list of curves that are sorted by length
curve_lengths = [] #lengths of curves in same order as output 'sorted_curves'

#Simple function to get the curve length
def curvelength(curve):
length = rs.CurveLength(curve)
return length

#Sort curves into list.
sorted_curves = sorted(curves, key=curvekey)
for crv in sorted_curves:
curve_lengths.append(rs.CurveLength(crv))

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service