I'm trying to get this subroutine to work which prompts the user to select a sketch and returns both the Sketch and its SketchFeature, but I'm running into erros with the SelectTaggedObject.
Any suggestions?
<code>
Sub SelectSketch(ByRef sketch As NXOpen.Sketch, ByRef sketchFeature As NXOpen.Features.SketchFeature, ByRef success As Boolean)
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim workPart As Part = theSession.Parts.Work
success = False
sketch = Nothing
sketchFeature = Nothing
' Use SelectionType.Feature to allow only features (including SketchFeature)
Dim types() As Selection.SelectionType = {Selection.SelectionType.Feature}
Dim selectedObj As TaggedObject
Dim cursor As Point3d
Dim response As Selection.Response = theUI.SelectionManager.SelectTaggedObject( _
"Select a Sketch Feature", "Please select a sketch feature", _
Selection.SelectionScope.WorkPart, types, selectedObj, cursor)
If response <> Selection.Response.Ok OrElse selectedObj Is Nothing Then
MsgBox("No sketch was selected.", MsgBoxStyle.Information, "Selection Cancelled")
Return
End If
sketchFeature = TryCast(selectedObj, SketchFeature)
If sketchFeature Is Nothing Then
MsgBox("Selected feature is not a sketch.", MsgBoxStyle.Critical, "Invalid Selection")
Return
End If
sketch = TryCast(sketchFeature.FindObject(sketchFeature.Name), Sketch)
If sketch Is Nothing Then
MsgBox("Could not retrieve the Sketch object from the SketchFeature.", MsgBoxStyle.Critical, "Error")
Return
End If
success = True
End Sub
</code>
Thanks,
Jeff
Any suggestions?
<code>
Sub SelectSketch(ByRef sketch As NXOpen.Sketch, ByRef sketchFeature As NXOpen.Features.SketchFeature, ByRef success As Boolean)
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim workPart As Part = theSession.Parts.Work
success = False
sketch = Nothing
sketchFeature = Nothing
' Use SelectionType.Feature to allow only features (including SketchFeature)
Dim types() As Selection.SelectionType = {Selection.SelectionType.Feature}
Dim selectedObj As TaggedObject
Dim cursor As Point3d
Dim response As Selection.Response = theUI.SelectionManager.SelectTaggedObject( _
"Select a Sketch Feature", "Please select a sketch feature", _
Selection.SelectionScope.WorkPart, types, selectedObj, cursor)
If response <> Selection.Response.Ok OrElse selectedObj Is Nothing Then
MsgBox("No sketch was selected.", MsgBoxStyle.Information, "Selection Cancelled")
Return
End If
sketchFeature = TryCast(selectedObj, SketchFeature)
If sketchFeature Is Nothing Then
MsgBox("Selected feature is not a sketch.", MsgBoxStyle.Critical, "Invalid Selection")
Return
End If
sketch = TryCast(sketchFeature.FindObject(sketchFeature.Name), Sketch)
If sketch Is Nothing Then
MsgBox("Could not retrieve the Sketch object from the SketchFeature.", MsgBoxStyle.Critical, "Error")
Return
End If
success = True
End Sub
</code>
Thanks,
Jeff