Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Selecting Point VB 1

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
This is used in UG, I am selecting a point, however if cancel is selected I want to use a default value of x and y. For some reason though I am only getting a value of 0, 0.

Code:
      Try
         response = theUI.SelectionManager.SelectScreenPosition("Select location for LAM Lines to Begin", _
            view, cursor)
         booleanResponse = True
      Catch
         booleanResponse = False
      End Try

      If booleanResponse = true Then
         x = cursor.x
         y = cursor.y
      Else
         x = 170
         y = 450
      End If

My head says this should work, when I select a point it works, so we definitely have a True response, however a false response is NOT working.

Any help is appreciated.
 
Replies continue below

Recommended for you

Found a new way to call for a point location and managed to get the cancel to work properly.
 
Update I got the cancel to work but now the actual click is not working.

Here is the code
Code:
Try
         ufS.Ui.SpecifyScreenPosition("Select location for LAM Lines to Begin", Nothing, IntPtr.Zero, _
            origin, view2, response)
         If response = UFConstants.UF_UI_PICK_RESPONSE Then
            booleanResponse = True
         End If
      Finally
         ' Restore UI state always including in case of error.
         ufS.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
      End Try

      If booleanResponse = true Then
         x = cursor.x
         y = cursor.y
      Else
         x = 170
         y = 450
      End If

When the user selects a point on the sheet I want the program to set x and y to those coordinates, otherwise I want them to use the default values.

I get no error when the command is run, cancel works fine, but when a point is clicked x and y are both set to 0.

Thanks in advance for any help.
 
Check out the sister site to this one - Tek-Tips.com. The computer nerds live and die over there!!!
 
Perhaps SelectScreenPosition will give you what you need?

Here is a small example from GTAC:
Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module select_screen_position

  Dim s As Session = Session.GetSession()
  Dim ufs As UFSession = UFSession.GetUFSession()
  Dim theUI As UI = UI.GetUI()

Sub Main()
Try
    Dim old_cursor_view As Integer
    Dim new_cursor_view As Integer = 0 'ANY view
    Dim screen_pos As Point3d

    ufs.Ui.AskCursorView(old_cursor_view) ' get original setting
    ufs.Ui.SetCursorView(new_cursor_view)

    While select_screen_pos(screen_pos) = Selection.Response.Ok
        s.ListingWindow.Open()
        s.ListingWindow.WriteLine("Position: X: " & screen_pos.X.ToString & _
                                          "  Y: " & screen_pos.Y.ToString & _
                                          "  Z: " & screen_pos.Z.ToString)
    End While

    ufs.Ui.SetCursorView(old_cursor_view) 'reset to original

Catch ex As Exception
    s.ListingWindow.Open()
        s.ListingWindow.WriteLine("ERROR: " & ex.ToString)
End Try

End Sub

Function select_screen_pos(ByRef loc As Point3d) As Selection.Response

    Dim resp As Selection.DialogResponse = Selection.DialogResponse.None
    Dim localView As View

    resp = theUI.SelectionManager.SelectScreenPosition("Screen Position:", _
                                                         localView, loc)
    If resp <> Selection.DialogResponse.Back And _
       resp <> Selection.DialogResponse.Cancel Then
        Return Selection.Response.Ok
    Else
        Return Selection.Response.Cancel
    End If

End Function
  Public Function GetUnloadOption(ByVal dummy As String) As Integer

      GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY

  End Function

End Module

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor