You are on page 1of 7

Filter out faces not facing the user - Manufacturing DevBlog

http://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces...

Manufacturing DevBlog
(http://adndevblog.typepad.com
/manufacturing/)
The resource for software developers working with Design, Lifecycle and Simulation
technologies from Autodesk.

07/06/2016

Filter out faces not facing the user


By Adam Nagy (http://adndevblog.typepad.com/manufacturing
/adam-nagy.html)
The API Help contains a sample that lets you prompt the user to
select a Face. This is helped by the option of specifying the object
types we allow:
oSelectEvents.AddSelectionFilter filter
If you need more granularity when deciding which faces should be
selectable then you can just handle the OnPreSelect event of
the SelectEvents object. There you can check e.g. if the Face is
planar or not, and in which direction its Normal is pointing. If e.g.
it's pointing away from the user then you could make it not selectable:
Module

1 de 7

20/01/2017 23:18

Filter out faces not facing the user - Manufacturing DevBlog

http://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces...

Public Sub TestSelection()


' Create a new clsSelect object.
Dim oSelect As New clsSelect
' Call the pick method of the clsSelect obje
ct and set
' the filter to pick any face.
Dim oFaces As ObjectsEnumerator
Set oFaces = oSelect.Pick(kPartFaceFilter)
' Check to make sure an object was selected.
Dim oSelSet As SelectSet
Set oSelSet = ThisApplication.ActiveDocument
.SelectSet
For Each oFace In oFaces
oSelSet.Select oFace
Next
End Sub
clsSelect

2 de 7

20/01/2017 23:18

Filter out faces not facing the user - Manufacturing DevBlog

http://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces...

'***********************************************
**************
' The declarations and functions below need to b
e copied into
' a class module whose name is "clsSelect". The
name can be
' changed but you'll need to change the declarat
ion in the
' calling function "TestSelection" to use the ne
w name.
' Declare the event objects
Private WithEvents oInteractEvents As Interactio
nEvents
Private WithEvents oSelectEvents As SelectEvents
' Declare a flag that's used to determine when s
election stops.
Private bStillSelecting As Boolean
Public Function Pick(filter As SelectionFilterEn
um) As ObjectsEnumerator
' Initialize flag.
bStillSelecting = True
' Create an InteractionEvents object.
Set oInteractEvents = ThisApplication.CommandM
anager.CreateInteractionEvents
' Ensure interaction is enabled.
oInteractEvents.InteractionDisabled = False
' Set a reference to the select events.
Set oSelectEvents = oInteractEvents.SelectEven
ts
oSelectEvents.WindowSelectEnabled = True
' Set the filter using the value passed in.
oSelectEvents.AddSelectionFilter filter
' Start the InteractionEvents object.
oInteractEvents.Start
' Loop until a selection is made.

3 de 7

20/01/2017 23:18

Filter out faces not facing the user - Manufacturing DevBlog

http://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces...

Do While bStillSelecting
ThisApplication.UserInterfaceManager.DoEvent
s
Loop
' Get the selected item. If more than one thin
g was selected,
' just get the first item and ignore the rest.
Dim oSelectedEnts As ObjectsEnumerator
Set oSelectedEnts = oSelectEvents.SelectedEnti
ties
If oSelectedEnts.Count > 0 Then
Set Pick = oSelectedEnts
Else
Set Pick = Nothing
End If
' Stop the InteractionEvents object.
oInteractEvents.Stop
' Clean up.
Set oSelectEvents = Nothing
Set oInteractEvents = Nothing
End Function
Private Sub oInteractEvents_OnTerminate()
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
Private Sub oSelectEvents_OnPreSelect( _
PreSelectEntity As Object, DoHighlight As Boolea
n, _
MorePreSelectEntities As ObjectCollection, _
ByVal SelectionDevice As SelectionDeviceEnum, _
ByVal ModelPosition As Point, _
ByVal ViewPosition As Point2d, ByVal View As Vie
w)
If Not TypeOf PreSelectEntity Is Face Then Ex
it Sub
Dim oFace As Face
Set oFace = PreSelectEntity

4 de 7

20/01/2017 23:18

Filter out faces not facing the user - Manufacturing DevBlog

http://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces...

If Not TypeOf oFace.Geometry Is Plane Then Ex


it Sub
Dim oPlane As Plane
Set oPlane = oFace.Geometry
Dim oViewDir As Vector
Set oViewDir = View.Camera.Eye.VectorTo(View.
Camera.Target)
If oFace.IsParamReversed Then
oViewDir.ScaleBy -1
End If
' The direction the user is looking into and
the face's
' normal the same then the dot product is pos
itive, so
' we won't highlight the face
If oPlane.Normal.DotProduct(oViewDir.AsUnitVe
ctor()) > 0 Then
' Without this all 6 faces of the box would
be selected
DoHighlight = False
End If
End Sub
Private Sub oSelectEvents_OnSelect( _
ByVal JustSelectedEntities As ObjectsEnumerator,
_
ByVal SelectionDevice As SelectionDeviceEnum, _
ByVal ModelPosition As Point, ByVal ViewPosition
As Point2d, ByVal View As View)
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub

5 de 7

20/01/2017 23:18

Filter out faces not facing the user - Manufacturing DevBlog

http://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces...

(http://adndevblog.typepad.com
/.a/6a0167607c2431970b01bb091be323970d-popup)
Only the 3 user facing faces are selected.
Posted at 12:56 PM in Adam Nagy (http://adndevblog.typepad.com/manufacturing
/adam-nagy/), Inventor (http://adndevblog.typepad.com/manufacturing
/inventor/) | Permalink (http://adndevblog.typepad.com/manufacturing/2016/07
/filter-out-faces-not-facing-the-user.html)
(http://twitter.com/share?url=http%3A%2F
%2Fadndevblog.typepad.com%2Fmanufacturing%2F2016%2F07%2Ffilterout-faces-not-facing-the-user.html&
text=Filter%20out%20faces%20not%20facing%20the%20user)
(https://plus.google.com/share?url=http://adndevblog.typepad.com
/manufacturing/2016/07/filter-out-faces-not-facing-the-user.html)
(http://www.facebook.com/sharer.php?u=http%3A%2F
%2Fadndevblog.typepad.com%2Fmanufacturing%2F2016%2F07%2Ffilterout-faces-not-facing-the-user.html)

Comments
Typepad (http://www.typepad.com
Comment below or sign in with
/sitelogin?uri=http%3A%2F
%2Fadndevblog.typepad.com%2Fmanufacturing%2F2016%2F07%2Ffilterout-faces-not-facing-the-user.html&fp=11de38fcb077768841c4aa0810914abd&
view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&post_uri=http:
//adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces-not-facingthe-user.html)
Facebook (http://www.typepad.com/sitelogin?uri=http%3A%2F
%2Fadndevblog.typepad.com%2Fmanufacturing%2F2016%2F07%2Ffilterout-faces-not-facing-the-user.html&fp=11de38fcb077768841c4aa0810914abd&
view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&
service=facebook&post_uri=http://adndevblog.typepad.com/manufacturing
/2016/07/filter-out-faces-not-facing-the-user.html)
Twitter
(http://www.typepad.com/sitelogin?uri=http%3A%2F
%2Fadndevblog.typepad.com%2Fmanufacturing%2F2016%2F07%2Ffilterout-faces-not-facing-the-user.html&fp=11de38fcb077768841c4aa0810914abd&
view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&
service=twitter&post_uri=http://adndevblog.typepad.com/manufacturing
/2016/07/filter-out-faces-not-facing-the-user.html)
Google+
(http://www.typepad.com/sitelogin?uri=http%3A%2F
%2Fadndevblog.typepad.com%2Fmanufacturing%2F2016%2F07%2Ffilterout-faces-not-facing-the-user.html&fp=11de38fcb077768841c4aa0810914abd&
view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&service=gplus&

6 de 7

20/01/2017 23:18

Filter out faces not facing the user - Manufacturing DevBlog

http://adndevblog.typepad.com/manufacturing/2016/07/filter-out-faces...

post_uri=http://adndevblog.typepad.com/manufacturing/2016/07/filterout-faces-not-facing-the-user.html) and more... (http://www.typepad.com


/sitelogin?uri=http%3A%2F
%2Fadndevblog.typepad.com%2Fmanufacturing%2F2016%2F07%2Ffilterout-faces-not-facing-the-user.html&fp=11de38fcb077768841c4aa0810914abd&
view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&
service=openid&post_uri=http://adndevblog.typepad.com/manufacturing
/2016/07/filter-out-faces-not-facing-the-user.html)

(URLs automatically linked.)

Email address is not displayed with comment.

(http://www.typepad.com/)
Manufacturing DevBlog (http://adndevblog.typepad.com/manufacturing/)

7 de 7

20/01/2017 23:18

You might also like