×
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

Journal exporting part files
4

Journal exporting part files

Journal exporting part files

(OP)
I am in search of vb code to finish a journal I am creating to seek out and export certain parts in an assembly. I can figure out how to find said parts but am stumped on to to actually export them out. I would like to specify the part be placed in given folder for all assemblies and would name it after the assembly, without parameters as well. Any ideas? All input is well appreciated.

RE: Journal exporting part files

I have had luck calling the SaveAs() function of a Part instance. The argument it takes is the full path of the file you want to save.
You can also specify different extensions (.stp, .igs, etc) and NX will translate them. As far as removing the parameters... don't know. I was working on a similar function before to export certain components of an assembly as step files but couldn't get the step exporter properties to apply correctly.

RE: Journal exporting part files

Do you want to export parasolids of the given solids or are you trying to do something else?

www.nxjournaling.com

RE: Journal exporting part files

(OP)
I would like to export unparamaterized .prt files of the given files individually

RE: Journal exporting part files

2
Here's a simplified example of exporting an unparameterized solid to a new part file.

CODE

Option Strict Off  
Imports System  
Imports NXOpen  
Imports NXOpen.UF  

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim ufs As UFSession = UFSession.GetUFSession  
        Dim workPart As Part = theSession.Parts.Work  

        Dim myOptions As UFPart.ExportOptions  
        myOptions.params_mode = UFPart.ExportParamsMode.RemoveParams  
        myOptions.new_part = True  

        Dim partName As String = "C:\temp\export_test.prt"  
        Dim bodyTag(0) As Tag  

        Dim mySolid As NXObject  
        If SelectSolid("Select a solid", mySolid) = Selection.Response.Cancel Then  
            Exit Sub  
        End If  

        bodyTag(0) = mySolid.Tag  

        ufs.Part.ExportWithOptions(partName, 1, bodyTag, myOptions)  

    End Sub  

    Function SelectSolid(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response  

        Dim theUI As UI = UI.GetUI  
        Dim title As String = "Select a solid"  
        Dim includeFeatures As Boolean = False  
        Dim keepHighlighted As Boolean = False  
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific  
        Dim cursor As Point3d  
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly  
        Dim selectionMask_array(0) As Selection.MaskTriple  

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

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _  
         title, scope, selAction, _  
         includeFeatures, keepHighlighted, selectionMask_array, _  
         selobj, cursor)  
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then  
            Return Selection.Response.Ok  
        Else  
            Return Selection.Response.Cancel  
        End If  

    End Function  


End Module 

www.nxjournaling.com

RE: Journal exporting part files

Would it be possible to export all solids and surfaces on layer 1 and all points and curves on layers 230-240?

RE: Journal exporting part files

Quote (UGperson)

Would it be possible to export all solids and surfaces on layer 1 and all points and curves on layers 230-240?

Yes.
Below is a bare bones journal to do just that. You'll want to add some error checking or possibly a file select dialog as needed, but this should get you started.

CODE

'eng-tips thread561-336277: Journal exporting part files: Journal exporting part files
'code to export unparameterized objects to a new file
'export all solids and surfaces from layer 1
'export all curves and points from layers 230-240

Imports NXOpen  
Imports NXOpen.UF  
Imports System.Collections.Generic  

Module Module2  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim ufs As UFSession = UFSession.GetUFSession  
        Dim workPart As Part = theSession.Parts.Work  

        Const bodyLayer As Integer = 1  
        Const curveLayerStart As Integer = 230  
        Const curveLayerEnd As Integer = 240  

        Dim myOptions As UFPart.ExportOptions  
        myOptions.params_mode = UFPart.ExportParamsMode.RemoveParams  
        myOptions.new_part = True  

        Dim partName As String = "C:\temp\export_test2.prt"  
        Dim objectTags As New List(Of Tag)  

 'collect bodies from layer 1
        For Each myObj As Body In workPart.Bodies  
            If myObj.Layer = bodyLayer Then  
                objectTags.Add(myObj.Tag)  
            End If  
        Next  

 'collect curves
        For Each myObj As Curve In workPart.Curves  
            If myObj.Layer >= curveLayerStart And myObj.Layer <= curveLayerEnd Then  
                objectTags.Add(myObj.Tag)  
            End If  
        Next  

 'collect points
        For Each myObj As Point In workPart.Points  
            If myObj.Layer >= curveLayerStart And myObj.Layer <= curveLayerEnd Then  
                objectTags.Add(myObj.Tag)  
            End If  
        Next  

        ufs.Part.ExportWithOptions(partName, objectTags.Count, objectTags.ToArray, myOptions)  

    End Sub  

End Module 

www.nxjournaling.com

RE: Journal exporting part files

Thanks!

Is there a better way to get the folder name that the file is in than what I have here?

'***********************************************************************

Function GetFilePath2()
Dim strPath as String
Dim strPart as String
Dim strPart2 as String
Dim pos as Integer
Dim pos2 as Integer

'get the full file path
strPart2 = displayPart.fullpath
pos = InStrRev(strPart2, "\")
strPart2 = Left(strPart2, pos -1)

strPath = strPart2

pos2 = InStrRev(strPath, "\")
strPart = Mid(strPath, pos2 + 1)

strPath = Left(strPath, pos)
strPart = Left(strPart, Len(strPart))

GetFilePath2 = strPart
End Function

'***********************************************************************

RE: Journal exporting part files

The .NET framework has you covered:

CODE

Option Strict Off  
Imports System  
Imports NXOpen  

Module Module1  

    Sub Main()  

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

        Dim fileName As String = IO.Path.GetFileName(workPart.FullPath)  
        Dim fileNameNoExt As String = IO.Path.GetFileNameWithoutExtension(workPart.FullPath)  
        Dim parentFolder As String = IO.Path.GetDirectoryName(workPart.FullPath)  
        Dim root As String = IO.Path.GetPathRoot(workPart.FullPath)  

        lw.WriteLine("full path: " & workPart.FullPath)  
        lw.WriteLine(New String("-", ("full path: " & workPart.FullPath).Length))  
        lw.WriteLine("file name: " & fileName)  
        lw.WriteLine("file name w/o extension: " & fileNameNoExt)  
        lw.WriteLine("parent folder: " & parentFolder)  
        lw.WriteLine("root folder: " & root)  

        lw.Close()  

    End Sub  

End Module 

www.nxjournaling.com

RE: Journal exporting part files

(OP)
cowski,
is there a way to process an assembly file and export all parts that have an attribute that equals a defined string.
Say, export out a .prt with all components that have a catalog attribute that equals "Outside_Work"?
My best swing at it was attempting to compile a list of objects where the attributed equaled "Outside_Work" but I am stuck on how to call out the attribute of each part individually.

Denis Huskic
Data Prep
Kettering University
Class of '17

RE: Journal exporting part files

Is the attribute defined at the component or the part level?

www.nxjournaling.com

RE: Journal exporting part files

(OP)
Component level I believe. It is an attribute we have in the assembly navigator.

Denis Huskic
Data Prep
Kettering University
Class of '17

RE: Journal exporting part files

(OP)
I still have yet to get the code to succesfully run. I am having issues with the two following lines. I don't know for sure if this is in the right direction to accomplish the goal, but this is all I have so far.

CODE --> vb

For Each child As Component In comp.GetChildren()
...
Dim mySolid As NXObject() = complist 

Here is what I have been trying.

CODE --> vb

'NXJournal to recursively walk through the assembly structure
'eng-tips thread561-335918: Using journal to select all: Using journal to select all: 
'eng-tips thread561-336277: Journal exporting part files: Journal exporting part files: 
'NX 7.5

Option Strict Off  
Imports System  
Imports NXOpen  
Imports NXOpen.UF  
Imports NXOpen.Utilities  
Imports NXOpen.Assemblies  
Imports System.Windows.Forms  
Imports System.IO  
Imports System.Collections  
Imports System.Collections.Generic  
Imports System.Environment  
Imports NXOpenUI  
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    
    Sub Main()
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
    Dim c As ComponentAssembly = dispPart.ComponentAssembly
    Dim Components As NXobject
    Dim complist As New List(Of NXobject)
    Dim comp As Component
        For Each child As Component In comp.GetChildren()
            if child.GetChildren.Length <> 0 then
            If child.GetStringAttribute("Catalog") = "Outside-Work" Then
               compList.Add(child)      
            end if
            end if
        Next
        'MsgBox(complist)
        Dim partname As String = Path.GetFileNameWithoutExtension(workPart.FullPath) 

        Dim folderName As String = "C:"  
        'assign output folder to workpart folder
        folderName = Path.GetDirectoryName(workPart.FullPath)  
        Dim outputDirectory As String = foldername  
        Dim strPartJpg As String
        partname = partname & "_RevComponents"
        strPartJpg = Path.Combine(outputDirectory, partname)
 
        Dim myOptions As UFPart.ExportOptions  
        myOptions.params_mode = UFPart.ExportParamsMode.MaintainAllParams  
        myOptions.new_part = True  
        Dim bodyTag(0) As Tag  

        Dim mySolid As NXObject() = complist
        
        bodyTag(0) = mySolid.Tag  
        'MsgBox(strPartJpg)
        ufs.Part.ExportWithOptions(strPartJpg, 1, bodyTag, myOptions)  
    End Sub
'**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
'**********************************************************
 
End Module 

Denis Huskic
Data Prep
Kettering University
Class of '17

RE: Journal exporting part files

The first problem I see is you are trying to use an empty variable.

CODE

Dim comp As Component
    For Each child As Component In comp.GetChildren() 

comp.GetChildren() will return nothing because the comp variable has been created but doesn't yet contain anything.

For some working code to walk through an assembly along with explanation, see: http://nxjournaling.com/?q=content/creating-subrou...

www.nxjournaling.com

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