Grasshopper

algorithmic modeling for Rhino

Dear all,

I am following the example from python 101.

something is goint wrong in some example below and nothing happen when I excute 'start debugging'...dose anyone knows whats the problem?

example on page 39:

def AddVector(vecdir, base_point=[0,0,0]):
    tip_point = rs.PointAdd(base_point, vecdir)
    line = rs.AddLine(base_point, tip_point)
    if line: return rs.CurveArrows(line, 2)

 

example on page 40:

import rhinoscriptsyntax as rs

# This script will compute a bunch of cross-product vector based on a pointcloud

def vectorfield():

    cloud_id = rs.GetObject("Input pointcloud", 2, True, True)

    if cloud_id is None: return

 

    listpoints = rs.PointCloudPoints(cloud_id)

    base_point = rs.GetPoint("Vector field base point")

    if base_point is None: return

        for point in listpoints:

           vecbase = rs.VectorCreate(point, base_point)

           vecdir = rs.VectorCrossProduct(vecbase, (0,0,1))

           if vecdir:

               vecdir = rs.VectorUnitize(vecdir)

               vecdir = rs.VectorScale(vecdir, 2.0)

               AddVector(vecdir, point)            

Views: 1484

Replies to This Discussion

Just call the vectorfield() function in the end.
Also there is an extra indentation at "for point in listpoints:". Delete it. Like so:

import rhinoscriptsyntax as rs

def AddVector(vecdir, base_point=[0,0,0]):
    tip_point = rs.PointAdd(base_point, vecdir)
    line = rs.AddLine(base_point, tip_point)
    if line: return rs.CurveArrows(line, 2)



# This script will compute a bunch of cross-product vector based on a pointcloud

def vectorfield():
    cloud_id = rs.GetObject("Input pointcloud", 2, True, True)
    if cloud_id is None: return

    listpoints = rs.PointCloudPoints(cloud_id)
    base_point = rs.GetPoint("Vector field base point")
    if base_point is None: return
    for point in listpoints:
           vecbase = rs.VectorCreate(point, base_point)
           vecdir = rs.VectorCrossProduct(vecbase, (0,0,1))
           if vecdir:
               vecdir = rs.VectorUnitize(vecdir)
               vecdir = rs.VectorScale(vecdir, 2.0)
               AddVector(vecdir, point)    
               

# call the second function:        
       
vectorfield()

alright, thx!

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