cschnei
Industrial
- Aug 14, 2014
- 14
Hello,
we often get Assemblies from suppliers that need to be imported into Teamcenter. These Assemblies contain parts from Part Families. I know that it is possible to convert Part Family members into normal Parts during the import process. But I have to add additional attributes to all parts of the assembly before I start the Import (e.g. OS_Part_Name). Is there a way to switch a Part Family part into a normal part by using a journal because Part Family members can not be saved with their changes.
This is my journal to add the needed attribute to all parts in one directory. But I need help to remove the Part Family information.
Thanks in advance
Carsten
we often get Assemblies from suppliers that need to be imported into Teamcenter. These Assemblies contain parts from Part Families. I know that it is possible to convert Part Family members into normal Parts during the import process. But I have to add additional attributes to all parts of the assembly before I start the Import (e.g. OS_Part_Name). Is there a way to switch a Part Family part into a normal part by using a journal because Part Family members can not be saved with their changes.
This is my journal to add the needed attribute to all parts in one directory. But I need help to remove the Part Family information.
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports System.Diagnostics
Module NXJournal
Sub Main
' Overall StopWatch
Dim stopWatch as StopWatch = new StopWatch()
Dim value As TimeSpan
Dim totalTime As String
' Individual Part StopWatch
Dim partWatch as StopWatch = new StopWatch()
Dim partTime As TimeSpan
Dim totalPartTime As String
' User Entry
Dim path As String
path = "C:\Temp\test_refile\"
Dim logFileName As String
logFileName = "C:\Temp\test_refile\xxxx.txt"
stopWatch.Start()
Dim theSession As Session = Session.GetSession()
Dim loadedPart As String
Dim loadParts() As String
' Read Directory
Dim directory As New IO.DirectoryInfo(path)
Dim directoryFiles As IO.FileInfo() = directory.GetFiles()
Dim fileNames As IO.FileInfo
Dim basePart1 As BasePart
Dim partLoadStatus1 As PartLoadStatus
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim markId1 As Session.UndoMarkId
Dim partSaveStatus1 As PartSaveStatus
Dim OS_FileName As String = Nothing
Dim write_at As String = "OS_File_Name"
For Each fileNames In directoryFiles
Dim read_at As String = ""
' Start the StopWatch
partWatch.Start()
' ----------------------------------------------
' Menu: File->Open...
' ----------------------------------------------
basePart1 = theSession.Parts.OpenBaseDisplay(path + fileNames.Name, partLoadStatus1)
partLoadStatus1.Dispose()
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Enter Gateway")
workPart = theSession.Parts.Work
workPart.ModelingViews.WorkView.Fit()
' ----------------------------------------------
' Write OS_FileName Attribute
' ----------------------------------------------
Try
OS_FileName = fileNames.Name.Remove(fileNames.Name.Length - 4, 4)
workPart.SetAttribute(write_at, OS_FileName)
Catch ex As Exception
MsgBox(write_at & " : " & OS_FileName & ex.Message)
End Try
' ----------------------------------------------
' Menu: File->Save
' ----------------------------------------------
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.False, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()
' ----------------------------------------------
' Read OS_FileName Attribute
' ----------------------------------------------
Try
read_at = workPart.GetStringAttribute(write_at)
Catch ex As Exception
MsgBox(write_at & " : " & OS_FileName & ex.Message)
End Try
' ----------------------------------------------
' Menu: File->Close->All Parts
' ----------------------------------------------
theSession.Parts.CloseAll(BasePart.CloseModified.CloseModified, Nothing)
workPart = Nothing
displayPart = Nothing
partSaveStatus1 = Nothing
basePart1 = Nothing
partWatch.Stop()
partTime = partWatch.Elapsed
totalPartTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", partTime.Hours, partTime.Minutes, partTime.Seconds, partTime.Milliseconds/10)
My.Computer.FileSystem.WriteAllText (logFileName, "Loaded: " + path + fileNames.Name + Environment.NewLine, True)
My.Computer.FileSystem.WriteAllText (logFileName, "OS_FileName: " + read_at + Environment.NewLine, True)
My.Computer.FileSystem.WriteAllText (logFileName, "Elapse Time: " + totalPartTime + Environment.NewLine + Environment.NewLine, True)
Next
' ----------------------------------------------
' Menu: Tools->Journal->Stop
' ----------------------------------------------
stopWatch.Stop()
value = stopWatch.Elapsed
totalTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", value.Hours, value.Minutes, value.Seconds, value.Milliseconds/10)
My.Computer.FileSystem.WriteAllText (logFileName, Environment.NewLine , true)
My.Computer.FileSystem.WriteAllText (logFileName, "Total Load Time: " + totalTime, true)
End Sub
End Module
Thanks in advance
Carsten