Showing results for 
Search instead for 
Do you mean 
Reply

Move, export, repeat

We have an assembly, and by using expressions, we can move components to varioius positions.  How complicated would it be, and what language would you use, to cycle this assembly thru 6 positions, and after each new position, export certain components out as parasolids?

 

Also, would it be possible to do this from outside NX?

 

NX 9, and all files are in Teamcenter.

-Dave
NX 11 | Teamcenter 11 | Windows 8.1
8 REPLIES

Re: Move, export, repeat

Sounds like a good job for a journal. Any language supported by journaling could be used.

 

Can it be done outside of NX? Depends on what you consider to be "outside of NX". You might be able to use the "run_journal" utility to execute the code without brining up a visible NX session; but it would still need to use the necessary NX licenses to do its job. I don't know of a way to update expressions and component positions without getting NX involved in some way.

Re: Move, export, repeat

At the core of your program, you will need to use either UF_PS_export_data() or UF_PS_export_linked_data().  These are both provided originally in Open C - traditional user function - but they have also been wrapped for use in all of the NXOpen Common API kits.  So as cowski pointed out, you could in fact do it in a journal.

 

You can create an "external program" from NXOpen code, which on Windows is an executable file (.exe) that you can run from the command line.  You can perform most NX actions in this type of program, as long as they don't require user interaction, and it all happens without ever launching an interactive NX session.

 

If your goal is to export the Parasolid bodies from different positions in space, as you move things around in the assembly, then you will need to be sure you are using the occurrence bodies in the top-level of the assembly, so that all that transformation data is taken into account, rather than the prototype bodies in the original components.

 

You can process parts that are managed in Teamcenter from an external program, but of course it adds a layer of complexity, because your program has to access the database.  It does this "behind the scenes", so to speak, so neither the NX interface or the TC interface is ever displayed.

Re: Move, export, repeat

By "outside of NX", I meant without running an explicit NX session.  Design can make changes, and tell the simulation group we're done, and they just run the script to get the new stuff.  That isn't a big requirement, they are familiar with NX enough, that they could open a session, and run the Journal.

 

Now, to see who can write the journal

 

Thanks!

-Dave
NX 11 | Teamcenter 11 | Windows 8.1

Re: Move, export, repeat

Here is a journal developed quite some time ago.  This case used three expression values read from a text file.  The text file name with an index number is used the output file.

If I remember correctly when I created this it was for NX5 and the user had a compiled program.  I have not checked this as a journal.

Let us know if you need more info to make any changes.

 

' Program description:	Program to output Parasolid files for configurations defined in a text file
' Created by:			Frank Swinkels, fsw13678@bigpond.net.au

' I provide programming code examples from which you can generate similar function tailored to your
' own specific needs.  The code is provided for illustrative purposes only. The example has not been
' thoroughly tested under all conditions. I therefore, cannot guarantee or imply reliability,
' serviceability, or function of the program.  The code contained herein is provided to you "AS IS" 
' without any warranties of any kind. The implied warranties of fitness for a particular purpose is
' expressly disclaimed.

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Layer
Imports System.Windows.Forms

Module RedBullTest1
    Sub Main()
        Dim s As Session = Session.GetSession()
        Dim ui As UI = ui.GetUI()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim displayPart As Part = s.Parts.Display
        Dim workPart As Part = s.Parts.Work
        Dim root As Component = s.Parts.Work.ComponentAssembly.RootComponent
        Dim result As DialogResult
        Dim filename As String = Nothing
        Dim psfilename As String = Nothing
        Dim psfilename2 As String = Nothing
        Dim filecollection As ArrayList = New ArrayList
        Dim linestring As String = Nothing
        Dim linestring2 As String = Nothing
        Dim index1 As Integer = 0
        Dim index2 As Integer = 0
        Dim index3 As Integer = 0
        Dim counter As Integer = 0
        Dim count1 As Integer = Nothing
        Dim count2 As Integer = 0
        Dim number1string As String
        Dim number2string As String
        Dim number3string As String
        Dim exp1 As Expression = Nothing
        Dim exp2 As Expression = Nothing
        Dim exp3 As Expression = Nothing
        Dim isBlankedStatus As Boolean
        Dim isSuppressedStatus As Boolean
        Dim layerStatus As Integer
        Dim c_part As Part = Nothing
        Dim solid_bodies(-1) As Tag
        Dim partTag As Tag
        Dim errorstate As UFPart.LoadStatus = Nothing
        Dim compPartName As String = Nothing
        Dim compRefsetName As String = Nothing
        Dim instanceName As String = Nothing
        Dim compOrigin() As Double = {0.0, 0.0, 0.0}
        Dim csysMatrix() As Double = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}
        Dim transform(,) As Double = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
        Dim markId1 As String = Nothing
        Dim nErrs1 As Integer = Nothing
        Dim ofd As OpenFileDialog = New OpenFileDialog()
        Dim member As Tag = Tag.Null
        Dim type As Integer = 0
        Dim subType As Integer = 0
        Dim testArray() As String

        ' Set undo
        s.SetUndoMark(Session.MarkVisibility.Visible, markId1)

        ' Select a text file using the Open File Dialog
        ofd.Title = "Select Data Text File"
        ofd.AddExtension = True
        ofd.DefaultExt = "txt"
        ofd.RestoreDirectory = True
        ofd.Filter = "Text files (*.txt)|*.txt"
        result = ofd.ShowDialog()
        filename = ofd.FileName
        ofd.Dispose()

        ' set up name string for ps files
        count1 = Len(filename)
        psfilename = filename.Substring(0, count1 - 4)

        ' Check all components
        ' Ignore component if on invisible layer
        ' Ignore component if  blanked
        ' Ignore component if suppressed
        ' Then test if component is partially loaded.  If so load it.
        ' Now get the solid bodies in each component and add them to an array
        counter = 0
        For Each child As Component In root.GetChildren()
            isBlankedStatus = child.IsBlanked
            isSuppressedStatus = child.IsSuppressed
            ufs.Layer.AskStatus(child.Layer, layerStatus)
            If isBlankedStatus = False And isSuppressedStatus = False _
                And layerStatus <> 4 Then
                ufs.Assem.AskComponentData(child.Tag, compPartName, compRefsetName, instanceName, _
                  compOrigin, csysMatrix, transform)
                partTag = ufs.Part.AskPartTag(compPartName)
                If ((ufs.Part.IsLoaded(compPartName)) <> 1) Then
                    ufs.Part.OpenQuiet(compPartName, partTag, errorstate)
                End If
                member = Tag.Null
start1:
                ufs.Assem.CycleObjsInComp(child.Tag, member)
                If member = Tag.Null Then GoTo end1
                ufs.Obj.AskTypeAndSubtype(member, type, subType)
                If type = 70 And subType = 0 Then
                    ReDim Preserve solid_bodies(counter)
                    solid_bodies(counter) = member
                    counter += 1
                End If
                GoTo start1
end1:
            End If
        Next
        ' Read data from the selected text file
        ' Set the expressions
        ' Export the solid bodies to ps file.
        Dim sr As StreamReader = File.OpenText(filename)
        Try
            Do While sr.Peek >= 0
                linestring = sr.ReadLine
                '      MsgBox("Line of text : " & linestring.ToString)
                index1 = Len(linestring)
                '    MsgBox(" length of string : " & index1.ToString)
                If index1 = 0 Then GoTo loop1
                If Asc(linestring(0)) > 47 And Asc(linestring(0)) < 58 Then
                    testArray = Split(linestring, vbTab, 3)
                    number1string = testArray(0)
                    number2string = testArray(1)
                    number3string = testArray(2)
                    exp1 = workPart.Expressions.FindObject("Height_1")
                    exp1.RightHandSide = number1string
                    exp2 = workPart.Expressions.FindObject("Height_2")
                    exp2.RightHandSide = number2string
                    exp3 = workPart.Expressions.FindObject("Height_3")
                    exp3.RightHandSide = number3string
                    nErrs1 = s.UpdateManager.DoUpdate(markId1)
                    count2 += 1
                    ' Now save the solid bodies to parasolid file
                    If count2 < 10 Then
                        psfilename2 = psfilename & "_00" & count2.ToString
                    ElseIf count2 > 9 And count2 < 100 Then
                        psfilename2 = psfilename & "_0" & count2.ToString
                    Else
                        psfilename2 = psfilename & "_" & count2.ToString
                    End If
                    ufs.Ps.ExportData(solid_bodies, psfilename2)
                End If
loop1:
            Loop
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        sr.Close()
    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

        
    End Function

End Module

 

Regards

 

Frank Swinkels

Re: Move, export, repeat

Here is a journal that worked for three expressions.  It reads the values from a text file and the text file name with index numbers is used. 

 

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Layer
Imports System.Windows.Forms
imports System.Collections

Module RedBullTest1
    Sub Main()
        Dim s As Session = Session.GetSession()
        Dim ui As UI = ui.GetUI()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim displayPart As Part = s.Parts.Display
        Dim workPart As Part = s.Parts.Work
        Dim root As Component = s.Parts.Work.ComponentAssembly.RootComponent
        Dim result As DialogResult
        Dim filename As String = Nothing
        Dim psfilename As String = Nothing
        Dim psfilename2 As String = Nothing
        Dim filecollection As ArrayList = New ArrayList
        Dim linestring As String = Nothing
        Dim linestring2 As String = Nothing
        Dim index1 As Integer = 0
        Dim index2 As Integer = 0
        Dim index3 As Integer = 0
        Dim counter As Integer = 0
        Dim count1 As Integer = Nothing
        Dim count2 As Integer = 0
        Dim number1string As String
        Dim number2string As String
        Dim number3string As String
        Dim exp1 As Expression = Nothing
        Dim exp2 As Expression = Nothing
        Dim exp3 As Expression = Nothing
        Dim isBlankedStatus As Boolean
        Dim isSuppressedStatus As Boolean
        Dim layerStatus As Integer
        Dim c_part As Part = Nothing
        Dim solid_bodies(-1) As Tag
        Dim partTag As Tag
        Dim errorstate As UFPart.LoadStatus = Nothing
        Dim compPartName As String = Nothing
        Dim compRefsetName As String = Nothing
        Dim instanceName As String = Nothing
        Dim compOrigin() As Double = {0.0, 0.0, 0.0}
        Dim csysMatrix() As Double = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}
        Dim transform(,) As Double = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
        Dim markId1 As String = Nothing
        Dim nErrs1 As Integer = Nothing
        Dim ofd As OpenFileDialog = New OpenFileDialog()
        Dim member As Tag = Tag.Null
        Dim type As Integer = 0
        Dim subType As Integer = 0
        Dim testArray() As String

        ' Set undo
        s.SetUndoMark(Session.MarkVisibility.Visible, markId1)

        ' Select a text file using the Open File Dialog
        ofd.Title = "Select Data Text File"
        ofd.AddExtension = True
        ofd.DefaultExt = "txt"
        ofd.RestoreDirectory = True
        ofd.Filter = "Text files (*.txt)|*.txt"
        result = ofd.ShowDialog()
        filename = ofd.FileName
        ofd.Dispose()

        ' set up name string for ps files
        count1 = Len(filename)
        psfilename = filename.Substring(0, count1 - 4)

        ' Check all components
        ' Ignore component if on invisible layer
        ' Ignore component if  blanked
        ' Ignore component if suppressed
        ' Then test if component is partially loaded.  If so load it.
        ' Now get the solid bodies in each component and add them to an array
        counter = 0
        For Each child As Component In root.GetChildren()
            isBlankedStatus = child.IsBlanked
            isSuppressedStatus = child.IsSuppressed
            ufs.Layer.AskStatus(child.Layer, layerStatus)
            If isBlankedStatus = False And isSuppressedStatus = False _
                And layerStatus <> 4 Then
                ufs.Assem.AskComponentData(child.Tag, compPartName, compRefsetName, instanceName, _
                  compOrigin, csysMatrix, transform)
                partTag = ufs.Part.AskPartTag(compPartName)
                If ((ufs.Part.IsLoaded(compPartName)) <> 1) Then
                    ufs.Part.OpenQuiet(compPartName, partTag, errorstate)
                End If
                member = Tag.Null
start1:
                ufs.Assem.CycleObjsInComp(child.Tag, member)
                If member = Tag.Null Then GoTo end1
                ufs.Obj.AskTypeAndSubtype(member, type, subType)
                If type = 70 And subType = 0 Then
                    ReDim Preserve solid_bodies(counter)
                    solid_bodies(counter) = member
                    counter += 1
                End If
                GoTo start1
end1:
            End If
        Next
        ' Read data from the selected text file
        ' Set the expressions
        ' Export the solid bodies to ps file.
        Dim sr As StreamReader = File.OpenText(filename)
        Try
            Do While sr.Peek >= 0
                linestring = sr.ReadLine
                '      MsgBox("Line of text : " & linestring.ToString)
                index1 = Len(linestring)
                '    MsgBox(" length of string : " & index1.ToString)
                If index1 = 0 Then GoTo loop1
                If Asc(linestring(0)) > 47 And Asc(linestring(0)) < 58 Then
                    testArray = Split(linestring, vbTab, 3)
                    number1string = testArray(0)
                    number2string = testArray(1)
                    number3string = testArray(2)
                    exp1 = workPart.Expressions.FindObject("Height_1")
                    exp1.RightHandSide = number1string
                    exp2 = workPart.Expressions.FindObject("Height_2")
                    exp2.RightHandSide = number2string
                    exp3 = workPart.Expressions.FindObject("Height_3")
                    exp3.RightHandSide = number3string
                    nErrs1 = s.UpdateManager.DoUpdate(markId1)
                    count2 += 1
                    ' Now save the solid bodies to parasolid file
                    If count2 < 10 Then
                        psfilename2 = psfilename & "_00" & count2.ToString
                    ElseIf count2 > 9 And count2 < 100 Then
                        psfilename2 = psfilename & "_0" & count2.ToString
                    Else
                        psfilename2 = psfilename & "_" & count2.ToString
                    End If
                    ufs.Ps.ExportData(solid_bodies, psfilename2)
                End If
loop1:
            Loop
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        sr.Close()
    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

        
    End Function

End Module

Frank Swinkels

 

Re: Move, export, repeat

Here is a journal that worked for this specific case but it may help in developing your requirement.  The expression values are read from a text file and the output file uses the text file name with an index number.

 

Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Layer
Imports System.Windows.Forms
imports System.Collections

Module RedBullTest1
    Sub Main()
        Dim s As Session = Session.GetSession()
        Dim ui As UI = ui.GetUI()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim displayPart As Part = s.Parts.Display
        Dim workPart As Part = s.Parts.Work
        Dim root As Component = s.Parts.Work.ComponentAssembly.RootComponent
        Dim result As DialogResult
        Dim filename As String = Nothing
        Dim psfilename As String = Nothing
        Dim psfilename2 As String = Nothing
        Dim filecollection As ArrayList = New ArrayList
        Dim linestring As String = Nothing
        Dim linestring2 As String = Nothing
        Dim index1 As Integer = 0
        Dim index2 As Integer = 0
        Dim index3 As Integer = 0
        Dim counter As Integer = 0
        Dim count1 As Integer = Nothing
        Dim count2 As Integer = 0
        Dim number1string As String
        Dim number2string As String
        Dim number3string As String
        Dim exp1 As Expression = Nothing
        Dim exp2 As Expression = Nothing
        Dim exp3 As Expression = Nothing
        Dim isBlankedStatus As Boolean
        Dim isSuppressedStatus As Boolean
        Dim layerStatus As Integer
        Dim c_part As Part = Nothing
        Dim solid_bodies(-1) As Tag
        Dim partTag As Tag
        Dim errorstate As UFPart.LoadStatus = Nothing
        Dim compPartName As String = Nothing
        Dim compRefsetName As String = Nothing
        Dim instanceName As String = Nothing
        Dim compOrigin() As Double = {0.0, 0.0, 0.0}
        Dim csysMatrix() As Double = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}
        Dim transform(,) As Double = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
        Dim markId1 As String = Nothing
        Dim nErrs1 As Integer = Nothing
        Dim ofd As OpenFileDialog = New OpenFileDialog()
        Dim member As Tag = Tag.Null
        Dim type As Integer = 0
        Dim subType As Integer = 0
        Dim testArray() As String

        ' Set undo
        s.SetUndoMark(Session.MarkVisibility.Visible, markId1)

        ' Select a text file using the Open File Dialog
        ofd.Title = "Select Data Text File"
        ofd.AddExtension = True
        ofd.DefaultExt = "txt"
        ofd.RestoreDirectory = True
        ofd.Filter = "Text files (*.txt)|*.txt"
        result = ofd.ShowDialog()
        filename = ofd.FileName
        ofd.Dispose()

        ' set up name string for ps files
        count1 = Len(filename)
        psfilename = filename.Substring(0, count1 - 4)

        ' Check all components
        ' Ignore component if on invisible layer
        ' Ignore component if  blanked
        ' Ignore component if suppressed
        ' Then test if component is partially loaded.  If so load it.
        ' Now get the solid bodies in each component and add them to an array
        counter = 0
        For Each child As Component In root.GetChildren()
            isBlankedStatus = child.IsBlanked
            isSuppressedStatus = child.IsSuppressed
            ufs.Layer.AskStatus(child.Layer, layerStatus)
            If isBlankedStatus = False And isSuppressedStatus = False _
                And layerStatus <> 4 Then
                ufs.Assem.AskComponentData(child.Tag, compPartName, compRefsetName, instanceName, _
                  compOrigin, csysMatrix, transform)
                partTag = ufs.Part.AskPartTag(compPartName)
                If ((ufs.Part.IsLoaded(compPartName)) <> 1) Then
                    ufs.Part.OpenQuiet(compPartName, partTag, errorstate)
                End If
                member = Tag.Null
start1:
                ufs.Assem.CycleObjsInComp(child.Tag, member)
                If member = Tag.Null Then GoTo end1
                ufs.Obj.AskTypeAndSubtype(member, type, subType)
                If type = 70 And subType = 0 Then
                    ReDim Preserve solid_bodies(counter)
                    solid_bodies(counter) = member
                    counter += 1
                End If
                GoTo start1
end1:
            End If
        Next
        ' Read data from the selected text file
        ' Set the expressions
        ' Export the solid bodies to ps file.
        Dim sr As StreamReader = File.OpenText(filename)
        Try
            Do While sr.Peek >= 0
                linestring = sr.ReadLine
                '      MsgBox("Line of text : " & linestring.ToString)
                index1 = Len(linestring)
                '    MsgBox(" length of string : " & index1.ToString)
                If index1 = 0 Then GoTo loop1
                If Asc(linestring(0)) > 47 And Asc(linestring(0)) < 58 Then
                    testArray = Split(linestring, vbTab, 3)
                    number1string = testArray(0)
                    number2string = testArray(1)
                    number3string = testArray(2)
                    exp1 = workPart.Expressions.FindObject("Height_1")
                    exp1.RightHandSide = number1string
                    exp2 = workPart.Expressions.FindObject("Height_2")
                    exp2.RightHandSide = number2string
                    exp3 = workPart.Expressions.FindObject("Height_3")
                    exp3.RightHandSide = number3string
                    nErrs1 = s.UpdateManager.DoUpdate(markId1)
                    count2 += 1
                    ' Now save the solid bodies to parasolid file
                    If count2 < 10 Then
                        psfilename2 = psfilename & "_00" & count2.ToString
                    ElseIf count2 > 9 And count2 < 100 Then
                        psfilename2 = psfilename & "_0" & count2.ToString
                    Else
                        psfilename2 = psfilename & "_" & count2.ToString
                    End If
                    ufs.Ps.ExportData(solid_bodies, psfilename2)
                End If
loop1:
            Loop
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        sr.Close()
    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

        
    End Function

End Module

Frank Swinkels

 

Re: Move, export, repeat

Here is a journal that worked for three expressions.  The expression values are read from a text file and the output uses the text file name with index numbers.

 

Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Layer
Imports System.Windows.Forms
imports System.Collections

Module RedBullTest1
    Sub Main()
        Dim s As Session = Session.GetSession()
        Dim ui As UI = ui.GetUI()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim displayPart As Part = s.Parts.Display
        Dim workPart As Part = s.Parts.Work
        Dim root As Component = s.Parts.Work.ComponentAssembly.RootComponent
        Dim result As DialogResult
        Dim filename As String = Nothing
        Dim psfilename As String = Nothing
        Dim psfilename2 As String = Nothing
        Dim filecollection As ArrayList = New ArrayList
        Dim linestring As String = Nothing
        Dim linestring2 As String = Nothing
        Dim index1 As Integer = 0
        Dim index2 As Integer = 0
        Dim index3 As Integer = 0
        Dim counter As Integer = 0
        Dim count1 As Integer = Nothing
        Dim count2 As Integer = 0
        Dim number1string As String
        Dim number2string As String
        Dim number3string As String
        Dim exp1 As Expression = Nothing
        Dim exp2 As Expression = Nothing
        Dim exp3 As Expression = Nothing
        Dim isBlankedStatus As Boolean
        Dim isSuppressedStatus As Boolean
        Dim layerStatus As Integer
        Dim c_part As Part = Nothing
        Dim solid_bodies(-1) As Tag
        Dim partTag As Tag
        Dim errorstate As UFPart.LoadStatus = Nothing
        Dim compPartName As String = Nothing
        Dim compRefsetName As String = Nothing
        Dim instanceName As String = Nothing
        Dim compOrigin() As Double = {0.0, 0.0, 0.0}
        Dim csysMatrix() As Double = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}
        Dim transform(,) As Double = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
        Dim markId1 As String = Nothing
        Dim nErrs1 As Integer = Nothing
        Dim ofd As OpenFileDialog = New OpenFileDialog()
        Dim member As Tag = Tag.Null
        Dim type As Integer = 0
        Dim subType As Integer = 0
        Dim testArray() As String

        ' Set undo
        s.SetUndoMark(Session.MarkVisibility.Visible, markId1)

        ' Select a text file using the Open File Dialog
        ofd.Title = "Select Data Text File"
        ofd.AddExtension = True
        ofd.DefaultExt = "txt"
        ofd.RestoreDirectory = True
        ofd.Filter = "Text files (*.txt)|*.txt"
        result = ofd.ShowDialog()
        filename = ofd.FileName
        ofd.Dispose()

        ' set up name string for ps files
        count1 = Len(filename)
        psfilename = filename.Substring(0, count1 - 4)

        ' Check all components
        ' Ignore component if on invisible layer
        ' Ignore component if  blanked
        ' Ignore component if suppressed
        ' Then test if component is partially loaded.  If so load it.
        ' Now get the solid bodies in each component and add them to an array
        counter = 0
        For Each child As Component In root.GetChildren()
            isBlankedStatus = child.IsBlanked
            isSuppressedStatus = child.IsSuppressed
            ufs.Layer.AskStatus(child.Layer, layerStatus)
            If isBlankedStatus = False And isSuppressedStatus = False _
                And layerStatus <> 4 Then
                ufs.Assem.AskComponentData(child.Tag, compPartName, compRefsetName, instanceName, _
                  compOrigin, csysMatrix, transform)
                partTag = ufs.Part.AskPartTag(compPartName)
                If ((ufs.Part.IsLoaded(compPartName)) <> 1) Then
                    ufs.Part.OpenQuiet(compPartName, partTag, errorstate)
                End If
                member = Tag.Null
start1:
                ufs.Assem.CycleObjsInComp(child.Tag, member)
                If member = Tag.Null Then GoTo end1
                ufs.Obj.AskTypeAndSubtype(member, type, subType)
                If type = 70 And subType = 0 Then
                    ReDim Preserve solid_bodies(counter)
                    solid_bodies(counter) = member
                    counter += 1
                End If
                GoTo start1
end1:
            End If
        Next
        ' Read data from the selected text file
        ' Set the expressions
        ' Export the solid bodies to ps file.
        Dim sr As StreamReader = File.OpenText(filename)
        Try
            Do While sr.Peek >= 0
                linestring = sr.ReadLine
                '      MsgBox("Line of text : " & linestring.ToString)
                index1 = Len(linestring)
                '    MsgBox(" length of string : " & index1.ToString)
                If index1 = 0 Then GoTo loop1
                If Asc(linestring(0)) > 47 And Asc(linestring(0)) < 58 Then
                    testArray = Split(linestring, vbTab, 3)
                    number1string = testArray(0)
                    number2string = testArray(1)
                    number3string = testArray(2)
                    exp1 = workPart.Expressions.FindObject("Height_1")
                    exp1.RightHandSide = number1string
                    exp2 = workPart.Expressions.FindObject("Height_2")
                    exp2.RightHandSide = number2string
                    exp3 = workPart.Expressions.FindObject("Height_3")
                    exp3.RightHandSide = number3string
                    nErrs1 = s.UpdateManager.DoUpdate(markId1)
                    count2 += 1
                    ' Now save the solid bodies to parasolid file
                    If count2 < 10 Then
                        psfilename2 = psfilename & "_00" & count2.ToString
                    ElseIf count2 > 9 And count2 < 100 Then
                        psfilename2 = psfilename & "_0" & count2.ToString
                    Else
                        psfilename2 = psfilename & "_" & count2.ToString
                    End If
                    ufs.Ps.ExportData(solid_bodies, psfilename2)
                End If
loop1:
            Loop
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        sr.Close()
    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

        
    End Function

End Module

Frank Swinkels

 

Re: Move, export, repeat

I have tried 4 times to insert a journal as code with no succes.

 

Here is a try for the vb file as a txt file attachment

 

Frank Swinkels