UG NX Assembly BOM & Structure
UG NX Assembly BOM & Structure
(OP)
Ok this is going to be a little long, I apologize up front.
We are newish to UG NX (running NX 3 & TeamCenter), We are transitioning from SoildWorks. I have built an enormous number of software tools to extract data and information from SolidWorks and manipulate it and collate it. The same level of ability is near impossible for me to do in UG or TeamCenter based on its lack of an API with any level of friendliness. However what I would like to do is extract either from UG - preferably TeamCenter is as follows.
A tab delimited text file that has an indented structure of all the parts and subassemblies (multiple occurrences of the same item need not be "compacted") with a part description if I can get it. Thats it!
If anyone has does similar things or has a program to do this it would be beyond greatly appreciated!
We are newish to UG NX (running NX 3 & TeamCenter), We are transitioning from SoildWorks. I have built an enormous number of software tools to extract data and information from SolidWorks and manipulate it and collate it. The same level of ability is near impossible for me to do in UG or TeamCenter based on its lack of an API with any level of friendliness. However what I would like to do is extract either from UG - preferably TeamCenter is as follows.
A tab delimited text file that has an indented structure of all the parts and subassemblies (multiple occurrences of the same item need not be "compacted") with a part description if I can get it. Thats it!
If anyone has does similar things or has a program to do this it would be beyond greatly appreciated!
Guy Edkins





RE: UG NX Assembly BOM & Structure
Anyway, take a look at this post:
thread561-119283
My code has since been updated to show assembly level.
CODE
'assembly navigator view.
'Assumes part number is in column A and
'component name is in column B.
'Quantity will be placed in column C.
Option Explicit
Dim strPartNumber As String
Dim strQuantity As String
Sub Macro1()
Attribute Macro1.VB_Description = "Parses quantity information from a UG assembly navigator that has been exported to spreadsheet."
Attribute Macro1.VB_ProcData.VB_Invoke_Func = "q\n14"
Call ParseQuantity
Call AssemblyLevel
End Sub
Private Sub ParseQuantity()
Dim i As Long
Dim j As Long
'insert quantity column
'change this as needed
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("C1:C1").Select
ActiveCell.Value = "Quantity"
Columns("C:C").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
.NumberFormat = "General"
End With
Columns("C:C").EntireColumn.AutoFit
'select first cell in part number column
'change this as needed
Range("A2:A2").Select
'loop through cells that are not empty
'when macro encounters an empty cell it stops
Do Until ActiveCell.Value = ""
strPartNumber = ActiveCell.Text
i = InStr(1, strPartNumber, " x ")
If i = 0 Then
'string not found, quantity = 1
ActiveCell.Offset(0, 2).Activate
ActiveCell.Value = "1"
ActiveCell.Offset(0, -2).Activate
Else
'string found, quantity > 1
j = Len(strPartNumber)
strQuantity = Right(strPartNumber, j - i)
'strip off first 2 characters of quantity string - "x "
strQuantity = Right(strQuantity, Len(strQuantity) - 2)
'strip off last character of part number string (a space)
strPartNumber = Left(strPartNumber, i - 1)
'record part number with quantity stripped off the end
ActiveCell.Value = strPartNumber
'move cell over a column and record quantity
ActiveCell.Offset(0, 2).Activate
ActiveCell.Value = strQuantity
'move cell back to partnumber column
ActiveCell.Offset(0, -2).Activate
End If
'move active cell down 1 row
ActiveCell.Offset(1, 0).Activate
Loop
End Sub
Private Sub AssemblyLevel()
Dim strAssemblyLevel As String
Dim strPartNumber As String
Dim strSpaces As String
Dim i As Long
'insert quantity column
'change this as needed
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A1:A1").Select
ActiveCell.Value = "Assembly Level"
Columns("A:A").Select
With Selection.Font
.Name = "Courier New"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Columns("A:A").Select
Selection.NumberFormat = "@"
Range("A1").Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Columns("A:A").EntireColumn.AutoFit
Range("B2:B2").Select
'loop through cells that are not empty
'when macro encounters an empty cell it stops
Do Until ActiveCell.Value = ""
strPartNumber = ActiveCell.Text
For i = 1 To Len(strPartNumber)
strSpaces = Mid(strPartNumber, i, 1)
If strSpaces <> " " Then
If i = 1 Then
strAssemblyLevel = "1"
Exit For
Else
i = i - 1
strAssemblyLevel = String(i / 4, ".")
strAssemblyLevel = strAssemblyLevel & CStr(i / 4 + 1)
Exit For
End If
End If
Next i
'move active cell to first column to record assembly level
ActiveCell.Offset(0, -1).Activate
ActiveCell.Value = strAssemblyLevel
'move active cell down a row and over a column to get next part number
ActiveCell.Offset(1, 1).Activate
'MsgBox strAssemblyLevel & " " & strPartNumber, vbOKOnly
Loop
Range("A1:A1").Select
End Sub
It looks a little intimidating, but most of the code is dealing with formatting (which you can do without if you are using a plain text file). Excel can save the output as a csv file. If you don't have excel, then I think I have a grip program (unfinished if I remember correctly) that may give you some ideas.
RE: UG NX Assembly BOM & Structure
The extraction portion of this is very helpful. Your macro is also very useful. Once I get the data into a known and understood format I can send you a tool I have developed for Excel that makes working with large assemblies very easy. I can send you a sample if your interested. I hyperlinked the SW file location into the spreadsheet and it allowed direct file viewing of the SW files, I will have to delete that portion for use with UG since we now use TeamCenter.
Guy Edkins
RE: UG NX Assembly BOM & Structure
By the way, it is a bit of jolt to go from a modern well built API enabled system like SW to something like UG. It's just so nice to be able to "talk" to your data programmatically with such ease! I miss it already and I have hardly scratched the surface.
Thanks again for your help.
Guy Edkins
RE: UG NX Assembly BOM & Structure
I notice you are on NX3, if you are running on windows you may want to look up 'journaling' in the help files. I am still stuck on NX2 but I hear that they are integrating a .net macro language. NX3 is the first release with it in there so there is probably not as much functionality as you would like but it should improve in future releases.
I'm looking forward to upgrading to NX3/4 just for the journaling.
RE: UG NX Assembly BOM & Structure
I have spent a great deal of time looking at the journaling under NX 3. Don't get your hopes up to high. UG has used "wrappers" to do the VBA interfacing since they still run native in the UNIX world they are saddled with the problem of cross platform inteopreabilty and there is no VB equiv on the UNIX side. The code is extremly top heavy to work with. And you are right the number of API calls available is limited at best. The good news is most of the calls there currently are data management related vs. geometry creation related. Until UG lets go of the UNIX world (no plans to do that) they can never really be fully integrated to the MS world, i.e. use the VBA or VB engines directly. Legacy is always an issue with older UNIX based systems.
Guy
Guy Edkins
RE: UG NX Assembly BOM & Structure