72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
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;
|
|
}
|
|
|
|
} |