[Python] Extrude Polysurface extrudes only one sub-surface RhinoScriptSyntax

Is this an issue?
How can I apply the extrude to all sub-surfaces in the polysurface without exploading?

import Rhino.Geometry as rg
a = []
for face in x.Faces:
    normal = face.NormalAt(0,0)
    centroid = rg.AreaMassProperties.Compute(face).Centroid
    profile = rg.Line(centroid, centroid+normal*y).ToNurbsCurve()
    a.append(face.CreateExtrusion(profile, False))

IVELIN PEYCHEV.gh (13.5 KB)

1 Like

@Mahdiyar, do you read minds :rofl:

I was about to ask (create a new thread) about how can I do an extrude by a vector instead a line.

You probably can’t, since the CreateExtrusion method, needs a path curve to extrude along, called “profile” in @Mahdiyar’s code.

public Brep CreateExtrusion(
	Curve pathCurve,
	bool cap
)

However, the profile line is created with a vector. This vector is the normal scaled by y. It is then added to the centroid, to produce the path curve end point at the peak of the vector.

You could refractor the code like this:

import Rhino.Geometry as rg

a = []
for face in x.Faces:
    normal = face.NormalAt(0,0)
    centroid = rg.AreaMassProperties.Compute(face).Centroid # path curve start point
    vec = normal * y # scaled normal vector
    end_pt = vec + centroid # path curve end point
    path_crv = rg.Line(centroid, end_pt).ToNurbsCurve()
    a.append(face.CreateExtrusion(path_crv, False)) # True for caps

You could also convert the face to a surface - face.ToNurbsSurface() - then use Surface.CreateExtrusion() which takes a vector. However, there is no option to cap in this case. You could also get the edges of the surface (if no holes) and use Extrusion.Create() which does have the Cap option.

in case I prefer this approach, how can I get this face in RhinoScriptSyntax to extrude it with rs.ExtrudeSurface?

Don’t bother, since ExtrudeSurface from rhinoscriptsyntax does exactly the same thing as @Mahdiyar proposed about, as you can see below (or on GitHub):

def ExtrudeSurface(surface, curve, cap=True):
   """Create surface by extruding along a path curve
   Parameters:
     surface (guid): identifier of the surface to extrude
     curve (guid): identifier of the path curve
     cap (bool, optional): extrusion is capped at both ends
   Returns:
     guid: identifier of new surface on success
   Example:
     import rhinoscriptsyntax as rs
     surface = rs.AddSrfPt([(0,0,0), (5,0,0), (5,5,0), (0,5,0)])
     curve = rs.AddLine((5,0,0), (10,0,10))
     rs.ExtrudeSurface(surface, curve)
   See Also:
     ExtrudeCurve
     ExtrudeCurvePoint
     ExtrudeCurveStraight
   """
   brep = rhutil.coercebrep(surface, True)
   curve = rhutil.coercecurve(curve, -1, True)
   newbrep = brep.Faces[0].CreateExtrusion(curve, cap)
   if newbrep:
       rc = scriptcontext.doc.Objects.AddBrep(newbrep)
       scriptcontext.doc.Views.Redraw()
       return rc