Grasshopper

algorithmic modeling for Rhino

Hello,

I'm creating a parametric surface with a python script in grasshopper (GhPython), which divides three curves into points, and then creates arcs to join the three curves. It uses the Get.Object command to select the curves, but I'm not able to control the resultant form afterwards in Grasshopper to create Pframes or array a geometry on the surface.

My script:

import rhinoscriptsyntax as rs

import Rhino

import scriptcontext as sc

sc.doc = Rhino.RhinoDoc.ActiveDoc

class TanLines:

def __init__(self, _curve, _numOfDivs):

self.curve = _curve;

self.numOfDivs = _numOfDivs

def tanPoints(self,strength):

#print("check")

doms = rs.CurveDomain(self.curve)

minDom = doms[0]

maxDom = doms[1]

ptList = []

tanPtList = []

for i in range (0, self.numOfDivs + 1):

param = (maxDom-minDom)/self.numOfDivs * i

tan = rs.CurveTangent(self.curve, param)

tan = rs.VectorScale(tan, strength)

pt = rs.EvaluateCurve(self.curve, param)

rs.AddPoint(tan)

rs.AddPoint(pt)

tanPt = rs.VectorAdd(tan, pt)

rs.AddLine(pt, tanPt)

ptList.append(pt)

tanPtList.append(tanPt)

return [ptList, tanPtList]

curve01 = rs.GetObject("pick curve 1", 4)

curve02 = rs.GetObject("pick curve 2", 4)

curve03 = rs.GetObject("pick curve 3", 4)

 

obj01 = TanLines(curve01,50)

data01 = obj01.tanPoints(-0.1)

obj02 = TanLines(curve02,50)

data02 = obj02.tanPoints(-0.1)

obj03 = TanLines(curve03,50)

data03 = obj03.tanPoints(-0.1)

 

ptList01 = data01[0] #point list of first line

ptList02 = data01[1] #tan points of first line

ptList03 = data02[0]

ptList04 = data02[1]

ptList05 = data03[0]

ptList06 = data03[1]

 

count = 0

crvList = [] #establish list of curves

 

for i in ptList01:

pointsForCurve = [ ptList01[count], ptList02[count], ptList03[count], ptList04[count], ptList05[count], ptList06[count] ]

crv=rs.AddArc3Pt(ptList01[count], ptList06[count], ptList04[count])

crvList.append(crv)

count += 1

Surface = rs.AddLoftSrf (crvList)

sc.doc = ghdoc

A = Surface

B = crvList

C = [curve01, curve03]

-

Any help would be much appreciated. Thank you.

Views: 2564

Attachments:

Replies to This Discussion

Hi Francis,

The reason why you can't control resultant is because your geometry gets added to the Rhino document, while you are trying to edit/create the grasshopper one.

While you can always add your geometry from Rhino to grasshopper document, I would advice you not to use the rs.GetObject function nor switch the documents at all.
You can simply assign each of these three curves (curve01,curve02,curve03) directly, by using grasshoppers' "Curve" parameter.
Check the attached files.

Attachments:

Hi Djordje,

It worked like a charm! Thank you for your help.

Cheers

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