Cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting something

Pioneer
Pioneer

HI, I am new to SNAP.

 

In my application I would like to select some points from the screen to get its position. The selection form comes up but it is inactive. I used;

 

Dim cue = "Please select a line to be hidden"

Dim dialog As Snap.UI.Selection.Dialog = Snap.UI.Selection.SelectObject(cue)

dialog.SetFilter(NX.ObjectTypes.Type.Line)

dialog.Title = "Selection Demo"

dialog.Scope = Snap.UI.Selection.Dialog.SelectionScope.AnyInAssembly

dialog.IncludeFeatures = False

Dim result As Snap.UI.Selection.Result = dialog.Show()

If result.Response <> NXOpen.Selection.Response.Cancel Then

result.Object.IsHidden = True

End If

5 REPLIES

Re: Selecting something

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Your code works quite nicely to select a line, and then it blanks (hides) the line.  Because of this line in your code:

 

dialog.SetFilter(NX.ObjectTypes.Type.Line)

 

It will only let you pick a line.

 

But you mentioned that you wanted to get points.  If you want to pick existing Point entities, change the line above to look like this:

 

dialog.SetFilter(NX.ObjectTypes.Type.Point)

 

Then in your if block, you can echo the value of the point that was selected:

 

Option Strict Off
Imports System
Imports NXOpen
Imports Snap

Module snapSelectPoint

    Dim theSession As Session = Session.GetSession()

    Sub Main()

        Dim cue As String = "Please select a line to be hidden"

        Dim dialog As Snap.UI.Selection.Dialog = Snap.UI.Selection.SelectObject(cue)

        dialog.SetFilter(NX.ObjectTypes.Type.Point)

        dialog.Title = "Selection Demo"

        dialog.Scope = Snap.UI.Selection.Dialog.SelectionScope.AnyInAssembly

        dialog.IncludeFeatures = False

        Dim result As Snap.UI.Selection.Result = dialog.Show()

        If result.Response <> NXOpen.Selection.Response.Cancel Then

            'result.Object.IsHidden = True
            Dim pnt As Point = result.Object
            Dim pnt3d As Point3d = pnt.Coordinates
            Echo(pnt3d.X & "  " & pnt3d.Y & "  " & pnt3d.Z)

        End If

    End Sub

    Sub Echo(ByVal output As String)

        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module

Re: Selecting something

Pioneer
Pioneer

Thanks for replying, I am sorry I did not give all the information.

 

I did actually change the code to select points, This was a snippet from the tutorial. perhaps I should have explained better;

 

I started my application using the windows snap template. I then later realized I need some user input, that is, I need to get some positions of the screen. So I used the snippet of code in my form. However, when I use the SNAP Block form application the snippet of code from the tutotial works ok. So I need to connect the two together. So what I am trying;  I created a new class in my Snap application and copied and pasted all the code to the new class. Then I call the class.

 

This is when the block form comes up but not active. So the real question is then actually. How to join the Snap block form application the my Snap application project? I am sure it is something simple, but something I dont know yet to do.

 

Thanks for the help. 

Re: Selecting something

Pioneer
Pioneer

Further to my previous reply;

 

I tried your code by pasting it into my vb.net program. The same thing happens. I had to remove the NX.Open stuff because I have Snap:

 

Private Sub BtnSelectPoint_Click(sender As Object, e As EventArgs) Handles BtnSelectPoint.Click

 

Dim cue As String = "Please select a Point"

Dim dialog As Snap.UI.Selection.Dialog = Snap.UI.Selection.SelectObject(cue)

dialog.SetFilter(Snap.NX.ObjectTypes.Type.Point)

dialog.Title = "Selection Demo"

dialog.Scope = Snap.UI.Selection.Dialog.SelectionScope.AnyInAssembly

dialog.IncludeFeatures = False

Dim result As Snap.UI.Selection.Result = dialog.Show()

If result.Response <> NXOpen.Selection.Response.Cancel Then

'Dim p1 = Snap.UI.Input.GetPosition("Specify first point")

'result.Object.IsHidden = True

Dim pnt As Snap.NX.Point = result.Object

' Dim pnt3d As Snap.NX.Point = pnt.X

Echo(pnt.X & " " & pnt.Y & " " & pnt.Z)

End If

 

 

End Sub

Sub Echo(ByVal output As String)

InfoWindow.WriteLine(output)

'theSession.ListingWindow.Open()

'theSession.ListingWindow.WriteLine(output)

'theSession.LogFile.WriteLine(output)

End Sub

 

So same thing happens, the selection form appears but there is no responce.

Re: Selecting something

Pioneer
Pioneer

Not to worry, I foud the problem.

 

It is a setting on the VS Express form. I found the answer in the example documentation.

 

Under Application Settings, select 'An Internal application that can be activated from an NX session (DLL)'and select 'NXOpen.UI API'.
      

 

Cool!!!

Re: Selecting something

Siemens Phenom Siemens Phenom
Siemens Phenom

I'm glad you got it working. But, I'm surprised that it's working, because you seem to be mixing up WinForms and NX Block dialogs.

 

Here is a program that (I think) does what you want:

 

Option Infer On

Public Class MyProgram

   Public Shared Sub Main()

      Dim dialog = Snap.UI.Selection.SelectObject("Please select a Point") 
      dialog.SetFilter(Snap.NX.ObjectTypes.Type.Point)
      dialog.Title = "Selection Demo"
      dialog.Scope = Snap.UI.Selection.Dialog.SelectionScope.AnyInAssembly
      dialog.IncludeFeatures = False
      Dim result = dialog.Show()

      If result.Response <> NXOpen.Selection.Response.Cancel Then
         Dim pnt As Snap.NX.Point = result.Object
         Snap.InfoWindow.WriteLine(pnt.Position)
         Snap.InfoWindow.WriteLine(pnt)
      End If

   End Sub

End Class

 

山田
yamada