GetObjectEx

python

#1

Hello,

I have a question my code is not working and no idea where the problem is.
I sais; ‘BrepFace’ object has no attribute ‘Object’.

EDIT: I want to use GetObjectEx because I need the selection point. So, I need to extract the Guid in the Tuple and assign it to the .Object().Id,

obj_ref = rs.GetObjectEx ("Surface to move", rs.filter.surface, preselect=False, select=False, objects=None)
obj_ref = obj_ref[0]
obj_ref = rs.coercesurface(obj_ref)
print obj_ref

parent_id = obj_ref.Object().Id

surface_index = obj_ref.GeometryComponentIndex.Index

if rs.IsObjectInGroup (obj_ref) == True:
    groupName = rs.ObjectGroups (obj_ref)
    surface_index = 0

surface_ids = rs.ExtractSurface(parent_id, surface_index,True)

#2

@onrender, to pick a sub-surface of a brep or extrusion you could do this:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    # get one sub-surface from a brep 
    obj_ref = rs.GetObject("Surface to extract", 8, False, False, None, True)
    if not obj_ref: return
    
    # get object id of picked brep
    object_id = obj_ref.ObjectId
    
    # get index of picked sub-surface, exit if index is negative
    index = obj_ref.GeometryComponentIndex.Index
    if index == -1: return
    
    # extract sub-surface by index
    surface_ids = rs.ExtractSurface(object_id, index, copy=False)
    if surface_ids: 
        rs.SelectObjects(surface_ids)
    
DoSomething()

Is this what you’re trying to do ?

_
c.


#3

It could be good but I am also looking for the selection point that the GetObjectEx can provide in a Tuple.
So I need to extract the Guid from the Tuple and asign it to the .ObjectId.

It was also interesting that I selected both surface and polysurface , the message was all the time ‘BrepFace’ object has no attribute ‘Object’.


(qythium) #4

What are you trying to achieve with this? GetObjectEx returns a tuple(guid, bool, number, point, str), where tuple[0] gives you the GUID of the selected surface, and tuple[3] is the selection point as a RhinoCommon Point3d object.

BrepFace does not have a Object property, see http://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_BrepFace.htm


#5

Yes, it might be a bug.

I want to select a surface or polysurface. I want to get the selection point (the position of the point on the surface the where I clicked)

I want to get the ID of the surface if it is a polysurface OR ID will be “0” if it is a single surface.

I need to use GetObjectEx, because this is the only method that provides the selection point. The code above could not work. I also do not understand if it is a Surface or Polysurface, why it gives me Brep in the message.

Test fie:

test.3dm (87.1 KB)


(qythium) #6

Brep is the RhinoCommon term for Polysurface, they’re the same thing.

You’re passing rs.filter.surface into the filter argument, so even if you select a polysurface it will automatically extract the face and return that instead. To differentiate the two cases, use this

tup = rs.GetObjectEx ("Surface to move", rs.filter.surface | rs.filter.polysurface , preselect=False, select=False, objects=None)
polysrf = rs.coercebrep(tup[0]) 
polysrf.IsSurface # True/False

#7

You can get that from the obj_ref:

if obj_ref.SelectionMethod() == Rhino.DocObjects.SelectionMethod.MousePick:
    rs.AddPoint(obj_ref.SelectionPoint())

This is done using line 12 in my example. The GUID is in the variable object_id.
_
c.


#8

Thanks Clement, I just quickly view in the morning. It works properly, however the selection point is a bit weird in RhinoCommon. It works on vertical and horizontal surfaces but the projection on the tilting one is a bit out. I mean when I pick on surface the selection point does not line up with the position of the mouse and the Point is created a little bit right or left. :slight_smile:


#9

I don’t see that here, maybe you should post your example.

_
c.


Bug: SelectionPoint()
#10

I tried on the test.3dm file that I attached before. The bottom part of the object is fine, but when I click on the surface I showed it is weird :smiley:


#11

@onrender, @dale,

i can reproduce this with above file and guess this is a bug which is related to the singularity of the surfaces. I’ve tried to use obj_ref.SelectionPoint() as well as obj_ref.SurfaceParameter() and created the point from the uv values on the brep_face which it returns. It gives slightly off values, but only if the surface has singularity and if picked near the opposite side of the singular brep face vertex. V6 does the same using rs.GetObjectEx() or rs.GetObject() with subobject selection enabled.

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():

    obj_ref = rs.GetObject("Pick", 8, False, False, None, True)
    if not obj_ref: return
    
    if obj_ref.SelectionMethod() == Rhino.DocObjects.SelectionMethod.MousePick:
        rs.AddTextDot("A", obj_ref.SelectionPoint())
        
        face, u, v = obj_ref.SurfaceParameter()
        rs.AddTextDot("B", face.PointAt(u, v) )

DoSomething()

_
c.


#12

Okay thanks,

I report this bug in a separate thread and share the link of this one.


#13

It works well with polysurface but not with grouped surface.


#14

@onrender, it is still unclear to me what you’re trying to do and why.

Your initial script at the first post looked looked like that you’re trying to extact a sub-surface from a brep (polysurface). The example i posted demonstrates that. There is no purpose in using my example script on a group of surfaces, as there is no polysurface to extract a surface form.

To remove a surface from a group of objects, you might just use the _RemoveFromGroup command. It does not require a script. If you still wand to script that, you might try below script:

import rhinoscriptsyntax as rs

def DoSomething():
    msg = "Select surface to remove from group"
    srf_id = rs.GetObject(msg, 8, True, True, None, False)
    if srf_id: 
        if rs.IsObjectInGroup(srf_id):
            rs.RemoveObjectFromAllGroups(srf_id)
    
DoSomething()

_
c.


#15

Hi, My aim to use it for polysurface and for single surfaces as well.


#16

So when you pick on a sub-surface of a polysurface, you would like to extract this sub-surface and when you click on a surface inside a group you would like to remove the surface from the group ?
_
c.


#17

Yes, to process it further. I will probably use the remove methods but for testing now I want to extract and make it separate from the group or polysurface. Work in progress.


#18

@onrender, you just need to put both examples above together:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    obj_ref = rs.GetObject("Surface to extract", 8, False, False, None, True)
    if not obj_ref: return
    
    index = obj_ref.GeometryComponentIndex.Index
    if index == -1: 
        # remove surface from group if it is grouped
        if rs.IsObjectInGroup(obj_ref.ObjectId):
            rs.RemoveObjectFromAllGroups(obj_ref.ObjectId)
        rs.SelectObject(obj_ref.ObjectId)
        return
    
    # extract surface from polysurface
    surface_ids = rs.ExtractSurface(obj_ref.ObjectId, index, copy=False)
    if surface_ids: 
        rs.SelectObjects(surface_ids)
    
DoSomething()

_
c.