GHPython - How to declare command on multiple objects? &&& BTW what are the right terms?


here is the code I’m trying to get to work:

#import Rhino as rc
import Rhino
import rhinoscriptsyntax as rs
#import scriptcontext as sc
import scriptcontext
#sc.doc = Rhino.RhinoDoc.ActiveDoc
import array as arr
import Rhino.Geometry as rg

BlendBreps = [Srf_a, Srf_b]
print BlendBreps
print type(BlendBreps)

print Srf_a.Faces[0]
edgeA = Srf_a.Edges[Side_a]
print Srf_a.Edges[Side_a]
print edgeA

dom_A = [ edgeA.Domain.T0, edgeA.Domain.T1 ]
print dom_A
print rev_a
print Gx_a

print Srf_b.Faces[0]
edgeB = Srf_b.Edges[Side_b]
print Srf_b.Edges[Side_b]
print edgeB

dom_B = [ edgeB.Domain.T0, edgeB.Domain.T1 ]
print dom_B
print rev_b
print Gx_b

BlendSrf = BlendBreps.CreateBlendSurface ( Srf_a.Faces[0], Srf_a.Edges[Side_A], dom_A, rev_a, Gx_a, Srf_b.Faces[0], Srf_b.Edges[Side_b], dom_B, rev_b, Gx_b )

My questions are:

  1. The command (CreateBlendSurface) doesn’t work on lists (BlendBreps). My understanding of the syntax is:
    objects (to do something to).command
    Since I have 2 objects here, how can I handle this?

  2. I’m always unsure, if I name things right. (e.g. “objects (to do something to).command”)
    Can anyone recommend a place where this is explained?

The RhinoCommon method, CreateBlendSurface, is documented here:

If you are trying to make this work in a GHPython component, you could do something like this, (BUT…this is an example, you will need to implement some method of deciding which two edges to use, in the example below they are hard coded, but depending on input geometry, will not always be the same…maybe just add inputs to your component to let the user set the appropriate edge?)

import Rhino
# Srf_a and Srf_b inputs set to item access with type hint "Brep".

# set variable names as listed in RhinoCommon
face0 = Srf_a.Faces[0]
edge0 = Srf_a.Edges[2] # you will need to determine a better way to find the 2 edges you want to blend.
dom0 = edge0.Domain

face1 = Srf_b.Faces[0]
edge1 = Srf_b.Edges[2] # you will need to determine a better way to find the 2 edges you want to blend.
dom1 = edge1.Domain

# find a way to set the blend continuity variable
if BC == 0:
    BlCont = Rhino.Geometry.BlendContinuity.Position
elif BC == 1:
    BlCont = Rhino.Geometry.BlendContinuity.Tangency
    BlCont = Rhino.Geometry.BlendContinuity.Curvature

# feed rhinocommon method your clearly named variables
# BlCont is the blend continuity, could be set different for each surface edge.  Here the same value is used
BlendSrf = Rhino.Geometry.Brep.CreateBlendSurface(face0, edge0, dom0, flipA, BlCont, face1, edge1, dom1, flipB, BlCont) (22.7 KB)

As far as your second question, I think one of the best ways for you to learn this is would be to start referencing the RhinoCommon Documentation, and understanding the difference between:

Generally, when calling a Rhinocommon method, if you aren’t sure what to name a variable…just use what is listed in the documentation. Example: documentation listed above, for the CreateBlendSurface method, shows face0, edge0, domain0, etc…

Also, giving this a read:

1 Like

Thx Chris Hanley,

this is a hint I was looking for:

…understanding the difference between:

Can you tell me, where you got this:

dom0 = edge0.Domain

I dug through

it says:

Type: Rhino.Geometry.Interval
The domain of edge0 to use.

Geometry Interval:

Interval(Double, Double)
T0 Gets or sets the lower bound of the Interval.
T1 Gets or sets the upper bound of the Interval.

I imagined an edge domain as parametric.
So, my thought was to declare the whole egde (from 0 to 1) as:

dom_A = [ edgeA.Domain.T0, edgeA.Domain.T1 ]
…wich is obviously wrong.

edge0 is a curve. A curve has a Domain property.
(In RhinoCommon, objects can inherit properties from their parent classes. The Brep Edge Class inherits properties from it’s parent class Rhino.Geometry.Curve.)

There are a few things you can do when writing in the ghpython script editor to help you find things.
1 - Use dir() to see what’s available from an object. example: print dir(edge0)
2 - Know what object type you are using. In this case, edge0 is a Rhino.Geometry.BrepEdge. The autocomplete will show you what is available if you type out Rhino.Geometry.BrepEdge, but, even though you declared edge0 as BrepEdge, if you type edge0, it will not autocomplete. So, while not terribly efficient, as you are working, you can type out the full path to the object type and let the autocomplete show you what is available. Then comment it out/delete it when you’re done.
3 - Don’t rely on autocomplete. Use things like dir(), GetType() to see what you are working with.
4 - Search the RhinoCommon API.

1 Like

Thx again. Great help!