From ae0c2ed99876fab2faa6f32997b36c7bb7fd04d8 Mon Sep 17 00:00:00 2001 From: eugen Date: Sun, 13 Oct 2024 00:20:33 +0200 Subject: [PATCH] Initialized --- Partname/PARTNAME_NATIV.cs | 72 ++++++++++++++++++++++++++++++++++++++ Partname/PARTNAME_TC.cs | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 Partname/PARTNAME_NATIV.cs create mode 100644 Partname/PARTNAME_TC.cs diff --git a/Partname/PARTNAME_NATIV.cs b/Partname/PARTNAME_NATIV.cs new file mode 100644 index 0000000..d14b128 --- /dev/null +++ b/Partname/PARTNAME_NATIV.cs @@ -0,0 +1,72 @@ +using System; +using NXOpen; +using NXOpen.Assemblies; +using NXOpen.UF; + +/* +Workaround for a pre-NX75 issue where the component names +were kept during a replace component operation. +The code simply compares the comp display name with the +instance name and renames the instance, if necessary. +*/ + + +class rename_component_instances_to_displayname +{ + static Session s = Session.GetSession(); + static UFSession ufs = UFSession.GetUFSession(); + static ListingWindow lw = s.ListingWindow; + + public static void Main() + { + + lw.Open(); + Component root = s.Parts.Display.ComponentAssembly.RootComponent; + + reportComponentChildren(root, 0); + } + + public static void reportComponentChildren(Component comp, int indent) + { + // Component child = null; + string space = null; + Part c_part = null; + + for (int ii = 1; ii <= indent; ii++) space = space + " "; + + foreach (Component child in comp.GetChildren()) + { + string part_name; + string refset_name; + string instance_name; + double[] origin = new double[3]; + double[] csys_matrix = new double[9]; + double[,] transform = new double[4,4]; + + ufs.Assem.AskComponentData( + child.Tag, + out part_name, + out refset_name, + out instance_name, + origin, + csys_matrix, + transform); + + lw.WriteLine(space + "Name: " + child.Name + " Display: " + child.DisplayName + " Instance: " + instance_name); + if( child.DisplayName != instance_name ) + { + lw.WriteLine(space + " -> renaming instance to " + child.DisplayName); + Tag instance_tag = ufs.Assem.AskInstOfPartOcc(child.Tag); + ufs.Assem.RenameInstance(instance_tag, child.DisplayName); + } + + reportComponentChildren(child, indent + 1); + } + } + + public static int GetUnloadOption(string dummy) + { + return (int)Session.LibraryUnloadOption.Immediately; + } + +} \ No newline at end of file diff --git a/Partname/PARTNAME_TC.cs b/Partname/PARTNAME_TC.cs new file mode 100644 index 0000000..0075fe6 --- /dev/null +++ b/Partname/PARTNAME_TC.cs @@ -0,0 +1,72 @@ +using System; +using NXOpen; +using NXOpen.Assemblies; +using NXOpen.UF; + +/* +Workaround for a pre-NX75 issue where the component names +were kept during a replace component operation. +The code simply compares the comp display name with the +instance name and renames the instance, if necessary. +*/ + + +class rename_component_instances_to_displayname +{ + static Session s = Session.GetSession(); + static UFSession ufs = UFSession.GetUFSession(); + static ListingWindow lw = s.ListingWindow; + + public static void Main() + { + + lw.Open(); + Component root = s.Parts.Display.ComponentAssembly.RootComponent; + + reportComponentChildren(root, 0); + } + + public static void reportComponentChildren(Component comp, int indent) + { + // Component child = null; + string space = null; + Part c_part = null; + + for (int ii = 1; ii <= indent; ii++) space = space + " "; + + foreach (Component child in comp.GetChildren()) + { + string part_name; + string refset_name; + string instance_name; + double[] origin = new double[3]; + double[] csys_matrix = new double[9]; + double[,] transform = new double[4,4]; + + ufs.Assem.AskComponentData( + child.Tag, + out part_name, + out refset_name, + out instance_name, + origin, + csys_matrix, + transform); + + lw.WriteLine(space + "Name: " + child.Name + " Display: " + child.DisplayName + " Instance: " + instance_name); + if( child.DisplayName != instance_name ) + { + lw.WriteLine(space + " -> renaming instance to " + child.DisplayName.Remove(child.DisplayName.IndexOf("/"))); + Tag instance_tag = ufs.Assem.AskInstOfPartOcc(child.Tag); + ufs.Assem.RenameInstance(instance_tag, child.DisplayName.Remove(child.DisplayName.IndexOf("/"))); + } + + reportComponentChildren(child, indent + 1); + } + } + + public static int GetUnloadOption(string dummy) + { + return (int)Session.LibraryUnloadOption.Immediately; + } + +} \ No newline at end of file