Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

vb Journal : Is it possible to Lock all options but one

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
0
0
IL
Hi

Is it possible to Lock all options but one of this command ufs.Ui.SpecifyCsys
say I want that the user will be obligated to use only the option 4 = CSYS of Object
Code:
  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 ---  [b]4 = CSYS of Object[/b]
    response = ufs.Ui.SpecifyCsys("Specify Desired Orientation", [b]4[/b], myCsys, myOrigin, newCsysTag) 
  theUI.UnlockAccess()

Thanks in advanced.
 
Replies continue below

Recommended for you

The .SpecifyCsys method inherently displays all creation options to the user; I don't know of a way to limit those options within the command. If the csys must be based on an existing object, perhaps you could prompt the user to select an object then extract the orientation matrix with .AskMatrixOfObject or something similar. The matrix could then be used to construct a csys.

www.nxjournaling.com
 
Cowski thank you very much.

what I want to do is simulate this function

according to this function with option 4
when I select a planar face and click OK
the x,y axis lay on the face and the
z axis towards the face normal.

I`m very thank you again.

 

I tryied AskMatrixOfObjec
but the z axis not allwais normal to face
for plain plate in one side z go normal to face
but whwen selcting the other side face
the z not go normal to face.

Code:
' NX 11.0.2.7
' Journal created on Mon Jul 09 12:22:12 2018
'
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities

Module NXJournal

 Dim ufs As UFSession = UFSession.GetUFSession()
 Sub Main (ByVal args() As String) 

  Dim s As NXOpen.Session = NXOpen.Session.GetSession()
  Dim workPart As NXOpen.Part = s.Parts.Work
  Dim displayPart As NXOpen.Part = s.Parts.Display

  Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
  markId1 = s.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

  Dim planarFace As NXOpen.Tag = NXOpen.Tag.Null

  If select_a_planar_face(planarFace) = Selection.Response.Ok Then
     ufs.Disp.SetHighlight(planarFace, 0)
  End If

  'Dim face1 As NXOpen.Face = NXObjectManager.Get(planarFace)

  Dim object_id As Tag
  Dim matrix_id As Tag
  Dim matrix_values(8) As Double

  object_id = planarFace
  ufs.Csys.[b]AskMatrixOfObjec[/b]t(object_id, matrix_id)

  ufs.Csys.AskMatrixValues(matrix_id, matrix_values)

  Dim matrix1 As NXOpen.Matrix3x3 = Nothing

  matrix1.Xx = matrix_values(0)
  matrix1.Xy = matrix_values(1)
  matrix1.Xz = matrix_values(2)
  matrix1.Yx = matrix_values(3)
  matrix1.Yy = matrix_values(4)
  matrix1.Yz = matrix_values(5)
  matrix1.Zx = matrix_values(6)
  matrix1.Zy = matrix_values(7)
  matrix1.Zz = matrix_values(8)

  Dim origin5 As NXOpen.Point3d = New NXOpen.Point3d(50.0, 50.0, 0.0)

  workPart.WCS.SetOriginAndMatrix(origin5, matrix1)

 End Sub

   Function select_a_planar_face(ByRef face As NXOpen.Tag) As Selection.Response

      Dim message As String = "Planar Face:"
      Dim title As String = "Select a PLANAR FACE"
      Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
      Dim response As Integer
      Dim view As NXOpen.Tag
      Dim cursor(2) As Double
      Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_planar_faces

      ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

      Try
         ufs.Ui.SelectWithSingleDialog(message, title, scope, mask_face, _
                      Nothing, response, face, cursor, view)
      Finally
         ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
      End Try

      If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
         response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
         Return Selection.Response.Cancel
      Else
         Return Selection.Response.Ok
      End If

   End Function

   Function mask_for_planar_faces(ByVal select_ As IntPtr, _
                          ByVal userdata As IntPtr) As Integer

      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_face_subtype
      mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE

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

   End Function

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

End Module
 
Hi
Tooked me a long time to fish the right statements.
I don't know what mean xform
but the code works.

This is the recorded journal

Code:
' NX 11.0.2.7
' Journal created on Mon Jul 09 12:19:29 2018 Jerusalem Daylight Time
'
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Format->WCS->Orient...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim origin1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal1 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane1 As NXOpen.Plane = Nothing
plane1 = workPart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling)

Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)

Dim expression1 As NXOpen.Expression = Nothing
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression2 As NXOpen.Expression = Nothing
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim origin2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal2 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane2 As NXOpen.Plane = Nothing
plane2 = workPart.Planes.CreatePlane(origin2, normal2, NXOpen.SmartObject.UpdateOption.WithinModeling)

Dim expression3 As NXOpen.Expression = Nothing
expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression4 As NXOpen.Expression = Nothing
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim origin3 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal3 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane3 As NXOpen.Plane = Nothing
plane3 = workPart.Planes.CreatePlane(origin3, normal3, NXOpen.SmartObject.UpdateOption.WithinModeling)

Dim expression5 As NXOpen.Expression = Nothing
expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression6 As NXOpen.Expression = Nothing
expression6 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim origin4 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
Dim normal4 As NXOpen.Vector3d = New NXOpen.Vector3d(0.0, 0.0, 1.0)
Dim plane4 As NXOpen.Plane = Nothing
plane4 = workPart.Planes.CreatePlane(origin4, normal4, NXOpen.SmartObject.UpdateOption.WithinModeling)

Dim expression7 As NXOpen.Expression = Nothing
expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression8 As NXOpen.Expression = Nothing
expression8 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression9 As NXOpen.Expression = Nothing
expression9 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

Dim expression10 As NXOpen.Expression = Nothing
expression10 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

Dim expression11 As NXOpen.Expression = Nothing
expression11 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression12 As NXOpen.Expression = Nothing
expression12 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

Dim expression13 As NXOpen.Expression = Nothing
expression13 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression14 As NXOpen.Expression = Nothing
expression14 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2)

expression9.RightHandSide = "0"

expression11.RightHandSide = "0"

expression13.RightHandSide = "0"

expression10.RightHandSide = "0"

expression12.RightHandSide = "0"

expression14.RightHandSide = "0"

expression9.RightHandSide = "0"

expression11.RightHandSide = "0"

expression13.RightHandSide = "0"

expression10.RightHandSide = "0"

expression12.RightHandSide = "0"

expression14.RightHandSide = "0"

expression9.RightHandSide = "0"

expression11.RightHandSide = "0"

expression13.RightHandSide = "0"

expression10.RightHandSide = "0"

expression12.RightHandSide = "0"

expression14.RightHandSide = "0"

theSession.SetUndoMarkName(markId1, "CSYS Dialog")

Dim extrude1 As NXOpen.Features.Extrude = CType(workPart.Features.FindObject("EXTRUDE(1)"), NXOpen.Features.Extrude)

Dim face1 As NXOpen.Face = CType(extrude1.FindObject("FACE 120 {(141.0229166666667,101.7984375,0) EXTRUDE(1)}"), NXOpen.Face)

Dim xform1 As NXOpen.Xform = Nothing
xform1 = workPart.Xforms.CreateXform(face1, NXOpen.SmartObject.UpdateOption.AfterModeling)

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "CSYS")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "CSYS")

Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem = Nothing
cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, NXOpen.SmartObject.UpdateOption.AfterModeling)

xform1.RemoveParameters()

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "CSYS")

workPart.Expressions.Delete(expression9)

workPart.Expressions.Delete(expression11)

workPart.Expressions.Delete(expression13)

workPart.Expressions.Delete(expression10)

workPart.Expressions.Delete(expression12)

workPart.Expressions.Delete(expression14)

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression2)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression4)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression6)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression8)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression1)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

plane1.DestroyPlane()

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression3)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

plane2.DestroyPlane()

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression5)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

plane3.DestroyPlane()

Try
  ' Expression is still in use.
  workPart.Expressions.Delete(expression7)
Catch ex As NXException
  ex.AssertErrorCode(1050029)
End Try

plane4.DestroyPlane()

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.AddToDeleteList(cartesianCoordinateSystem1)

Dim objects1(0) As NXOpen.NXObject
Dim cartesianCoordinateSystem2 As NXOpen.CartesianCoordinateSystem = CType(workPart.FindObject("ENTITY 45 1"), NXOpen.CartesianCoordinateSystem)

objects1(0) = cartesianCoordinateSystem2
Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.AddToDeleteList(objects1)

Dim origin5 As NXOpen.Point3d = New NXOpen.Point3d(141.0229166666667, 101.79843749999995, 0.0)
Dim matrix1 As NXOpen.Matrix3x3 = Nothing
matrix1.Xx = 1.0
matrix1.Xy = 0.0
matrix1.Xz = 0.0
matrix1.Yx = 0.0
matrix1.Yy = 1.0
matrix1.Yz = 0.0
matrix1.Zx = 0.0
matrix1.Zy = 0.0
matrix1.Zz = 1.0
workPart.WCS.SetOriginAndMatrix(origin5, matrix1)

Dim id1 As NXOpen.Session.UndoMarkId = Nothing
id1 = theSession.NewestVisibleUndoMark

Dim nErrs3 As Integer = Nothing
nErrs3 = theSession.UpdateManager.DoUpdate(id1)

' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

And this is the fishery code.

Code:
' NX 11.0.2.7
' Journal created on Mon Jul 09
'
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities

Module menu_format_wcs_orient

 Dim ufs As UFSession = UFSession.GetUFSession()
 Sub Main (ByVal args() As String) 

   Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
   Dim workPart As NXOpen.Part = theSession.Parts.Work
   Dim displayPart As NXOpen.Part = theSession.Parts.Display
   Dim planarFace As NXOpen.Tag = NXOpen.Tag.Null
   Dim xform1 As NXOpen.Xform = Nothing
   Dim face1 As NXOpen.Face
   Dim xform1_csys As NXOpen.CartesianCoordinateSystem = Nothing

   Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
   markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

   If select_a_planar_face(planarFace) = Selection.Response.Ok Then
     ufs.Disp.SetHighlight(planarFace, 0)
   Else
     Return
   End If
   face1 = NXObjectManager.Get(planarFace)

   xform1 = workPart.Xforms.CreateXform(face1, NXOpen.SmartObject.UpdateOption.AfterModeling)
   xform1_csys = workPart.CoordinateSystems.CreateCoordinateSystem(xform1, _
                                              NXOpen.SmartObject.UpdateOption.AfterModeling)
   xform1.RemoveParameters()
   displayPart.WCS.SetCoordinateSystemCartesianAtCsys(xform1_csys)

 End Sub

   Function select_a_planar_face(ByRef face As NXOpen.Tag) As Selection.Response

      Dim message As String = "Planar Face:"
      Dim title As String = "Select a PLANAR FACE"
      Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
      Dim response As Integer
      Dim view As NXOpen.Tag
      Dim cursor(2) As Double
      Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_planar_faces

      ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)

      Try
         ufs.Ui.SelectWithSingleDialog(message, title, scope, mask_face, _
                      Nothing, response, face, cursor, view)
      Finally
         ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
      End Try

      If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
         response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
         Return Selection.Response.Cancel
      Else
         Return Selection.Response.Ok
      End If

   End Function

   Function mask_for_planar_faces(ByVal select_ As IntPtr, _
                          ByVal userdata As IntPtr) As Integer

      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_face_subtype
      mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_PLANAR_FACE

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

   End Function

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

End Module
 
Status
Not open for further replies.
Back
Top