Option Strict Off Imports NXOpen Imports NXOpen.UF Imports NXOpen.Assemblies Imports System Module Create_Component Dim theSession As Session = Session.GetSession() Dim ufsSession As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Dim strWorkPart As String = workpart.Leaf Dim objects() As NXOpen.Tag Dim inx As Integer = 0 Sub Main 'Test ob Part geladen if theSession.Parts.Work is Nothing Then Windows.Forms.MessageBox.Show("Kein Part geladen!") Exit Sub End If Dim parent_part As Tag = theSession.Parts.Work.Tag Dim Partname, refset_name, instance_name As String Dim origin As Double() = {0, 0, 0} Dim csys_matrix As Double() = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0} Dim n_objects, Layer As Integer Dim instance As NXOpen.Tag Dim units As Integer = 1 Dim PartnamePrompt As String = "Bitte Partnamen eingeben" Dim PartnameCaption As String = "Bitte Partnamen eingeben" Dim PartnameInitialText As String = "new_Component" Dim PartnameNXInputBox As NXOpenUI.NxInputBox = New NXOpenUI.NXInputBox() Dim PartFilter As String = "C:\Temp\*.prt" Dim PartFilename As String Dim PartResponse As Integer Dim LayerPrompt As String = "Orig.Layer = -1 | Work Layer = 0 | Spec.Layer = 0-255" Dim LayerCaption As String = "Auf welchen Layer?" Dim LayerInitialNumber As String = "-1" Dim LayerNXInputBox As NXOpenUI.NxInputBox = New NXOpenUI.NXInputBox() Dim LayerIFormatProvider As IFormatProvider Dim LayerResponse As Integer 'Partnamen erfragen ufsSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Try ufsSession.Ui.CreateFilebox(PartnamePrompt, PartnameCaption, PartFilter, PartnameInitialText, PartFilename, PartResponse) ufsSession.Abort.DisableAbort() Finally ufsSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) End Try If Not PartResponse = 2 Then Exit Sub End If 'Layer-Nummer erfragen ufsSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Try Layer = LayerNXInputBox.GetInputNumber(LayerPrompt, LayerCaption, LayerInitialNumber) ufsSession.Abort.DisableAbort() Finally ufsSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) End Try 'Solids fuer Component auswahlen While selBodies(objects) = Selection.Response.Ok End While Dim i As Integer For i = 0 To inx - 1 ufsSession.Disp.SetHighlight(objects(i), 0) Next i n_objects = objects.Length 'Component erzeugen ufsSession.Assem.CreateComponentPart(parent_part, PartFilename, refset_name, instance_name, units, Layer, origin, csys_matrix, n_objects, objects, instance) 'Neues Component zum Displayed Part machen Dim ComponentPart As Part = CType(theSession.Parts.FindObject(PartFilename), Part) Dim partLoadStatus1 As PartLoadStatus Dim partCollection_SdpsStatus1 As PartCollection.SdpsStatus partCollection_SdpsStatus1 = theSession.Parts.SetDisplay(ComponentPart, True, True, partLoadStatus1) partLoadStatus1.Dispose() 'Neues Component speichern Dim partSaveStatus1 As PartSaveStatus ComponentPart.Save(Part.SaveComponents.False, Part.CloseAfterSave.False, partSaveStatus1) partSaveStatus1.Dispose() 'Find old workpart in session Dim oldWorkPart As Part = CType(theSession.Parts.FindObject(strWorkPart), Part) Dim partLoadStatus2 As PartLoadStatus Dim partCollection_SdpsStatus2 As PartCollection.SdpsStatus partCollection_SdpsStatus2 = theSession.Parts.SetDisplay(oldWorkPart, True, True, partLoadStatus2) theSession.Parts.SetWork(oldWorkPart) partLoadStatus2.Dispose() End Sub Function selBodies(ByRef body() As NXOpen.Tag) As Selection.Response Dim message As String Dim title As String = "Select a body" Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY Dim response As Integer Dim view As NXOpen.Tag Dim ip As UFUi.SelInitFnT = AddressOf mask_for_body ufsSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM) Try ufsSession.Ui.SelectWithClassDialog(message, title, scope, ip, Nothing, response, inx, objects) Finally ufsSession.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 ufsSession.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 GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY End Function End Module