Showing results for 
Search instead for 
Do you mean 

Editing component name

If you a big assembly with a particular component throughout the assembly at al levels. Is there a way to set the Component name so that it reads the same throught the entire assembly?


Re: Editing component name

Here is the code in C#.


using System;
using NXOpen;
using NXOpen.Assemblies;
using NXOpen.UF;

class renameSelectedComponentAllLevels
    static Session s = Session.GetSession();
    static UFSession ufs = UFSession.GetUFSession();
    static ListingWindow lw = s.ListingWindow;

    public static void Main()

        Component root = s.Parts.Display.ComponentAssembly.RootComponent;

        Component theComponent = null;
        string newName;

        theComponent = SelectAComponent("Select Component to Rename");
        if (theComponent != null)
            newName = theComponent.Name;

            if (getStringInput("New Name", ref newName))
                renameComponentChildren(root, theComponent, newName);


    public static void renameComponentChildren(Component comp, Component theComponent, string newName)

        foreach (Component child in comp.GetChildren())

            if (child.Prototype == theComponent.Prototype)

            renameComponentChildren(child, theComponent, newName );

    public static NXOpen.Assemblies.Component SelectAComponent(string prompt)
        TaggedObject selobj = null;
        Point3d cursor = default(Point3d);
        Selection.MaskTriple[] comps = { new Selection.MaskTriple(UFConstants.UF_component_type, 0, 0) };

        Selection.Response resp = UI.GetUI().SelectionManager.SelectTaggedObject(prompt, "Select a component",
            Selection.SelectionScope.AnyInAssembly, Selection.SelectionAction.ClearAndEnableSpecific, false, false, comps, out selobj, out cursor);

        return (NXOpen.Assemblies.Component)selobj;

    static bool getStringInput(string prompt, ref string inputString)
        int n = 0;
        int resp;

        NXOpen.UF.UFSession ufs = UFSession.GetUFSession();


        resp = ufs.Ui.AskStringInput(prompt, ref inputString, out n);


        if (resp == 3 || resp == 5)
            return true;
            return false;


    public static int GetUnloadOption(string dummy)
        return (int)Session.LibraryUnloadOption.Immediately;