Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal: problem with deleted body

Status
Not open for further replies.

MANox

Mechanical
Apr 2, 2007
121
Hey,

For find solid body in part I use:
Code:
			Dim bodies As BodyCollection = workpart.Bodies
Dim solidBodies(0) As NXObject
Dim counter as Integer = 0
			
	if bodies.ToArray.Length > 0 then
			
		For Each thisBody As Body In bodies
                     If thisBody.IsSheetBody.Equals(False) Then
					 solidbodies(counter)=(thisBody)
					 counter += 1
		     End If
		Next
        End If
and it works fine.
But I have part with Delete Body function.
In Part Navigator Window I have only one body, but Vb sees two bodies, and one of then is no solid and no sheet body.
And can't add fantom body to solidbodies()
I don't know what I must doing for eliminate deleted body.
Maybe somebody can help me.
Best regards

Michał Nowak

NX9 & Tc10



 
Replies continue below

Recommended for you

Try the following code. It adds all the solid bodies to a list; it then looks through the feature tree for any "delete body" features and removes those bodies from the list.

Code:
Option Strict Off

Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module27
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim ufs As UFSession = UFSession.GetUFSession()

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim solidBodies As New List(Of Body)

        For Each theBody As Body In workPart.Bodies
            'lw.WriteLine("IsSheetBody: " & theBody.IsSheetBody.ToString)
            'lw.WriteLine("IsSolidBody: " & theBody.IsSolidBody.ToString)
            If theBody.IsSolidBody Then
                solidBodies.Add(theBody)
            End If
        Next

        For Each theFeature As Features.Feature In workPart.Features
            If TypeOf (theFeature) Is NXOpen.Features.DeleteBody Then
                Dim delBodyFeat As Features.DeleteBody = theFeature
                Dim delBodies() As Body = delBodyFeat.GetBodies
                For Each delBody As Body In delBodies
                    If solidBodies.Contains(delBody) Then
                        solidBodies.Remove(delBody)
                    End If
                Next
            End If
        Next

        lw.WriteLine("work part contains: " & solidBodies.Count.ToString & " solid bodies that have not been deleted")

    End Sub

End Module

www.nxjournaling.com
 
Thanks cowski,
it works great.
But I have another problem with user form and selection functions.
I wrote small program for show this:
Code:
Option Strict Off
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Features
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Math
Imports System.Windows.Forms
Imports System.Collections

Module Module1



    Public ufs As UFSession = UFSession.GetUFSession()
    Public theUI As UI = UI.GetUI
    Public theSession As Session = Session.GetSession()
    Public workPart As Part = theSession.Parts.Work
    Public displayPart As Part = theSession.Parts.Display
    Public lw As ListingWindow = theSession.ListingWindow
    Public myBodies() As NXObject
    Public myBody As NXOpen.Body


    Sub Main()



        Dim myDialog As New Form1

	myDialog.ShowDialog()
    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function
    Function SBody(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
        'funkcja pobiera body wkazane przez użytkownika
        Dim title As String = "Selection"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart

        Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_component_subtype
            .SolidBodySubtype = 0
        End With
        With selectionMask_array(1)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With


        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, title, scope, selAction, _
            includeFeatures, keepHighlighted, selectionMask_array, selObj, cursor)

        If resp = Selection.Response.ObjectSelected OrElse _
            resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

    Function Bodies(ByVal prompt As String, ByRef selObj() As NXObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        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 = Selection.SelectionScope.WorkPart

        Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_component_subtype
            .SolidBodySubtype = 0
        End With
        With selectionMask_array(1)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
        End With

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

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

    End Function


End Module



Public Class Form1

    Private Sub Button_OK_Click(sender As Object, e As EventArgs) Handles Button_OK.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK

        Me.Close()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button_Cancel.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub


    Private Sub SelectBodies_Click(sender As Object, e As EventArgs) Handles SelectBodies.Click
        Me.Hide()

        If Bodies("Wskaż zwierciadla", myBodies) = Selection.Response.Cancel Then
            Exit Sub
        End If
        Me.Show()
    End Sub

    Private Sub SelectBody_Click(sender As Object, e As EventArgs) Handles SelectBody.Click


        Me.Hide()
        If SBody("Wskaż swiatłowód", myBody) = Selection.Response.Cancel Then
            Exit Sub

        End If
        Me.Show()

    End Sub
End Class


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

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Button_Cancel = New System.Windows.Forms.Button()
        Me.Button_OK = New System.Windows.Forms.Button()
        Me.SelectBody = New System.Windows.Forms.Button()
        Me.SelectBodies = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Button_Cancel
        '
        Me.Button_Cancel.Location = New System.Drawing.Point(25, 133)
        Me.Button_Cancel.Name = "Button_Cancel"
        Me.Button_Cancel.Size = New System.Drawing.Size(100, 42)
        Me.Button_Cancel.TabIndex = 8
        Me.Button_Cancel.Text = "Cancel"
        Me.Button_Cancel.UseVisualStyleBackColor = True
        '
        'Button_OK
        '
        Me.Button_OK.Location = New System.Drawing.Point(193, 133)
        Me.Button_OK.Name = "Button_OK"
        Me.Button_OK.Size = New System.Drawing.Size(114, 42)
        Me.Button_OK.TabIndex = 7
        Me.Button_OK.Text = "OK"
        Me.Button_OK.UseVisualStyleBackColor = True
        '
        'SelectBody
        '
        Me.SelectBody.Location = New System.Drawing.Point(25, 40)
        Me.SelectBody.Name = "SelectBody"
        Me.SelectBody.Size = New System.Drawing.Size(100, 45)
        Me.SelectBody.TabIndex = 9
        Me.SelectBody.Text = "Select Body"
        Me.SelectBody.UseVisualStyleBackColor = True
        '
        'SelectBodies
        '
        Me.SelectBodies.Location = New System.Drawing.Point(193, 40)
        Me.SelectBodies.Name = "SelectBodies"
        Me.SelectBodies.Size = New System.Drawing.Size(114, 45)
        Me.SelectBodies.TabIndex = 10
        Me.SelectBodies.Text = "Select Bodies"
        Me.SelectBodies.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(319, 192)
        Me.Controls.Add(Me.SelectBodies)
        Me.Controls.Add(Me.SelectBody)
        Me.Controls.Add(Me.Button_OK)
        Me.Controls.Add(Me.Button_Cancel)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Add Attribute"
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents Button_Cancel As System.Windows.Forms.Button
    Friend WithEvents Button_OK As System.Windows.Forms.Button
    Friend WithEvents SelectBody As System.Windows.Forms.Button
    Friend WithEvents SelectBodies As System.Windows.Forms.Button

End Class

When I used "Select Body" or "Select Bodies" program started, I saw selection window and I couldn't select anything.
What I can do?

Best regard
Michał Nowak
 
The form.ShowDialog method will essentially lock you out of NX until the form is closed. If you compile the code to a .dll, you can use the form.Show method which will not lock you out of NX (but may cause problems if you are not careful). If the code will be run as a journal, you are limited to using the form.ShowDialog method.

However, if you are limited to running the code as a journal, all is not lost. You may be able to re-work the logic of the workflow to use the form to set the desired options, then close the form and pass control back to the Sub Main routine. I'll try to post a simple example, but it may not be today...

www.nxjournaling.com
 
Here's a quick example. The form simply gathers the user input, the module code (Sub Main, in this case) does all the work.

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim theForm As New Form1
        theForm.ShowDialog()
        'user is essentially locked out of NX until the form is closed

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

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

        Dim userSelectedObjects() As TaggedObject
        If SelectObjects("select one or more objects", userSelectedObjects) = Selection.Response.Cancel Then
            lw.WriteLine("object selection canceled")
            Return
        End If

        'get the options that the user selected on the form
        'the journal could perform different actions based on the options chosen
        lw.WriteLine("Options selected:")
        lw.WriteLine("Option 1: " & theForm.CheckBox1.Checked.ToString)
        lw.WriteLine("Option 2: " & theForm.CheckBox2.Checked.ToString)
        lw.WriteLine("Option 3: " & theForm.CheckBox3.Checked.ToString)
        lw.WriteLine("")
        lw.WriteLine(userSelectedObjects.Length.ToString & " object(s) selected")

        lw.Close()

    End Sub

    Function SelectObjects(prompt As String, ByRef selObj As TaggedObject()) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim typeArray() As Selection.SelectionType = _
           {Selection.SelectionType.All, _
               Selection.SelectionType.Faces, _
               Selection.SelectionType.Edges, _
               Selection.SelectionType.Features}

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects( _
                prompt, "Selection", _
                Selection.SelectionScope.AnyInAssembly, _
                False, typeArray, selObj)

        If resp = Selection.Response.ObjectSelected Or _
                resp = Selection.Response.ObjectSelectedByName Or _
                resp = Selection.Response.Ok Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

End Module

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

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 = Windows.Forms.DialogResult.Cancel
        Me.Close()
		'form is now closed, but not unloaded
		'values from the form can still be accessed

    End Sub

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

        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
		'form is now closed, but not unloaded
		'values from the form can still be accessed

    End Sub

End Class

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

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

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.CheckBox3 = New System.Windows.Forms.CheckBox()
        Me.CheckBox2 = New System.Windows.Forms.CheckBox()
        Me.CheckBox1 = 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.CheckBox3)
        Me.GroupBox1.Controls.Add(Me.CheckBox2)
        Me.GroupBox1.Controls.Add(Me.CheckBox1)
        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 = "Generic Options"
        '
        'CheckBox3
        '
        Me.CheckBox3.AutoSize = True
        Me.CheckBox3.Location = New System.Drawing.Point(22, 76)
        Me.CheckBox3.Name = "CheckBox3"
        Me.CheckBox3.Size = New System.Drawing.Size(66, 17)
        Me.CheckBox3.TabIndex = 2
        Me.CheckBox3.Text = "Option 3"
        Me.CheckBox3.UseVisualStyleBackColor = True
        '
        'CheckBox2
        '
        Me.CheckBox2.AutoSize = True
        Me.CheckBox2.Location = New System.Drawing.Point(22, 53)
        Me.CheckBox2.Name = "CheckBox2"
        Me.CheckBox2.Size = New System.Drawing.Size(66, 17)
        Me.CheckBox2.TabIndex = 1
        Me.CheckBox2.Text = "Option 2"
        Me.CheckBox2.UseVisualStyleBackColor = True
        '
        'CheckBox1
        '
        Me.CheckBox1.AutoSize = True
        Me.CheckBox1.Location = New System.Drawing.Point(22, 30)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(66, 17)
        Me.CheckBox1.TabIndex = 0
        Me.CheckBox1.Text = "Option 1"
        Me.CheckBox1.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
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents CheckBox3 As System.Windows.Forms.CheckBox
    Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
End Class

www.nxjournaling.com
 
Here's a slightly more interesting version based on the journal above. This one filters the allowable selections based on the options chosen on the user form.

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

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim theForm As New Form1
        theForm.ShowDialog()

        If theForm.DialogResult = 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
            lw.WriteLine("object selection canceled")
            Return
        End If

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

        lw.WriteLine("")
        lw.WriteLine(userSelectedObjects.Length.ToString & " object(s) selected")

        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 = 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

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

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

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

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

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 = 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 = Windows.Forms.DialogResult.OK
        Me.Close()

    End Sub

End Class

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

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

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        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
    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
End Class

www.nxjournaling.com
 
thanks for the help cowski.
Last week I was sick and I couldn't work with this.
I pay tribute to your solution

Best regards

Michał Nowak
 
Hello Cowski,
Can you make a similar example but with MODELESS?
I have the NX AUTHOR LICENSE and I can compile it.
Thanks

CAD NX9 Electrical Designer / NXOpen
Product Design Analyst
MSXI / LEAR Sao Paulo Brasil
Masters Degree Math, Wayne State Univ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor