Grasshopper

algorithmic modeling for Rhino

hey everyone!

I just started scripting python in gh and allready have a very basic problem.

i created a grid of points and an "attractor" point.

now i want to create vectors form each of the "gridpoints" to my attractor...
i could manage to get the lengths of these vectors in a list (to process them in a later state of the script) but somehow my vectors aren't displayed...maybe someone knows what the problem could be?
thanks in advance!

import rhinoscriptsyntax as rs
import Rhino as rc

gridpoints = [] #list with all the gridpoints
lengths = [] #list with vector lengths

#attractor
ptattractor = rs.AddSphere(attractor,radius)

#setting up the pointgrid
for i in range(0,Xwidth):
for j in range(0,Ywidth):
point = rc.Geometry.Point3d(i,j,0)
rs.AddSphere([i,j,0],radius)
gridpoints.append(point)

#setting up vectors from gridpoints to attractor
for pt in gridpoints:
vector = rs.VectorCreate(attractor,pt)
length = rs.VectorLength(vector)
lengths.append(length)

#test to see how many vectors are in list
print len(lengths)
for i in lengths:
print i

a=ghdoc.Objects.Geometries

Views: 634

Attachments:

Replies to This Discussion

Hi maxk,

You can add all your vectors to a separate list and then output them from ghpython component. Check the attached file.

Also you can use the rhinoscriptsyntax function rs.AddPoint instead of RhinoCommon method Rhino.Geometry.Point3d, in case you intend to use rhinoscriptsyntax functions only.

Attachments:

Vectors are not typically drawn as previews. After all it's not known where to draw them, as the vectors themselves only store direction and magnitude data, not position.

You can output line segments if you want to see something on the screen though.

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