Select Backfaces command?

A command like SelBackfaces would be really useful - a command that selects only objects facing away from the camera. In a model with a lot of such surfaces/mesh faces Flipping them all in one go might save some time.

In an example below backfaces are colored pink - they are all separate surfaces.

2 Likes

Hi @Daniel_Krajnik
I agree that would be a good command to have implemented. Especially when the faces are part of a polysurface.

If that’s your custom display and if those are not part of a polysurface you could write a quick macro
selcolor
flip
RM

1 Like

Yep, I’ve been thinking of a more general “Select by Normal” command, but SelBackface may be more intuitive.

The pink color is driven by this display setting, so SelColor won’t work:
image

Try this:

-runscript (
sub SelectByCentralNormal

Dim arrObjects, strObject
objs = Rhino.AllObjects
If IsArray(objs) Then
Rhino.UnselectAllObjects()
For Each obj In objs


' SURFACE CASE
if Rhino.IsSurface(obj) then
surf = obj
UV = Rhino.SurfaceParameter (surf , Array(0.5,0.5))
normal = Rhino.SurfaceNormal (surf , UV)
cameraLocs = Rhino.ViewCameraTarget()
vector = Rhino.VectorCreate(cameraLocs(1),cameraLocs(0))
angle = Rhino.VectorAngle(vector,normal)
if angle<90 then
Rhino.SelectObject(surf)
End If
End If


Next
Rhino.ZoomSelected()
End If
End sub
SelectByCentralNormal
3 Likes

Hi @Daniel_Krajnik

Argh yet another one of Rhino’s caveats. For instance sel color doesn’t work even if you have a layer color assigned on an object, this only works if you have a material assigned first.

RM

Hello- please provide an example of this.

-Pascal

Thank you very much @maje90, I have just tried running the script, but I can’t quite get it to work - it doesn’t seem to select the backfaces for me (pink). I’ve tried running it both by copy pasting your code into the console and saving it as .rvb and running it via RunScript command - same results.


Sample 3dm attached:
sample.3dm (2.3 MB)

@3dsynergy hmm I haven’t experienced this one yet, for example here are two cubes on two layers that take colors “ByLayer” with both layers turned to red. SelColor seems to pick both up?

It seems you need to swap the test, from >90 to <90, i made a mistake. I edited the code.
In your file there are only 2 surfaces, if you do that edit it will work.
Polysurfaces and other types are not handled.

Coding in the old rhinoscript is hard :sweat_smile:, I can’t wait to work with Rhinocode…

1 Like

Brilliant, thank you very much! Confirmed, it’s working here as well :slight_smile:

Do you know if it’s possible to set this script to an alias? When I did this I got an error (sorry, not used to rhinoscripts)

image

I think you need to use _-Loadscript and not _-Runscript. Plus you need to add a ‘Call’ statement at the top to launch the script once it has loaded.

Call SelectByCentralNormal()
Sub SelectByCentralNormal()
1 Like

I’m relatively late to the party here, I was traveling yesterday. While these are not selection scripts, they might be useful to automatically flip backfaces (i.e. no need to select and then run Flip)

UnifyNormalsZ.py (1.4 KB)
(useful for topo maps for example)

UnifyNormalsView.py (1.3 KB)
(only takes planar surfaces)

UnifyNormalsViewNP.py (1.9 KB)
(allows non planar surfaces)

And this one, still a bit in development, which I made recently in response to [another thread] which did not go further. (How to select flipped faces only? - #9 by Helvetosaur)

FlipBrepNormalsAwayFromCentroid5.py (3.9 KB)

2 Likes