Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Modify a journal that run in native mode. So to be run also in manager Mode.

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
Hi

This journal run OK in native mode. and I want to modify it so its work also in manager mod.
I tried as shown in bolt text but that fail to run.
Please help to make it run in manager.

Thank you in advanced.

Code:
'                                            010919_1654
Option Strict Off
'
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI

Module part_export_with_options

 Dim cnt as Integer = 0

 Sub Main()

   Dim theSession As Session = Session.GetSession()
   Dim theUFSession As UFSession = UFSession.GetUFSession()
   Dim abody() As TaggedObject = Nothing 
   Dim bodyTags As New List(Of Tag)
   Dim options As UFPart.ExportOptions
   Dim dp as Part = Nothing
   Dim wp as Part = Nothing
   Dim newExportParName As String = Nothing
   Dim cnt As Integer = 0
   Dim nowDateTime As String = Nothing
   Dim sfxBnum As Integer
   Dim rand As New Random()
   Dim internal_part_name As String = Nothing

   wp = theSession.Parts.Work
   dp = theSession.Parts.display
   nowDateTime = Format(Now, "_ddMMyy_hhmmss_")
   sfxBnum = rand.Next(1000, 8000)  
   newExportParName = wp.FullPath.Replace(".prt", "_export" & nowDateTime & sfxBnum & ".prt")  ' for native mode
[b]   'newExportParName = "DB/export" & nowDateTime & sfxBnum & "/-")                             ' 1 for manager mode

   'Try
   '  ufs.UGmgr.ConvertNameFromCli(newExportParName, internal_part_name)
   'Catch e As NXException
   '  lw.WriteFullLine("The Import process failed Message = " & e.Message)
   'End Try
   'newExportParName = internal_part_name                                                       ' 2 for manager mode
[/b]
   If SelectBodies("select bodies", abody) = Selection.Response.Cancel Then
     Return
   End If

   For Each temp As TaggedObject In abody
     bodyTags.Add(temp.Tag)
   Next

   With options
     .new_part = True
     .params_mode = UFPart.ExportParamsMode.MaintainParams  ' RemoveParams
     .expression_mode = UFPart.ExportExpMode.CopyExpDeeply  ' CopyExpShallowly
   End With

   theUFSession.Part.ExportWithOptions(newExportParName, _
                                       bodyTags.ToArray.Length, bodyTags.ToArray, options)
 End Sub

 Function SelectBodies(ByVal prompt As String, ByRef selObj() As TaggedObject) As Selection.Response

   Dim theUI As UI = UI.GetUI
   Dim title As String = "Select one or more bodies"
   Dim includeFeatures As Boolean = False
   Dim keepHighlighted As Boolean = False
   Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
   Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
   Dim selectionMask_array(0) As Selection.MaskTriple

   With selectionMask_array(0)
     .Type = UFConstants.UF_solid_type
     .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
   End With

   Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
                                                              title, scope, selAction, _
                            includeFeatures, keepHighlighted, selectionMask_array, selobj)
   If resp = Selection.Response.Ok 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
 
Replies continue below

Recommended for you

I'm not going to try debug your existing program, because I'm probably not the right one to do that, but I did create a program a long time back (NX 5/2010 - forget which Tc we used) that was used to do certain verifications of Managed data.

When I tested the program, however, I ran it in native. The easy way out for me was to add code to automatically detect this, rather than have to modify the program for Test or Production.

The key for Managed is to call out the part name using the CLI format that Tc uses, so it can find the item in the Tc DB by partnumber.

Below is the code that was relevant to this checking section of my VB program.

I see I had note in their that it sometimes failed for me. I have no memory of that, and it may have been due to older NX and Tc, so no idea if that is important for your case or not. You might ignore that to start.

Maybe this has hints to get you started:

----------------

[pre]'
' Get Mode, Managed or Native
'
Try
theUfSession.UF.IsUgmanagerActive(managedMode)
'listingWindow.WriteLine("managedMode : " & managedMode)
Catch ex As Exception
' The Managed detection seems to fail sometimes, maybe a timeout or something
managedMode = True
listingWindow.WriteLine("Could not detect Native/Managed mode, so assuming Managed")
theSession.LogFile.WriteLine("Could not detect Native/Managed mode, so assuming Managed")
End Try

'
' Open Part
'

If managedMode Then

'
' Managed Mode: Build Partname, Open, and Status/Error Check
'

'
' Managed (CLI) format = "@DB@PRE_30492_num@-.001"
'
' Mar. 15, 2010 - Change from original format, with "/" to "@"
' solve prolblem when Part Number contains a "/"
' i.e. original format = "@DB/PRE_30492_num/-.001"
'
partName = String.Concat("@DB@" , _
itemID , _
"@" , _
nxRevID )

listingWindow.WriteLine("processing (managed) : " & partName)

' theSession.Parts.SetNonmasterSeedPartData(partName)
basePart1 = theSession.Parts.OpenBaseDisplay(partName , partLoadStatus1)
openFlag = 1
' listingWindow.WriteLine("NumUnloaded : " & Cstr(partLoadStatus1.NumberUnloadedParts))

If partLoadStatus1.NumberUnloadedParts Then '1 => the part failed to load; 0=>part loaded
listingWindow.WriteLine("Failed to Open Part " & partName)
theSession.LogFile.WriteLine("Failed to Open Part " & partName)

statusFlag = String.Concat("Failure")
statusMsg = String.Concat("Part Open Failure")
openFlag = 0
End If

Else

'
' Native mode: Build Partname, Open, and Status/Error Check
'

'
' Native format = "D:\work5\Verify\Export\PRE_30492_num.prt" (%VERIFY_HOME%="D:\work5\Verify")
' (native parts must be stored in %VERIFY_HOME%\export\)
'
partName = String.Concat(pathVar, _
"\Export\", _
itemID , _
".prt" )

listingWindow.WriteLine("processing (native) : " & partName)

Try
' theSession.Parts.SetNonmasterSeedPartData(partName)
basePart1 = theSession.Parts.OpenBaseDisplay(partName , partLoadStatus1)
openFlag = 1

Catch ex As Exception
listingWindow.WriteLine("Failed to Open Part " & partName)
theSession.LogFile.WriteLine("Failed to Open Part " & partName)
theSession.LogFile.WriteLine("Error: ")
theSession.LogFile.WriteLine(ex.GetBaseException.ToString())

statusFlag = String.Concat("Failure")
statusMsg = String.Concat("Part Open Failure")
openFlag = 0
End Try


End If


Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display[/pre]
 
Hi CADPat and thank you very much.

In my above journal.
I used CLI format (see the first commented
Bolt line)

and I do a test in managed platform.

The issue is the nx UF function:
theUFSession.Part.ExportWithOptions(newExportParName, _
bodyTags.ToArray.Length, bodyTags.ToArray, options)

Do it compatible to managed mode or not.
This is why I tried also the internal file format.

If you're journal do export a part in
Managed mode . I will happily use it.


Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor