I'm looking for a method to edit properties en masse. I am new to NX but a long time Solid Edge User. In Solid Edge there is a tool call "Property Manager". From there we can edit all associated files from an assembly or from a directory.
What is the best approach to Mass Edit properties in NX? Either via the UI or ever at the OS level.
In NX 9, from an assembly I have found group select, properties, bulk edit... but this appears to limit the properties to edit down to the least common shared Props...?
Solved! Go to Solution.
I'm wondering if you can push updates down via the spreadsheet functions? Open the spreadsheet, import attributes and then push them down the assembly structure.
Maybe Taylor Anderson will pipe in....
Even though your Excel version may not be "officially supported", it will still probably work with NX 9.
I'm not an SE user, but from your description, it sounds like SE offers more options for "bulk editing" than NX does. One option would be to write some custom code to import/add your desired attributes. I'd be glad to help with that if you post or PM some details such as what form your attribute/value list is currently in (text file, spreadsheet, existing part, etc), what to do if the attribute already exists (keep current value, overwrite with new value, etc), what type of report (if any) to give for processed parts, etc etc.
Do you only need to delete part attributes or are you looking to delete other attributes as well (component attributes, feature attributes, body attributes, etc)?
Here's a quick journal that when run will prompt you to select a directory; it will then process all the part files in the directory and attempt to delete the "PG_PART_TYPE" attribute. It isn't heavily tested, I suggest copying several of your files to a new directory for testing, and creating backups of the files that you intend to use it on. It does not check to see if anything else references the attribute before attempting to delete it (such as drafting notes, expressions, or other attributes). It tries to save the file after deleting the attribute, so you will need write access to the folder/files. In its current state, it only processes the folder specified, not any of its subfolders. If desired, you can process subdirectories by passing "True" as the second argument to the "processParts" subroutine.
'Journal to Cycle All Part Files in a specified folder (with option to include subfolders) 'based on 'cyclePartFiles' code example from GTAC ' 'This journal will prompt for a folder (selection dialog) 'then open each file, delete the specified part attribute, and then save & close the file. Option Strict Off Imports System Imports System.IO Imports System.Collections Imports System.Windows.Forms Imports NXOpen Imports NXOpenUI Imports NXOpen.UF Module attribute_deleter Dim theSession As Session = Session.GetSession Dim LW As ListingWindow = theSession.ListingWindow Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display Dim initialPart As Part = theSession.Parts.Display Dim nTotalPartFiles As Integer = 0 Sub Main() Dim strOutputFolder As String LW.Open() Dim FolderBrowserDialog1 As New FolderBrowserDialog ' Change the .SelectedPath property to the default location With FolderBrowserDialog1 ' Desktop is the root folder in the dialog. .RootFolder = Environment.SpecialFolder.Desktop ' Change the following line to default to a given path .SelectedPath = "C:\" ' Prompt the user with a custom message. .Description = "Select the directory to scan" If .ShowDialog = DialogResult.OK Then ' Display the selected folder if the user clicked on the OK button. 'msgbox(.SelectedPath) strOutputFolder = .SelectedPath Else 'user pressed "cancel", exit the journal Exit Sub End If End With LW.WriteLine("Cycle All Parts in a Folder Tree") LW.WriteLine("Start Time: " & CType(TimeOfDay(), String)) LW.WriteLine("") Try processParts(strOutputFolder, False) Catch ex As NXException LW.WriteLine("Cycle Files and Folders Error: " & ex.Message) Exit Sub End Try LW.WriteLine("") LW.WriteLine("Number of part files processed: " & nTotalPartFiles) LW.WriteLine("Stop Time: " & CType(TimeOfDay(), String)) End Sub Sub processParts(ByVal directoryPath As String, ByVal includeSubDirs As Boolean) 'Process All Parts in a specified directory Dim nPartFiles As Integer = 0 Dim part1 As Part = Nothing Dim files() As String 'save the current load options Dim curComponentLoadOption As LoadOptions.LoadComponents = theSession.Parts.LoadOptions.ComponentsToLoad 'set load option to NOT load components theSession.Parts.LoadOptions.ComponentsToLoad = LoadOptions.LoadComponents.None If includeSubDirs Then files = Directory.GetFiles(directoryPath, "*.prt", SearchOption.AllDirectories) Else files = Directory.GetFiles(directoryPath, "*.prt", SearchOption.TopDirectoryOnly) End If For Each fileName As String In files nPartFiles += 1 nTotalPartFiles += 1 LW.WriteLine(" " & Path.GetFileName(fileName)) If (IsNothing(initialPart)) OrElse (initialPart.FullPath <> fileName) Then Try part1 = theSession.Parts.OpenDisplay(fileName, Nothing) Catch ex As NXException LW.WriteLine("open error: " & ex.Message) Catch ex2 As Exception LW.WriteLine("exception: " & ex2.Message) End Try Else 'LW.WriteLine("initial part equals display part: " & initialPart.Equals(displayPart).ToString) part1 = displayPart End If displayPart = theSession.Parts.Display workPart = theSession.Parts.Display 'do something 'write your own subroutines and/or functions to process the part and call them from here DeleteAttribute("PG_PART_TYPE") 'save file Dim partSaveStatus1 As PartSaveStatus partSaveStatus1 = part1.Save(BasePart.SaveComponents.False, BasePart.CloseAfterSave.False) partSaveStatus1.Dispose() 'close file unless this file was initially open If (IsNothing(initialPart)) OrElse (initialPart.FullPath <> fileName) Then part1.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.CloseModified, Nothing) part1 = Nothing workPart = Nothing displayPart = Nothing End If If Not IsNothing(initialPart) Then Dim partLoadStatus1 As PartLoadStatus = Nothing Dim status1 As PartCollection.SdpsStatus status1 = theSession.Parts.SetDisplay(initialPart, False, False, partLoadStatus1) displayPart = theSession.Parts.Display partLoadStatus1.Dispose() theSession.Parts.SetWork(displayPart) workPart = theSession.Parts.Work End If Next fileName 'reset load option theSession.Parts.LoadOptions.ComponentsToLoad = curComponentLoadOption End Sub Sub DeleteAttribute(ByVal attributeTitle As String) 'delete the specified attribute from the work part If theSession.Parts.Work.HasUserAttribute(attributeTi
tle, NXObject.AttributeType.Any, -1) Then Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visi ble, "delete attribute") Dim objects1(0) As NXObject objects1(0) = theSession.Parts.Work Dim attributePropertiesBuilder1 As AttributePropertiesBuilder attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropert iesBuilder(theSession.Parts.Work, objects1, AttributePropertiesBuilder.OperationType.None) attributePropertiesBuilder1.Title = attributeTitle attributePropertiesBuilder1.Delete(theSession.Part s.Work) attributePropertiesBuilder1.Title = "" Dim nXObject1 As NXObject nXObject1 = attributePropertiesBuilder1.Commit() Dim id1 As Session.UndoMarkId id1 = theSession.GetNewestUndoMark(Session.MarkVisibilit y.Visible) Dim nErrs1 As Integer nErrs1 = theSession.UpdateManager.DoUpdate(id1) attributePropertiesBuilder1.Destroy() End If 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
Copy the code above to a text file (use a plain text editor such as Notepad) and save it to a convenient location; be sure to change the file extension from .txt to .vb. To run the journal, go to menu -> tools -> journal -> play... and select the journal file then press the "run" button. This journal does not require you to open a part before running it; and it may actually work better if you don't have any open parts before running it.
@cowski1, thank you very much!
Sincerly appreciate your time and effort!!!
Above and beyond!