Showing results for 
Search instead for 
Do you mean 
Reply

Create JT from Journal.vb

Hi, 

 

Is possible to create JT from parts to Teamcenter by programing journal.vb in NX??

 

I have found information for create JT but outside Teamcenter (NXOpen.JtCreator()).

 

Thanks for all.

 

 

 

2 REPLIES

Re: Create JT from Journal.vb

Hi,

I can only this (in NX11.0.0.33): create a JT file and upload it into the UGMASTER dataset.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.PDM

Module Module1

    '  Explicit Activation
    '      This entry point is used to activate the application explicitly
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim workPart As NXOpen.Part = theSession.Parts.Work

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

        Dim export_folder As String = Nothing

        Dim managerActive As Boolean

        theUfSession.UF.IsUgmanagerActive(managerActive)

        If managerActive = True Then
            theUfSession.Ugmgr.AskExportDirectory(theSession.Parts.BaseWork.Tag, export_folder)
            lw.WriteFullline("Export Directry: " & export_folder.ToString)

            Dim partName As String = ""
            theUfSession.Part.AskPartName(theSession.Parts.Display.Tag, partName)

            Dim partNumber As String = ""
            Dim partRevision As String = ""
            Dim partFileType As String = ""
            Dim partFileName As String = ""

            theUfSession.Ugmgr.DecodePartFileName(partName, partNumber, partRevision, partFileType, partFileName)

            lw.WriteLine("Part Number " & partNumber)
            lw.WriteLine("Part Revision " & partRevision)
            lw.WriteLine("Part File Type " & partFileType)
            lw.WriteLine("Part File Name " & partFileName)

            ' ----------------------------------------------
            '   Menu: File->Export->JT...
            ' ----------------------------------------------
            Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
            markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

            Dim jtCreator1 As NXOpen.JtCreator = Nothing
            jtCreator1 = theSession.PvtransManager.CreateJtCreator()

            jtCreator1.IncludePmi = NXOpen.JtCreator.PmiOption.PartAndAsm

            jtCreator1.TessOption = NXOpen.JtCreator.TessellationOption.Defined

            jtCreator1.LighweightLabel = "JT_Facet"

            'jtCreator1.ConfigFile = "C:\Siemens\NX11\pvtrans\tessUG.config"
            jtCreator1.ConfigFile = theSession.GetEnvironmentVariableValue("UGII_BASE_DIR") + "\pvtrans\tessUG.config"

            'JT translate in one file
            jtCreator1.JtfileStructure = NXOpen.JtCreator.FileStructure.Monolithic

            jtCreator1.AutolowLod = True

            jtCreator1.TessOption = NXOpen.JtCreator.TessellationOption.Nx

            jtCreator1.PreciseGeom = True

            theSession.SetUndoMarkName(markId1, "Export JT Dialog")

            Dim listCreator1 As NXOpen.ListCreator = Nothing
            listCreator1 = jtCreator1.NewLevel()

            listCreator1.TessOption = NXOpen.ListCreator.TessellationOption.Defined

            listCreator1.Chordal = 0.001

            listCreator1.Angular = 20.0

            jtCreator1.LodList.Append(listCreator1)

            Dim listCreator2 As NXOpen.ListCreator = Nothing
            listCreator2 = jtCreator1.NewLevel()

            listCreator2.TessOption = NXOpen.ListCreator.TessellationOption.Defined

            listCreator2.Chordal = 0.001

            listCreator2.Angular = 20.0

            jtCreator1.LodList.Append(listCreator2)

            Dim listCreator3 As NXOpen.ListCreator = Nothing
            listCreator3 = jtCreator1.NewLevel()

            listCreator3.TessOption = NXOpen.ListCreator.TessellationOption.Defined

            listCreator3.Chordal = 0.001

            listCreator3.Angular = 20.0

            jtCreator1.LodList.Append(listCreator3)

            listCreator2.Chordal = 0.0035

            listCreator2.Angular = 0.0

            listCreator2.Simplify = 0.4

            listCreator2.AdvCompression = 0.5

            listCreator3.Chordal = 0.01

            listCreator3.Angular = 0.0

            listCreator3.Simplify = 0.1

            listCreator3.AdvCompression = 1.0

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

            theSession.DeleteUndoMark(markId2, Nothing)

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

            'jtCreator1.OutputJtFile = "C:\Users\Administrator\AppData\Local\Temp\027493__A____1\.jt"

            Dim nXObject1 As NXOpen.NXObject = Nothing
            Try
                ' Invalid file name
                nXObject1 = jtCreator1.Commit()
            Catch ex As NXException
                ex.AssertErrorCode(640005)
            End Try

            theSession.UndoToMarkWithStatus(markId3, Nothing)

            theSession.DeleteUndoMark(markId3, Nothing)

            Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
            markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export JT")

            theSession.DeleteUndoMark(markId4, Nothing)

            Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
            markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export JT")

            theSession.DeleteUndoMark(markId5, Nothing)

            Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
            markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Export JT")

            jtCreator1.OutputJtFile = export_folder.ToString + "\" + partNumber.ToString + "_" + partRevision.ToString + ".jt"

            Dim nXObject2 As NXOpen.NXObject = Nothing
            nXObject2 = jtCreator1.Commit()

            theSession.DeleteUndoMark(markId6, Nothing)

            theSession.SetUndoMarkName(markId1, "Export JT")

            'jtCreator1.Destroy()

            Dim thePDMSession As NXOpen.PDM.PdmSession = theSession.PdmSession()

            Dim fm As NXOpen.PDM.FileManagement = thePDMSession.NewFileManagement

            Dim itemids() As String = {Nothing}
            Dim itemrevisionids() As String = {Nothing}
            Dim datasetnames() As String = {Nothing}
            Dim datasettypenames() As String = {Nothing}
            Dim datasetrelationtypenames() As String = {Nothing}
            Dim datasettoolnames() As String = {Nothing}
            Dim filetype() As Boolean = {Nothing}
            Dim namedreferencednames() As String = {Nothing}
            Dim importfilenames() As String = {Nothing}
            Dim importdirectorynames() As String = {Nothing}

            itemids(0) = partNumber
            itemrevisionids(0) = partRevision
            datasetnames(0) = partNumber.ToString + "-" + partRevision.ToString
            datasettypenames(0) = "UGMASTER"
            datasetrelationtypenames(0) = "has shape"
            'datasettoolnames(0) = ""
            'filetype(0) = True
            'namedreferencednames(0) = ""
            'importfilenames(0) = jtCreator1.OutputJtFile.ToString
            importdirectorynames(0) = export_folder
            lw.WriteFullline("JT: " & jtCreator1.OutputJtFile.ToString)

            'NX 11.0.2 create dataset
            'fm.ImportFilesAndCreateDatasets(itemids, itemrevisionids, datasetnames, datasetrelationtypenames, datasetrelationtypenames, datasettoolnames, filetype, namedreferencednames, importfilenames, importdirectorynames)
            fm.ImportFiles(itemids, itemrevisionids, datasetnames, datasettypenames, datasetrelationtypenames, importdirectorynames)

            jtCreator1.Destroy()

        End If

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

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

Modify the TC preference to see this JT in the Viewer tab:

TC PrefTC Pref

The demo video:

(view in My Videos)

Attila Szepesi, Application Engineer, graphIT Ltd.
Production: NX11.0.2 | TcUA 11.2 MP2 Patch 1 (11.2.2.1)
Development: VB.NET Testing: NX12.0

Re: Create JT from Journal.vb

Hi @ManuSendon,

File > Save > Save Options > Save JT Data.

Is there any particular requirement to create JT using VB journal?

Testing NX10 | NX11
Teamcenter 11.2 | TC Vis 11.3 | Active Workspace 3.2