Sample NX Open .NET Visual Basic program : transform copy a single selected body
작성자k2ice작성시간08.06.30조회수743 목록 댓글 0Date: 6-JUN-2008
Subject: Sample NX Open .NET Visual Basic program : transform copy a single selected body
Note: GTAC provides programming examples for illustration only, and
assumes that you are familiar with the programming language being
demonstrated and the tools used to create and debug procedures. GTAC
support professionals can help explain the functionality of a particular
procedure, but we will not modify these examples to provide added
functionality or construct procedures to meet your specific needs.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Module transform_copy_a_single_selected_body
Public s As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = s.ListingWindow
Sub Main()
Dim theBody As NXOpen.Tag = NXOpen.Tag.Null
Dim transformationMatrix(15) As Double
Dim objects(0) As NXOpen.Tag
Dim copiedObjects(0) As NXOpen.Tag
Dim count As Integer = 1
Dim move As Integer = 1
Dim copy As Integer = 2
Dim layer As Integer = 0 ' original layer
Dim trace_curves As Integer = 2 ' Off
Dim returnStatus As Integer = -1
Dim translation() As Double = {100, 100, 100}
While select_a_body(theBody) = Selection.Response.Ok
objects(0) = theBody
ufs.Trns.CreateTranslationMatrix(translation, transformationMatrix)
ufs.Trns.TransformObjects(transformationMatrix, objects, _
count, copy, layer, trace_curves, _
copiedObjects, Nothing, returnStatus)
ufs.View.FitView(NXOpen.Tag.Null, 0.9)
lw.Open()
lw.WriteLine("Original Object: " & objects(0).ToString())
lw.WriteLine("Copied Object: " & copiedObjects(0).ToString())
ufs.Disp.SetHighlight(theBody, 0)
If returnStatus > 0 Then
lw.Open()
lw.WriteLine("TransformObjects returned a status code: " & _
returnStatus.ToString())
End If
End While
End Sub
Function select_a_body(ByRef body As NXOpen.Tag) As Selection.Response
Dim message As String = "BODY:"
Dim title As String = "Select a body"
Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_WORK_PART
Dim response As Integer
Dim view As NXOpen.Tag
Dim cursor(2) As Double
Dim ip As UFUi.SelInitFnT = AddressOf mask_for_body
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Try
ufs.Ui.SelectWithSingleDialog(message, title, scope, ip, _
Nothing, response, body, 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_body(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_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
Public Function check_for_missing_display_part() As Integer
Dim dispPart As Part = Nothing
Try
dispPart = s.Parts.Display
Catch ex As Exception
lw.Open()
lw.WriteLine("+++Error: " & ex.ToString())
End Try
If dispPart Is Nothing Then
lw.Open()
lw.WriteLine("There is no current Displayed Part")
ufs.UF.PrintSyslog("+++ERROR: There is no current Displayed Part", _
False)
Return 1
End If
Return 0
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module