Grasshopper

algorithmic modeling for Rhino

Hi all,

I have been using Grasshopper for a while, but have just started trying out Python for Grasshopper. I am wondering what the rhinosyntax.coerce methods do exactly? I thought supposedly they are to get the "geometry," but it seems like I am not really understanding them properly.

Any insight, advice, and help would be much appreciated!

For example, below is a part of a script I am working on (please find attached the GH file as well).

When I did rs.coercecurve(edge) to reparameterize the curves, the method works, but when I did rs.coercesurface(srf_new), it is returning a different surface then the one from the line before, rs.AddPlanarSrf(edge_new):

------------------------------------------------------------

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg


srf_edge = rs.DuplicateEdgeCurves(srf, False)

#vector to move with
pt_0 = rs.AddPoint(0,0,0)
pt_1 = rs.AddPoint(0,0,z)
translation = rs.VectorCreate(pt_1, pt_0)

#corners of new planar srf
endPt = []
for edge in srf_edge:
    rs.MoveObjects(edge, translation)

    #reparameterize edge
    edge = rs.coercecurve(edge)
    edge.Domain = rc.Geometry.Interval(0,1)

    for p in range(2):
        endPt.append(rs.EvaluateCurve(edge, p))

#edges of new planar srf
edge_new = []
for x in range(len(endPt)-1):
    if abs(rs.Distance(endPt[x], endPt[x+1])) > 0:
        line = rs.AddLine(endPt[x], endPt[x+1])
        edge_new.append(line)

srf_new = rs.AddPlanarSrf(edge_new)

#turn list into surface
srf_new = rs.coercesurface(srf_new)

#the output surface seems to be a smaller subdivision of the planar surface previously created !

Views: 3098

Attachments:

Replies to This Discussion

I gave it a few more tries and realized when I do:

rs.coercesurface(srf_new)

print type(srf_new)

>>type 'BrepFace'

(and as mentioned above, returns the wrong "object," as this "face" is smaller than the actual surface referenced.

however, when I do:

rs.coercebrep(srf_new)

print type(srf_new)

>>type 'Brep'

I get the correct geometry, ie. the entire surface.

Why is that?

Thanks again,

Tim

Hi Timothy,

sorry, I think you are mixing two concepts. One is the 'coerceX' family. This is only used to lookup an object from the document, and get it as a scriptable RhinoCommon object. I think you understand that all right.

The problem you are facing, i.e., the surface is untrimmed, is just a reflection of what Grasshopper calls 'surface' (that is, also a trimmed brep with a single faces) and RhinoCommon calls, well, again, surface: the latter cannot be trimmed, as it does not have the required data structure.

Does it help?

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

BTW: You can see what each 'coerceX' function does, if you step into it with the debugger.

Hi Giulio,

Thanks for your explanation, and sorry for the late response - I forgot to write back after moving onto different parts of the project.

And yes, I realized that was not really a misunderstanding in python, but between grasshopper and rhino in general.

I was just in general not too familiar with the syntax, so thought I was doing something wrong in the python script.

Thanks again,

Tim

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service