×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Transfer data between journals

Transfer data between journals

Transfer data between journals

(OP)
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

RE: Transfer data between journals

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.

RE: Transfer data between journals

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

RE: Transfer data between journals

(OP)
Thanks for your answer.
I think write to file that's good idea.

Best regards

Michał Nowak

RE: Transfer data between journals

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

RE: Transfer data between journals

(OP)
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

RE: Transfer data between journals

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

RE: Transfer data between journals

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources