Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Transfer data between journals

Status
Not open for further replies.

MANox

Mechanical
Joined
Apr 2, 2007
Messages
130
Location
PL
Hey,

I have one problem:
I wrote journal for identifying data (curves and bodies) and calculated results.
I must use that journal several time and every time I must selected these same curves and bodies. (f.ex. I change only one dimension.)

Is it possibility divide my journal into two parts?
One for identifying curves and bodies and second for calculated results.

How can I pass data from one to the other journal?


Best regards

Michał Nowak
 
If by "two parts" you mean two separate files, I am not sure journaling can do that - I fear not.
Better code directly thru MS Visual Studio and create your own external .dll functions you'd be able to call when needed in any of your main program.
 
For passing the data to another journal I think you can save the data to a simple text file
Then retrieve that data in the text file from the other journal
 
Thanks for your answer.
I think write to file that's good idea.

Best regards

Michał Nowak
 
Interesting question; I was curious how that might work so I started playing around with some code yesterday. Here is a bare-bones example I came up with (this version works with point, curve, and body objects).

Use this code to save the selection (press the cancel button when you are done selecting objects).

Code:
Option Strict Off
Imports System
Imports NXOpen

Module save_selection

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim mySelectedObject As NXObject

        lw.Open()

        Dim myDocs As String
        myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        Dim outputFile As String = IO.Path.Combine(myDocs, "selection.log")
        If IO.File.Exists(outputFile) Then
            Try
                IO.File.Delete(outputFile)
            Catch ex As Exception
                lw.WriteLine("error deleting file: " & outputFile)
                Return
            End Try
        End If

        Do Until SelectAnObject("Select object", _
                               mySelectedObject) = Selection.Response.Cancel
            lw.WriteLine("Object journal identifier: " & mySelectedObject.JournalIdentifier)
            lw.WriteLine("Object Tag: " & mySelectedObject.Tag)
            lw.WriteLine("Object Type: " & mySelectedObject.GetType.ToString)
            lw.WriteLine("")


            'pass False to overwrite existing file, True to append existing file
            'if file does not exist, a new file will be created and the True/False value will be ignored
            Using myWriter As New IO.StreamWriter(outputFile, True)

                myWriter.WriteLine(mySelectedObject.GetType.ToString)
                myWriter.WriteLine(mySelectedObject.JournalIdentifier)

            End Using

        Loop

        lw.Close()

    End Sub

    Function SelectAnObject(prompt As String, _
               ByRef selObj As NXObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim cursor As Point3d
        Dim typeArray() As Selection.SelectionType = _
            {Selection.SelectionType.All}

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject( _
                prompt, "Selection", _
                Selection.SelectionScope.AnyInAssembly, _
                False, typeArray, selObj, cursor)

        If resp = Selection.Response.ObjectSelected Or _
                resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

End Module

Then run this code to retrieve the saved selection. This code simply writes out the object's type, color, and layer to the information window to show that you have a reference to the previously chosen object.

Code:
Option Strict Off
Imports System
Imports NXOpen

Module retrieve_selection

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow

        lw.Open()

        Dim myDocs As String
        myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        Dim inputFile As String = IO.Path.Combine(myDocs, "selection.log")

        If Not IO.File.Exists(inputFile) Then
            lw.WriteLine("file not found: " & inputFile)
            Return
        End If

        Dim objType As String
        Dim identifier As String

        Using myReader As New IO.StreamReader(inputFile)
            Try
                objType = myReader.ReadLine
                identifier = myReader.ReadLine()
                While Not identifier Is Nothing

                    Dim found As Boolean = False
                    Dim theObject As DisplayableObject = Nothing
                    lw.WriteLine("name: " & identifier)
                    lw.WriteLine("type: " & objType)

                    If objType.ToLower.Contains("point") Then

                        theObject = workPart.Points.FindObject(identifier)
                        found = True
                    ElseIf objType.ToLower.Contains("line") Or _
                        objType.ToLower.Contains("arc") Or _
                        objType.ToLower.Contains("spline") Then

                        theObject = workPart.FindObject(identifier)
                        found = True

                    ElseIf objType.ToLower.Contains("body") Then

                        theObject = workPart.Bodies.FindObject(identifier)
                        found = True

                    Else
                        lw.WriteLine("object type not currently supported, add it")
                        lw.WriteLine("")

                    End If

                    If found Then
                        Try
                            'theObject = CType(workPart.FindObject(identifier), DisplayableObject)
                            lw.WriteLine("type: " & theObject.GetType.ToString)
                            lw.WriteLine("color: " & theObject.Color.ToString)
                            lw.WriteLine("layer: " & theObject.Layer.ToString)
                            lw.WriteLine("")

                        Catch ex As Exception
                            lw.WriteLine(ex.Message)
                            lw.WriteLine("")
                        End Try

                    End If

                    objType = myReader.ReadLine
                    identifier = myReader.ReadLine()
                End While
            Catch ex As Exception
                lw.WriteLine(ex.Message)
            End Try
        End Using
        lw.Close()

    End Sub

End Module

www.nxjournaling.com
 
cowski thank for help. You are The Best.
I have another one small question: Is it possible with face (This way - not - I tested it)?
In this moment I can do my journals using body (and select faces in main journal).
I think about write Face.Tag to file. But how find face by tag?
Something like this:

Code:
For each anyface in workPart.faces
if mytag = anyface.tag then
MyArray.Add(anyface)
end if
Next

But when I will work with thousand faces...

Maybe somebody have some easer idea.

Best regards

Michał Nowak
 
Just remember that tags are not persistent. What this means is that if you check the tag of 'body X', close and reopen NX, the tag of 'body X' may be different. Tags are assigned per NX session, they are not permanently assigned to an object. This may or may not be an acceptable method depending on your intended use. If you intend to shut down your computer for the night and pick up where you left off tomorrow, finding the face by the tag; you may be out of luck. However, if you only need to save and retrieve the face during a single NX session, it may work fine.

www.nxjournaling.com
 
What I usually do to accomplish this is to mark the objects with an attribute, then at a later point when the program is run I iterate over the desired object type and select the ones with the attribute marking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top