Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Import assembly from excel/text file 2

Status
Not open for further replies.

Nham

Mechanical
Mar 20, 2013
27
All more experienced users and or Journal(ists) please help :)

I have a problem with some assembly work. I have a bunch of files (a lot)on disk (parts) that need to be assembled.
Assembly structure is possible to get in Excel/text format with relatively small effort. Used NX version is NX7.5

Is there a quick way to import assemblies according to excel list so that native nx could read all listed part files from one directory? End results would be then easy to modify later if some parts change before importing them to Teamcenter later.
Importing to TC is not an option yet because TC installation does not exist yet for this location. Have to set wheels in motion before installation can be started.

Examples and perhaps excisting journals would be helpful.

Thanks in advance

NH
 
Replies continue below

Recommended for you

Here is some code to get you started. It assumes the full path to a part file is on each line of a text file. It will assemble each given part as a component into the work part. There is not much error checking done in this version.

Code:
Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen

Module Module1

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

    Sub Main()

        If theSession.Parts.Display Is Nothing Then
            MsgBox("Active part required")
            Exit Sub
        End If

        Dim openFileDialog1 As New OpenFileDialog()

        openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True

        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            Dim line As String

            Using sr As StreamReader = New StreamReader(openFileDialog1.FileName)
                Try
                    line = sr.ReadLine()
                    While Not line Is Nothing
                        If File.Exists(line) Then
                            Dim componentName As String = Path.GetFileNameWithoutExtension(line).ToUpper
                            AddComponent(line, "", componentName)
                        End If
                        line = sr.ReadLine()
                    End While
                Catch E As Exception
                    MessageBox.Show(E.Message)
                End Try
            End Using
        End If

    End Sub

    Sub AddComponent(ByVal compPath As String, ByVal refSet As String, Optional ByVal compName As String = Nothing)

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add Component")

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

        Dim basePoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim orientation1 As Matrix3x3
        orientation1.Xx = 1.0
        orientation1.Xy = 0.0
        orientation1.Xz = 0.0
        orientation1.Yx = 0.0
        orientation1.Yy = 1.0
        orientation1.Yz = 0.0
        orientation1.Zx = 0.0
        orientation1.Zy = 0.0
        orientation1.Zz = 1.0
        Dim partLoadStatus1 As PartLoadStatus
        Dim component1 As Assemblies.Component
        component1 = workPart.ComponentAssembly.AddComponent(compPath, refSet, compName, basePoint1, orientation1, 1, partLoadStatus1, True)

        partLoadStatus1.Dispose()

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

    End Function

End Module

www.nxjournaling.com
 
Cowski, Thank you for this, works like a charm [bigsmile]
I tested with some parts and though reporting might help in some cases this was exactly what was needed. We will put this to more serious use soon. [bigsmile]
 
Hello Cowski,
Last post about my request was great!

Here is another nut to crack. Your code makes thigs easier but there is just too many parts and of course shared by many assemblies.
Below is a simplified example of a multilevel BOM exported to a text file from previous system. Assuming that all child parts are in the same directory and no assembly levels exist, would it be possible to generate the assembly structure from the text file using existing parts? Levels of assembly can be marked differently if the format is a problem. Generating empty child assemblies components against a text file with existing template file and populating them with existing parts is way beyond me.

Now with that previous journal it is possible to assemble one level at the time. More convenient way would be to have multiple levels in one text file imported once. I do not know how easy this would be, but with multiple levels there should be a report telling if no part was found from the import folder.

How to do this, first generate all assembly files and then populate them with parts or start from lowest level assy first and then progress to higher levels... Assemblies could be marked with A to distinguish which ones to create and so on.

MAIN_ASSY.PRT
. FIRST_LEVEL_CHILD_ASSY.PRT
. . SECOND_LEVEL_ASSY1.PRT
. . . bolt.prt
. . . Plate.prt
. . . Flat_Washer-prt
. . . 1_8_BSP_STR_Grease_Nipple.prt
. . . bolt.prt
. . . Flat_Washer.prt
. . . Flat_Washer.prt
. . . nut.prt
. . . Flat_Washer.prt
. . . nut.prt
. . . THIRD_LEVEL_ASSY1.PRT
. . . . Beam1.prt
. . . . Beam2.prt
. . . . Beam1.prt
. . Second_Level_assy2.prt
. . . Flat_Washer.prt
. . . nut_20.prt
. . . Hose1.prt

Do you think you could help me out with this?

Cheers
-NH
 
I've had a chance to get back to this problem; below is a link to a journal.

It has correctly handled my (limited) test cases; however, I do not claim to have tested for every possibility. Create some fictional test cases of your own to try it out. This journal will create new files and add components to existing files, do NOT use it without some testing first. Use at your own risk, please report any bugs you find and I will try to sort them out.

Reporting in this initial version is minimal.


www.nxjournaling.com
 
It's possible implement the quantity import, because actually import all in 1 q.ty.

Thank you...

Using NX 8 and TC9.1
 
In my testing the quantity import works fine.
Can you provide a sample text file BOM that shows the problem you are having?

www.nxjournaling.com
 
Sorry,
which is the syntax to put more then one of the same component ?

Thank you...

Using NX 8 and TC9.1
 
The journal was programmed to handle input such as that given by Nham in his post of 12 Sep 13 11:44. Each line is interpreted as a component, periods and spaces (or other characters as defined by the user) at the beginning of the line indicate the assembly level. If you have multiples of a component, it will need to show up multiple times under the appropriate assembly/subassembly level.

www.nxjournaling.com
 
Yes, I'm using the code linked in your dropbox public folder.
Then, if I've 30 screws of the same part number, I need to create 30 lines of this part number ?
If yes, you can implement in the journal the support for the quantity ?
Example :
MAIN_ASSY.PRT
. FIRST_LEVEL_CHILD_ASSY.PRT,5
. . SECOND_LEVEL_ASSY1.PRT,1
. . . bolt.prt,1
. . . Plate.prt
. . . Flat_Washer-prt
. . . 1_8_BSP_STR_Grease_Nipple.prt
. . . bolt.prt
. . . Flat_Washer.prt
. . . Flat_Washer.prt
. . . nut.prt
. . . Flat_Washer.prt
. . . nut.prt
. . . THIRD_LEVEL_ASSY1.PRT
. . . . Beam1.prt
. . . . Beam2.prt
. . . . Beam1.prt
. . Second_Level_assy2.prt
. . . Flat_Washer.prt
. . . nut_20.prt
. . . Hose1.prt

Thank you...

Using NX 8 and TC9.1
 
can't you just select the fields in excel, copy (ctrl-c) them and paste them in a nx drawing? it works in autocad...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor