Extract surface?


#1

Hey all,

I’ m trying to extract surface based on mouse click .

it tried code below, but something is wrong, if i click on cube face, the face is extracted, but another one too, i got 2 faces extracted in one click.

if i try on a cylinder , nothing happend no faces were extracted , strange …

How i can do that ?

Thanks for help.

Call Main()
Sub Main()

	Dim arrParameter, arrPick , LastSfr 
	
	arrPick = Rhino.GetObjectEx("Select surface to Extract ", 16)

	If IsArray(arrPick) Then

		arrParameter = Rhino.BrepClosestPoint(arrPick(0), arrPick(3))		
	
		LastSfr = Rhino.ExtractSurface(arrPick(0), arrParameter(2))
		
					
	End If

End Sub


#2

@Cyver,

you might just use rs.GetObject() with subobjects=True, this returns an obj_ref from which you can get the parent polysurface Id and the subsurface index:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    obj_ref = rs.GetObject("Surface to extract", 8, True, False, None, True)
    if not obj_ref: return
    
    parent_id = obj_ref.Object().Id
    surface_index = obj_ref.GeometryComponentIndex.Index
    
    if surface_index >= 0:
        surface_ids = rs.ExtractSurface(parent_id, surface_index)
        if surface_ids:
            rs.SelectObjects(surface_ids)
    
if __name__=="__main__":
    DoSomething()

c.


#3

Hi Clement,

Thanks for reply, but i’m using VBscript and i don’t see any subobjects options in rhino.GetObject.
that’s why i tried with GetObjectEx

is there a solution for rhinoscript ?

Thx.


#4

@Cyver

Your script seems to work here - you forgot to dim the extracted surface variable LastSfr … --Mitch


#5

Hi Mitch

yes and no, as a said if i use script on a Cube, for example, 2 surfaces will be detached, one under click and another one. LastSfr return 2 strings, what’s wrong ?

If i use script on a Cylinder, nothing happend, LastSfr is Null

Any idea ?


#6

Hi @Cyver, sorry ! Please see if below does what you need:

Option Explicit

Call Main()
Sub Main()

    Dim arrPick, arrCP, arrTypeIndex, intIndex, strSurface
        arrPick = Rhino.GetObjectEx("Select surface to Extract ", 16)
        If IsArray(arrPick) Then
            arrCP = Rhino.BrepClosestPoint(arrPick(0), arrPick(3))
            If IsArray(arrCP) Then
                arrTypeIndex = arrCP(2)
                If arrTypeIndex(0) = 3 Then
                    intIndex = arrTypeIndex(1)
                    strSurface = Rhino.ExtractSurface(arrPick(0), CInt(intIndex))
                    If Not IsNull(strSurface) Then 
                        Rhino.SelectObject strSurface
                    End If
                End If    
            End If
        End If

End Sub

Some tips: Always use Option Explicit on top of your scripts to prevent writing variable names which cannot be found because they where not Dim'ed. Meaningfull variable names help you, eg. Rhino.BrepClosestPoint does not return parameters but an array of other arrays. Note that the second argument in Rhino.ExtractSurface was the error in your script. You need to get the index of the brep face which arrCP (in my script) contains and pass this.

@dale, i think Rhino.ExtractSurface has some buglet here. If i pass the variable intIndex in above script without converting it using CInt, the method complains that i need to pass an array, intIndex is a vbSingle coming right from the Rhino.BrepClosestPoint result.

c.


#7

This happens because you are passing an array of two numbers. See what Rhino.BrepClosestPoint returns. Element 2 is an array containing two numbers, the first number is the type, the second the index.

c.


#8

Clement,

Thanks for time and help.

Each time i use rhinoscript help, but that’s not always really clear for me.


#9

No problem. Also note that Rhino.BrepClosestPoint offers an argument blnFaces. If you never want to get indices of brep vertices, edges, trims or loops returned, you might want to set this to True.

c.