Sub-object vbscript


#1

Hi,
in Vbscript
how to use GetObject to select the surface from polysurface, or other sub-object


#2

I’m afraid you can’t with VBScript, none of the subobject selection methods are exposed yet. The only way I know of to get to a sub-surface with scripting is with Python and RhinoCommon. Otherwise, the common workaround is to explode a copy of the polysurface in question, isolate the surface(s) you need, and throw away the rest…

–Mitch


#3

Below is an example with Python… --Mitch

import Rhino, scriptcontext
import rhinoscriptsyntax as rs
#Example adapted from Python forum post, thanks to Vittorio and Emilio

def DuplicateBRepSrfs():
    prompt="Select BRep surface(s) to duplicate"
    srf_type=Rhino.DocObjects.ObjectType.Surface
    
    rc, subsurf_refs = Rhino.Input.RhinoGet.GetMultipleObjects(prompt, True, srf_type)
    if rc != Rhino.Commands.Result.Success: return
    if subsurf_refs:
        breps=[]
        #breps will contain the duplicate surface *geometry*
        for srf in subsurf_refs:
            face=srf.Face()
            brep=face.DuplicateFace(False)
            breps.append(brep)
            
    #if you actually want to add the objects to the document:
    dupsrf_IDs=[scriptcontext.doc.Objects.AddBrep(brep) for brep in breps]
    scriptcontext.doc.Views.Redraw()
    
DuplicateBRepSrfs()

#4

Thanks for help


(Steve Baer) #5

It is also worth noting that the GetObject function in rhinoscriptsyntax does support subobject selection (note the subobjects optional parameter in the function)
https://github.com/mcneel/rhinopython/blob/master/scripts/rhinoscript/selection.py#L170