Help! This pycode does not work

Hi,

This pycode does not work,can you help me?

import rhinoscriptsyntax as rs

srf = rs.GetObject("select Extrude surface",rs.filter.surface)
if srf:
    cmd = "_ExtrudeSrf _Pause S=_Yes "
    rc = rs.command(cmd + chr(34) + srf + chr(34), True)
    rs.HideObject(srf)
else:
    print "not select surface"

It does not work,please help me.

This is one way:

import rhinoscriptsyntax as rs

srf = rs.GetObject("Select surface to extrude",rs.filter.surface,select=True)
if srf:
    rc = rs.Command("_ExtrudeSrf _Solid=_Yes ", True)
    rs.HideObject(srf)
else:
    print "No surface selected"

Preselect the surface before calling rs.Command()
Pay attention to both indentation as well as capitalization with Python (rs.Command(), not rs.command(), etc.)

HTH, --Mitch

Hi Helvetosaur,

It must preselect the surface, can you make to select the surface to extrude at once? Do not select it twice.

Thank you.

srf = rs.GetObject("Select surface to extrude",rs.filter.surface,preselect=True,select=True)

Thank you. It works well.

Hi Helvetosaur,

If I select the surface of the joined solid, could it done?
Now I can only select the single surface,no the surface of joined solid object selected.

You want the extrusion to be selected at the end, is that it? Otherwise, I don’t quite get your question. --Mitch

thanks

Something like the following will allow you to select either a single surface or a polysurface and extrude it, deleting the original.

import rhinoscriptsyntax as rs

msg="Select a surface or polysurface face"
obj_ref=rs.GetObject(msg,8,preselect=True,select=True,subobjects=True)
rs.Command("_ExtrudeSrf _Solid=_Yes _DeleteInput=_Yes", True)

HTH, --Mitch

I am very sincerely grateful to you for help me.

If I want to select a curve and a surface, How can I do?

Thanks,
Have a good day!

This gets more sophisticated, as first, there are two separate Rhino commands for extruding curves and surfaces, plus in order to extrude a curve solid, it has to be closed and planar. So you need to separate the two cases curves/surfaces and also filter for closed planar curves.

Two basic ways to do this, one is to accept all curves and then filter after the selection - refusing to do anything if the curve is not closed and planar - or using a more sophisticated technique, prevent the user from picking curves that are not closed and planar with a custom filter in rs.GetObject().

import rhinoscriptsyntax as rs

msg="Select a closed planar curve, surface or polysurface face"
obj_ref=rs.GetObject(msg,4+8,True,True,subobjects=True)
#separate curves and surfaces
obj_ID=obj_ref.ObjectId
if rs.IsCurve(obj_ID):
    if rs.IsCurveClosed(obj_ID) and rs.IsCurvePlanar(obj_ID):
        rs.Command("_ExtrudeCrv _Solid=_Yes", True)
    else:
        print "Unable to extrude, curve is not closed and planar!"
else:
    rs.Command("_ExtrudeSrf _Solid=_Yes _DeleteInput=_Yes", True)
import rhinoscriptsyntax as rs

def cp_crv_filt(rhino_object, geometry, component_index):
    #filter for closed planar curves
    return rs.IsCurvePlanar(geometry) and rs.IsCurveClosed(geometry)

msg="Select a closed planar curve, surface or polysurface face"
obj_ref=rs.GetObject(msg,4+8,True,True,custom_filter=cp_crv_filt,subobjects=True)
#separate curves and surfaces
if rs.IsCurve(obj_ref.ObjectId):
    rs.Command("_ExtrudeCrv _Solid=_Yes", True)
else:
    rs.Command("_ExtrudeSrf _Solid=_Yes _DeleteInput=_Yes", True)

HTH, --Mitch

Very Nice!
Thank you very much. I’m going to study hard.This is a good idea.