Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

This [b]ufs.Obj.DeleteObject(newCsys.Tag)[/b] Cause no error no delete

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
Hi

This statement ufs.Obj.DeleteObject(newCsys.Tag) Cause no error and no delete
can someone helpe.

after I the journal move the Csys to a new WCS location
I want to the delete the traling csys.

Thank you

Code:
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Windows.Forms
 
Module nxj_dynamic_csys_dialog_function
 
 Sub Main (pattern_type() As String)

   showDynamicCsysDialog
   while ContinueOrRepeate() = 2  'Continue=1, Repeat=2 
     showDynamicCsysDialog
   End while

 End Sub 
 
 Sub showDynamicCsysDialog()
 
  Dim s As NXOpen.Session = NXOpen.Session.GetSession()
  'Dim workPart As NXOpen.Part = s.Parts.Work
  Dim ufs As UFSession = UFSession.GetUFSession()
  Dim displayPart As NXOpen.Part = s.Parts.Display
  Dim theUI As UI = UI.GetUI()
 
  Dim markId1 As NXOpen.Session.UndoMarkId
  markId1 = s.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
  
  If IsNothing(displayPart) Then
    'active part required
    Return
  End If
 
  '9 element orientation matrix of specified csys
  'arrays are zero based
  Dim myCsys(8) As Double
 
  '3 element array: origin point of specified csys
  Dim myOrigin(2) As Double
 
  'tag variable used as input/output for the .SpecifyCsys method
  'passing a null tag into the function uses the current WCS as the starting csys
  Dim newCsysTag As Tag = Tag.Null
 
  'variable to hold the user specified coordinate system
  Dim newCsys As CartesianCoordinateSystem
 
  Dim response As Integer
 
  'If you want to know the option the user used to specify the csys, pass in a variable.
  'The initial value of the variable will control the default option shown to the user.
  'After the function returns, this variable will hold the actual option used.
 
  'optional message to user
  'MessageBox.Show("Orient manipulator to the desired location/orientation", _
          '"Specify Coordinate System", MessageBoxButtons.OK, MessageBoxIcon.Information)

  theUI.LockAccess() 
    'if you don't care what option was used to specify the csys, simply pass in an integer
    'that specified the default method to show to the user
    response = ufs.Ui.SpecifyCsys("Specify Desired Orientation", 5, myCsys, myOrigin, newCsysTag) 
  theUI.UnlockAccess()
 
  If response = Selection.Response.Ok Then
    'get CartesianCoordinateSystem object from tag
    newCsys = Utilities.NXObjectManager.Get(newCsysTag)
    displayPart.WCS.SetCoordinateSystem(newCsys)
  Else
    Return
  End If
  [b]ufs.Obj.DeleteObject(newCsys.Tag)[/b] 
  
 End Sub 

  Public Function ContinueOrRepeate() As Integer

    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim titleString As String = "NX Manager Clone Assembly === By Elbaz Haviv"
    Dim resp As Integer
    Dim messages(0) As String
    messages(0) = "Click Repeate to show dynamic Csys again" & vbCrLf & _
                  "Or Click Continue if WCS is set to bottom left corner" & vbCrLf & _
                  "and you are ready to select and mark components" 
    Dim but As UFUi.MessageButtons

    but.button1 = True
    but.label1 = "Continue"
    but.response1 = 1

    but.button2 = True
    but.label2 = "Repeate Dynamic Csys"
    but.response2 = 2
 
    theUfSession.Ui.MessageDialog(titleString, UiMessageDialogType.UiMessageQuestion, _
                                                 messages, messages.Length, False, but, resp)
    Return(resp) 
  End Function

 Public Function GetUnloadOption(ByVal dummy As String) As Integer 
   'Unloads the image when the NX session terminates
   GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination 
 End Function
 
End Module
 
Replies continue below

Recommended for you

The .SetCoordinateSystem creates a coordinate system in the graphics window. If you get this return value from the .SetCoordinateSystem method, the call to .DeleteObject will work as expected.

Code:
If response = Selection.Response.Ok Then
    'get CartesianCoordinateSystem object from tag
    newCsys = Utilities.NXObjectManager.Get(newCsysTag)
    newCsys = displayPart.WCS.SetCoordinateSystem(newCsys)
Else
    Return
End If
ufs.Obj.DeleteObject(newCsys.Tag)

Alternately, you can use the .SetCoordinateSystemCartesianAtCsys method, which does not create a csys object in the graphics window (nothing to delete later).
Code:
If response = Selection.Response.Ok Then
    'get CartesianCoordinateSystem object from tag
    newCsys = Utilities.NXObjectManager.Get(newCsysTag)
    newCsys = displayPart.WCS.SetCoordinateSystemCartesianAtCsys(newCsys)
Else
    Return
End If

Alternate option #2: Instead of calling the .DeleteObject method, you could use the .UpdateManager methods to delete an object. The example below creates a visible undo mark in the NX history. If this is undesirable, you could create the mark as invisible or delete the mark after it is no longer needed.
Code:
theSession.UpdateManager.ClearErrorList()

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(newCsys)

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)

www.nxjournaling.com
 
Hi CoWski and thank you.

I actually used wcs set origin and matrix
that do not create a csys.

but your solution that not create a csys
is more brief.

Thank you very much.
 
Cowski

how I can save location and display state
of wcs and restore it later.
 
To save the location/orientation, the WCS has a .CoordinateSystem property that you can save to a variable before manipulating the WCS. At the end of your program, you can restore the WCS to the original position/orientation. The WCS also has a .Visibility property that you can get/set to query/control the visibility of the WCS.

www.nxjournaling.com
 
Great. I'm very thank you.
 

Cowski Thank you for your help.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Windows.Forms
 
Module dynamic_csys_dialog_function
 
 Sub Main (pattern_type() As String)
   Dim s As Session = Session.GetSession()
   Dim ufs As UFSession = UFSession.GetUFSession()
   Dim workPart As Part = s.Parts.Work
   Dim displayPart As NXOpen.Part = s.Parts.Display
   Dim originalCsys As CoordinateSystem
   Dim originalVisibility As Boolean

   [b]originalCsys = displayPart.WCS.CoordinateSystem[/b]
   [b]originalVisibility = displayPart.WCS.Visibility[/b]
   displayPart.WCS.Visibility = True
 
   showDynamicCsysDialog

   [b]displayPart.WCS.Visibility = originalVisibility[/b]
   [b]displayPart.WCS.SetCoordinateSystemCartesianAtCsys(originalCsys)[/b]
 End Sub 
 
 Function body_init_proc(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer

   Dim s As Session = Session.GetSession()
   Dim ufs As UFSession = UFSession.GetUFSession()
   Dim num_triples As Integer = 1
   Dim mask_triples(0) As UFUi.Mask
   mask_triples(0).object_type = UFConstants.UF_solid_type
   mask_triples(0).object_subtype = UFConstants.UF_solid_body_subtype
   mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_BODY

   ufs.Ui.SetSelMask(select_, UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
                                                          num_triples, mask_triples)
   Return UFConstants.UF_UI_SEL_SUCCESS

 End Function
 
 Sub showDynamicCsysDialog()
 
  Dim s As NXOpen.Session = NXOpen.Session.GetSession()
  Dim workPart As NXOpen.Part = s.Parts.Work
  Dim ufs As UFSession = UFSession.GetUFSession()
  Dim displayPart As NXOpen.Part = s.Parts.Display
  Dim theUI As UI = UI.GetUI()
 
  Dim markId1 As NXOpen.Session.UndoMarkId
  markId1 = s.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
  
  If IsNothing(displayPart) Then
    'active part required
    Return
  End If
 
  '9 element orientation matrix of specified csys
  'arrays are zero based
  Dim myCsys(8) As Double
 
  '3 element array: origin point of specified csys
  Dim myOrigin(2) As Double
 
  'tag variable used as input/output for the .SpecifyCsys method
  'passing a null tag into the function uses the current WCS as the starting csys
  Dim newCsysTag As Tag = Tag.Null
 
  'variable to hold the user specified coordinate system
  Dim newCsys As CartesianCoordinateSystem
 
  Dim response As Integer
 
  'If you want to know the option the user used to specify the csys, pass in a variable.
  'The initial value of the variable will control the default option shown to the user.
  'After the function returns, this variable will hold the actual option used.
 
  'optional message to user
  'MessageBox.Show("Orient manipulator to the desired location/orientation", _
          '"Specify Coordinate System", MessageBoxButtons.OK, MessageBoxIcon.Information)

  theUI.LockAccess() 
    'if you don't care what option was used to specify the csys, simply pass in an integer
    'that specified the default method to show to the user ---  2 = x-axis,y-axis
    response = ufs.Ui.SpecifyCsys("Specify Desired Orientation", 2, myCsys, myOrigin, newCsysTag) 
  theUI.UnlockAccess()
 
  If response = Selection.Response.Ok Then
    'get CartesianCoordinateSystem object from tag
    [b]newCsys = Utilities.NXObjectManager.Get(newCsysTag)[/b]
    [b]newCsys = displayPart.WCS.SetCoordinateSystemCartesianAtCsys(newCsys)[/b]
  Else
    Return
  End If
  
 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
 
End Module
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor