Grasshopper

algorithmic modeling for Rhino

Here I am with another question. As remove the zeros from the list "D"?
  and another onebecause I do not get the lines?

In that site I can see examples of definitions of GH resolved in Python?

Thank you!

Views: 2453

Attachments:

Replies to This Discussion

Hi Fernando,

Please, upload the rhino file compatible with 4.0

Hola Fernando,

por favor, sube el archivo de rhino compatible con la versión 4.0

Thanks Albert but it is a Python code that only runs on Rhino 5!

Hi Fernando,

there are other ways to approach this altogether, but I think the attached file answers your question.
It is based on this code:

Lineas = [Lineas[i] for i,e in enumerate(D) if e!=0]

I hope this helps,

- Giulio
________________
giulio@mcneel.com

Attachments:

I think you can even remove the enumerate call and just get it down to

Lineas = [e for e in D if e!=0]

Thanks Steve! if I get the call to enumerate get an undesired result

Mh... this is interesting and makes me now wonder: what is the goal of this exercise?
What should each variable contain?

- Giulio
_________________
giulio@mcneel.com

Giulio

The idea is to connect the dots with straight without repeating!

My interests as an exercise as I am new to Python. but I was surprised that I can not solveusing only GH!

With the intension of improving our understanding of Python in the environment of GH, I think it would be a good idea to propose "replace" or rewrite a definition in GH withpython code
Attachments:

And delete the values that repinten "D" is also repeated lines!

Usually what you are trying to obtain is approached in the following way, because of memory and to iterate through the whole list fewer times.

If you one day need to have the same lines twice (in the two directions), you could just construct the same line but with reversed inputs, or modify the loop for j so that it starts at the beginning of the list.import rhinoscriptsyntax as rs

L = [] # construct a new, empty list for L (lines)
D = []

for i in range(len(M) - 1):
    for j in range(i + 1, len(M)):
        if rs.PointCoordinates(M[i]) == rs.PointCoordinates(M[j]):
            continue
        
        line = rs.AddLine(M[i], M[j])    #if so, add the line
        D.append(rs.CurveLength(line))   #also, compute the length
        L.append(line)

I hope this helps,

- Giulio
____________
giulio@mcneel.com

Attachments:

Giulio Excellent I have a question. In quesaos is advisable to place "else" after the "if"

It would be good to create a group of style ( http://www.grasshopper3d.com/group/coffee-and-grasshopper ) amplar to knowledge of Python!

Studying your code I saw the condition that is within the "if" not met not by how they areraised loops, so you can remove this line correct?
 Thanks for your tiermpo!



import rhinoscriptsyntax as rs

Lineas = [] # construct a new, empty list for L (lines)
D = []
for i in range(len(M) - 1):
for j in range(i + 1, len(M)):
#if rs.PointCoordinates(M[i]) == rs.PointCoordinates(M[j]):
# continue

line = rs.AddLine(M[i], M[j]) #if so, add the line
D.append(rs.CurveLength(line)) #also, compute the length
Lineas.append(line)


RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service