Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Converting a UG assembly file into a single part file with component names and attributes 1

Status
Not open for further replies.

gcrow

Automotive
May 23, 2013
25
0
0
US
We have to upload our asm files into our OEM teamcenter. We have been getting away with putting our asm files in as bulk parasolid files. The oem now wants us to supply individual part files because when they open the file all the see is "body" in the part navigator. I have been going through this site trying to find a journal or work around with no luck. What i need is a way that i can get a single file with with parasolids that show the component name, has material associated with it. I know you can do this manually but there is no association and will have to be done every time we put somehting in teamcenter. We have attributes in the file sucha as DB_PART_NAME and P_MAT that i would like to be added to the solids. Ive tried wave and that only shows as linked body and doesn't have the part name or material. Catia has a function called generate CATPART from PRODUCT that that converts an asm file into a single part file and names the bodys the file names. This is what i need in UG.
 
Replies continue below

Recommended for you

@grow
my idea behind is to offer an all catpart the people in v5/many viewers like in downstream process... one single catpart file from step.
regards
 
@gcrow
thats no problem the following workflow:
Activate your to assembly level put everything you want to have in your all catpart in to show.
goto file export part choose new a name for the allcatpart.prt
object scope to all objects
class selection to body select all
optional remove parameters -> Ok
thats all -
a one click solution can be done with a journal but its no problem to create an all catpart in nx.
historic in unigraphics we pulled it to parasolid in V5 the workaround was the allcatpart
in V5 there's nothing like parasolid - does anybody save as cgm(the v5 kernal base / not the grapfic format) ?
regards
 
That doesn't do what i need. Catia names the bodies the file name. UG names them solid body with no reference to original component. Catia combines asm to one file with bodies named same as component (basically same as parasolid). The journal cowski wrote does what i need.
 
Updated code that limits names to 30 characters.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim mySelectedObjects() As NXObject
        Dim myResponse As Selection.Response
		Dim tagList As New List(Of NXOpen.Tag)
		Dim strParasolid As String

        lw.Open()

        strParasolid = workPart.FullPath
        strParasolid = Left(strParasolid, Len(strParasolid) - 4)
		strParasolid = strParasolid & ".x_t"

		If My.Computer.FileSystem.FileExists(strParasolid) Then
			Try
				My.Computer.FileSystem.DeleteFile(strParasolid)
			Catch ex As Exception
				lw.WriteLine(ex.GetType.ToString & " : " & ex.Message)
				lw.WriteLine("journal exiting")
				Exit Sub
			End Try
		End If

        myResponse = SelectObjects(mySelectedObjects)
        If (myResponse = Selection.Response.Cancel) OrElse (myResponse = Selection.Response.Back) Then
            'user canceled selection, exit journal
            Exit Sub
        End If

        For Each obj As Body In mySelectedObjects
			If obj.IsOccurrence Then
				If obj.OwningComponent.DisplayName.Length > 30 Then
					obj.SetName(obj.OwningComponent.DisplayName.Substring(0, 30))
				Else
					obj.SetName(obj.OwningComponent.DisplayName)
				End If
			Else
				If obj.OwningPart.Leaf.Length > 30 Then
					obj.SetName(obj.OwningPart.Leaf.Substring(0, 30))
				Else
					obj.SetName(obj.OwningPart.Leaf)
				End If
			End If
			tagList.Add(obj.Tag)
        Next

		ufs.Ps.ExportData(tagList.ToArray, strParasolid)
        lw.WriteLine("Output file: " & strParasolid)
        lw.Close()

    End Sub

    Function SelectObjects(ByRef selobj() As NXObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim prompt As String = "Select Solid Bodies"
        Dim title As String = "Selection"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = _
            Selection.SelectionAction.ClearAndEnableSpecific

        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple

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

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
            prompt, title, scope, selAction, _
            includeFeatures, keepHighlighted, selectionMask_array, selobj)

        Return resp

    End Function


End Module

www.nxjournaling.com
 
Hey Cowski,
Any chance to modify this journal to assign Material properties to the solid bodies. What you have done so far is great. Problem now is assigning the same material that was in the original file. Many of our parts in the asm have different materials assigned. It leaves room for error. The attribute is P_MAT. I don't know how to do it.

Thanks
 
I believe that attribute information is lost in the parasolid export process. I know of no way to successfully assign attributes to exported parasolids and have them show up when you import the parasolid into a new file.

www.nxjournaling.com
 
Hi guys, Is it possible to assign components attribute value to exported bodies names. Each selected component has an attribute "Description" which I want to assign to exported body. I tried to modify the code a little bit. The problem is that it uses only work part attribute, not selected component attribute.


Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim displayPart As Part = theSession.Parts.Display
        Dim lw As ListingWindow = theSession.ListingWindow
        Dim mySelectedObjects() As NXObject
        Dim myResponse As Selection.Response
        Dim tagList As New List(Of NXOpen.Tag)
        Dim strParasolid As String

        lw.Open()

        strParasolid = workPart.FullPath
        strParasolid = Left(strParasolid, Len(strParasolid) - 4)
        strParasolid = strParasolid & ".x_t"

        If My.Computer.FileSystem.FileExists(strParasolid) Then
            Try
                My.Computer.FileSystem.DeleteFile(strParasolid)
            Catch ex As Exception
                lw.WriteLine(ex.GetType.ToString & " : " & ex.Message)
                lw.WriteLine("journal exiting")
                Exit Sub
            End Try
        End If

        myResponse = SelectObjects(mySelectedObjects)
        If (myResponse = Selection.Response.Cancel) OrElse (myResponse = Selection.Response.Back) Then
            'user canceled selection, exit journal
            Exit Sub
        End If

        For Each obj As Body In mySelectedObjects
            If obj.IsOccurrence Then
                If obj.OwningComponent.DisplayName.Length > 30 Then
                    obj.SetName(obj.OwningComponent.DisplayName.Substring(0, 30))
                Else
                    obj.SetName(obj.OwningComponent.DisplayName)
                End If
            Else
             [highlight #729FCF]   Dim Attribute As String
                Attribute = workPart.GetStringAttribute("DESCRIPTION")
                If obj.OwningPart.Leaf.Length > 30 Then
                    obj.SetName(Attribute)
                Else
                    obj.SetName(Attribute)[/highlight]
                End If
            End If
            tagList.Add(obj.Tag)
        Next

        ufs.Ps.ExportData(tagList.ToArray, strParasolid)
        lw.WriteLine("Output file: " & strParasolid)
        lw.Close()

    End Sub

    Function SelectObjects(ByRef selobj() As NXObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim prompt As String = "Select Solid Bodies"
        Dim title As String = "Selection"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = _
            Selection.SelectionAction.ClearAndEnableSpecific

        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple

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

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
            prompt, title, scope, selAction, _
            includeFeatures, keepHighlighted, selectionMask_array, selobj)

        Return resp
    End Function
End Module
 
Hey guys, Thanks for the help. Do I have to modify the field where it says ("DESCRIPTION") to the attribute name I want to apply? I'm getting "object reference not set to instance of object" error.
 
when i use a 3d imported from other system like cadenas partserver hasco merkle ecc..
the parasolid created "remember" the original name
for example: part name "2430_cylinder" ---> merkle_xmdesf_sasd
worst with more solids into the part "2430_cylinder" --> create more parts merkle_rod,merkle_block_merkle_o-ring.

 
Status
Not open for further replies.
Back
Top