Select sketch in 3D view in part document

Select sketch in 3D view in part document

Jo_Perturbable
Contributor Contributor
692 Views
3 Replies
Message 1 of 4

Select sketch in 3D view in part document

Jo_Perturbable
Contributor
Contributor

Hi,

is it possible to select sketch(es) in the 3D view with the SelectionFilterEnum in a part document (.ipt)?

The selection of sketches is described in another post: Selection Methods.
But this does not allow to select a sketch in the 3D view, only in the model browser. What am I missing?
And the same applies to the selection via InteractionEvents like:

_InteractionEvents = _Application.CommandManager.CreateInteractionEvents();
_SelectEvents.AddSelectionFilter(SelectionFilterEnum.kSketch3DObjectFilter);


Thanks in advance 🙂

I use:
Autodesk Inventor Professional 2021
64-Bit-Edition
Build: 245, Release 2021.1

0 Likes
Accepted solutions (1)
693 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Unfortunately, no.  It can only be selected from the BrowserNode, but what you could do is select another type of sketch entity, then get its Parent within the code, to get the Sketch object.

Like this:

Dim oEnt As SketchEntity =  ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveFilter, "Select a Sketch Curve.")
MsgBox("You picked a Sketch named  " & oEnt.Parent.Name)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 4

Anonymous
Not applicable

using a slight modification:

Dim oEnt As SketchEntity =  ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DObjectFilter, "Select a Sketch Curve.")
MsgBox("You picked a Sketch named  " & oEnt.Parent.Name)


i get error message:

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.SketchEntity'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B546124D-09AA-11D5-8DEC-0010B541CAA8}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 
you can reverse engineer the error message to see how you can interact with the entity or 'System._ComObject" 

You even get an Interface with IID #. 

hope this helps. 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @Anonymous.  When using the Pick method, you either have to define the variable as the correct object Type (to match the filter), or you have to not define the variable's Type ahead of time, to avoid errors.  Then, it's usually best to check if any value was given to the variable, in case you canceled out of it without picking something (I didn't do that in my example).  If you chose to not define the variable's Type ahead of time, then you may need to check the variable's Type afterwards, especially when there may be a small range of actual object types that may be returned by the specified selection filter.  In this case, you are trying to get an actual Sketch3D object, so the variable's type would need to be defined as Sketch3D to match the filter.  But you still can't select that Sketch3D object directly within the model space, and must instead select it from the model browser tree, to make this rule work.

 

Dim oS3D As Sketch3D = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DObjectFilter, "Select a Sketch Curve.")
If IsNothing(oS3D) Then Return
MsgBox("You picked a 3D Sketch named  " & oS3D.Name)

 

However, as stated before, if you want to select the Sketch3D object by selecting some geometry belonging to it within the model space, you could do that this way:

 

Dim oSE3D As SketchEntity3D = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DDefaultFilter, "Select a 3D Sketch entity.")
If IsNothing(oSE3D) Then Return
MsgBox("You picked a 3D Sketch named  " & oSE3D.Parent.Name)
ThisDoc.Document.SelectSet.Select(oSE3D.Parent)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes