Grasshopper

algorithmic modeling for Rhino

I am trying to create a script which uses Brep.CreatePatch to create a surface from a Polyline. When ever I run it, the script completes without any errors but the surface is not created. Can some please help me fix this?

import Rhino as rc
import rhinoscriptsyntax as rs

lines = []

PLine = rs.GetObject("Select Polyline", 4)
cList = rs.ExplodeCurves(PLine)
CPts = rs.CurvePoints(PLine)


for i in range(len(CPts)):
line = rc.Geometry.LineCurve(CPts[i-1],CPts[i])
lines.append(line)

a = rc.Geometry.Brep.CreatePatch(lines,10,10,0.005)

Views: 1201

Replies to This Discussion

Hi Nicolo,

Are you trying to do this in Rhino Python Editor or ghPython component. Got a little bit confused as you are inputting your polylines as if you were using Rhino Python Editor, but you have assigning the return value of CreatePatch method to "a" as if you were working in ghPython. I will assume you want to do it in Rhino Python Editor.

Do you want to simply patch a planar closed, polyline?

If that is so, then you could just use CreatePlanarBreps method instead of CreatePatch. Here is an example for both:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

polyline_id = rs.GetObject("pick your closed polyline")
if rs.IsCurveClosed(polyline_id):
    plnSrf = Rhino.Geometry.Brep.CreatePlanarBreps(rs.coercecurve(polyline_id))[0]
    plnSrf_id = sc.doc.Objects.AddBrep(plnSrf)
    patch = Rhino.Geometry.Brep.CreatePatch([rs.coercecurve(polyline_id)], 1, 1, 0.01)
    patch_id = sc.doc.Objects.AddBrep(patch)

rs.ObjectColor(plnSrf_id, [255,195,14])    # plnSrf is orange
rs.ObjectColor(patch_id, [0,120,221])    # patch is blue
rs.Redraw()

Hi  djordje,

Thanks a lot for your reply! That is exactly what I was looking for! I haven't had much practice with RhinoCommon and I'm still figuring out how to use it within the Rhino Python Editor. 

I was using  Rhino Python Editor but I usually transfer some of my scripts to gh when they are done. That is why I was using the "a". 

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