@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()
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’.
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.
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.
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
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.
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()
@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()
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.
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.
@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()