Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

NX Open: WinForm + Mask Select Body

Patrick1234

Mechanical
Oct 21, 2024
2
0
0
CA
Hello,

I have a technical question. I'd like to validate a point before spending too much time trying to find a solution.

I'm currently working on a small application (on VS2019 in VB .net) to export Parasolid using a WinForm interface.

1-In journaling: open the application (WinForm interface with 1 button “Select Button”)
2-Click on the selection button: Clicking on the selection button calls a “Selection.MaskTriple” function. While the function is active, the WinForm window should become background.
3-Select a component on the screen. I want to select a component in the screen and retrieve the Tag of this component and its attributes...then I'll do other things with this information.
4-Exit the “Selection.MaskTriple” function and return the WinForm window to the foreground.

So in Journaling, my application is displayed correctly from NX. When I click on my button, I call a “Selection.MaskTriple” function and the NX selection window appears correctly. However, the focus remains on the Winform window and although I see the “Selection.MaskTriple” window, it's inaccessible and I can't select any items in the NX assembly or in the NX window.

My question is, is it possible to pair a Winform Interface and a ''Selection.MaskTriple'' function with NX's little selection box? I want to know if I'm wasting my time with this approach.

If you tell me that it's possible to combine the two, I'll look into the matter further... because I've been trying a lot of things for two days now and haven't found a solution yet.

Best Ragards!

Patrick
 
Replies continue below

Recommended for you

I found this code that almost does the job.

Is it possible to have “Form1” displayed again after the items have been selected?





Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

Public TheSession As Session = Session.GetSession()
Public TheUI As UI = UI.GetUI()
Public TheUFSession As UFSession = UFSession.GetUFSession()
Public ufs As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()

Sub Main(ByVal args() As String)

Dim workPart As Part = TheSession.Parts.Work
Dim lw As ListingWindow = TheSession.ListingWindow

If IsNothing(TheSession.Parts.Work) Then
'active part required
Return
End If

lw.Open()
Echo("PTS-0")
Dim theForm As New Form1()
theForm.ShowDialog()
Echo("PTS-1")

If theForm.DialogResult = System.Windows.Forms.DialogResult.Cancel Then
MsgBox("User pressed 'Cancel', exit journal")
Return
End If

'MsgBox("continue journal code in Sub Main()")

Dim selectionMask() As Selection.MaskTriple = Nothing
BuildSelectionMask(selectionMask, theForm.chkFaces.Checked, theForm.chkCurves.Checked)

Dim userSelectedObjects() As TaggedObject = Nothing
If SelectObjects(selectionMask, userSelectedObjects) = Selection.Response.Cancel Then
Echo("object selection canceled")
Return
End If

Echo("Options selected:")
Echo("Select Solids: " & theForm.chkSolids.Checked.ToString)
Echo("Select Faces: " & theForm.chkFaces.Checked.ToString)
Echo("Select Curves: " & theForm.chkCurves.Checked.ToString)

Echo("")
Echo(userSelectedObjects.Length.ToString & " object(s) selected")

For Each temp As TaggedObject In userSelectedObjects
Echo("object type: " & temp.GetType.ToString)
Echo("object tag: " & temp.Tag.ToString)
Echo("")
Next

lw.Close()

End Sub

Function SelectObjects(ByVal selMask() As Selection.MaskTriple, ByRef selObj() As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim prompt As String = "Select Objects"
Dim title As String = "Selection"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific

Dim scope As Selection.SelectionScope = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY 'Selection.SelectionScope.WorkPart

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, title, scope, selAction, includeFeatures, keepHighlighted, selMask, selObj)

If resp = Selection.Response.Ok Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Sub BuildSelectionMask(ByRef maskArray() As Selection.MaskTriple, ByVal faces As Boolean, ByVal curves As Boolean)

Dim theSelectionMasks As New List(Of Selection.MaskTriple)

Dim newSelMask As Selection.MaskTriple
With newSelMask
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With

theSelectionMasks.Add(newSelMask)

If faces Then
newSelMask.Type = UFConstants.UF_solid_type
newSelMask.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
theSelectionMasks.Add(newSelMask)
End If

If curves Then
newSelMask.Type = UFConstants.UF_line_type
newSelMask.Subtype = UFConstants.UF_line_normal_subtype
theSelectionMasks.Add(newSelMask)

newSelMask.Type = UFConstants.UF_circle_type
newSelMask.Subtype = UFConstants.UF_all_subtype
theSelectionMasks.Add(newSelMask)

newSelMask.Type = UFConstants.UF_conic_type
newSelMask.Subtype = UFConstants.UF_all_subtype
theSelectionMasks.Add(newSelMask)

newSelMask.Type = UFConstants.UF_spline_type
newSelMask.Subtype = UFConstants.UF_all_subtype
theSelectionMasks.Add(newSelMask)

End If

maskArray = theSelectionMasks.ToArray
End Sub

'FUNCTION: Echo
Public Function Echo(ByVal output As String)
TheSession.ListingWindow.Open()
TheSession.ListingWindow.WriteLine(output)
TheSession.LogFile.WriteLine(output)
End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

' Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

'************************************************************************************************

Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()

End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()

End Sub

End Class

'************************************************************************************************
'Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
Inherits System.Windows.Forms.Form


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

End Sub


'Form overrides dispose to clean up the component list.
'
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.

Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents chkCurves As System.Windows.Forms.CheckBox
Friend WithEvents chkFaces As System.Windows.Forms.CheckBox
Friend WithEvents chkSolids As System.Windows.Forms.CheckBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button

'Private Sub InitializeComponent()
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form_NXOpen_Template))

Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.chkCurves = New System.Windows.Forms.CheckBox()
Me.chkFaces = New System.Windows.Forms.CheckBox()
Me.chkSolids = New System.Windows.Forms.CheckBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.chkCurves)
Me.GroupBox1.Controls.Add(Me.chkFaces)
Me.GroupBox1.Controls.Add(Me.chkSolids)
Me.GroupBox1.Location = New System.Drawing.Point(12, 26)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(260, 118)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Selection Options"
'
'chkCurves
'
Me.chkCurves.AutoSize = True
Me.chkCurves.Location = New System.Drawing.Point(22, 76)
Me.chkCurves.Name = "chkCurves"
Me.chkCurves.Size = New System.Drawing.Size(59, 17)
Me.chkCurves.TabIndex = 2
Me.chkCurves.Text = "Curves"
Me.chkCurves.UseVisualStyleBackColor = True
'
'chkFaces
'
Me.chkFaces.AutoSize = True
Me.chkFaces.Location = New System.Drawing.Point(22, 53)
Me.chkFaces.Name = "chkFaces"
Me.chkFaces.Size = New System.Drawing.Size(55, 17)
Me.chkFaces.TabIndex = 1
Me.chkFaces.Text = "Faces"
Me.chkFaces.UseVisualStyleBackColor = True
'
'chkSolids
'
Me.chkSolids.AutoSize = True
Me.chkSolids.Checked = True
Me.chkSolids.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkSolids.Enabled = False
Me.chkSolids.Location = New System.Drawing.Point(22, 30)
Me.chkSolids.Name = "chkSolids"
Me.chkSolids.Size = New System.Drawing.Size(54, 17)
Me.chkSolids.TabIndex = 0
Me.chkSolids.Text = "Solids"
Me.chkSolids.UseVisualStyleBackColor = True
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(12, 165)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(84, 34)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Select Objects"
Me.Button1.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button2.Location = New System.Drawing.Point(188, 165)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(84, 34)
Me.Button2.TabIndex = 2
Me.Button2.Text = "Cancel"
Me.Button2.UseVisualStyleBackColor = True
'
'Form1
'
Me.AcceptButton = Me.Button1
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.Button2
Me.ClientSize = New System.Drawing.Size(284, 218)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.GroupBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.Text = "Form1"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)

End Sub
#End Region


End Class
End Module
 
Back
Top