CS_NXOpen_0011_MoveBodies2Components



using System;
using NXOpen;
using NXOpen.UF;

public class NXJournal
{
    static Session theSession = Session.GetSession();
    static UFSession theUFSession = UFSession.GetUFSession();
    static Part workPart = theSession.Parts.Work;

    public static void Main(string[] args)
    {
        // Move multiple bodies from Assembly level into an individual components

        theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Body Components");

        bool nxMan = false;
        theUFSession.UF.IsUgmanagerActive(out nxMan);

        string tmp_dir = null;
        theUFSession.UF.TranslateVariable("UGII_TMP_DIR", out tmp_dir);

        double[] origin = { 0.0, 0.0, 0.0 };
        double[] csys = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };

        int unitFlag = UFConstants.UF_PART_ENGLISH;
        if (workPart.PartUnits.Equals(BasePart.Units.Millimeters)) unitFlag = UFConstants.UF_PART_METRIC;

        foreach (Body aBody in workPart.Bodies.ToArray())
        {
            string compName = null;
            string tpn = null;
            theUFSession.Cfi.GetUniqueFilename(out tpn);
            if (nxMan) compName = "@DB/" + tpn + "/A";
            else compName = tmp_dir + "\\" + tpn;

            Tag instance = Tag.Null;
            theUFSession.Assem.CreateComponentPart(workPart.Tag, compName, null, null, unitFlag,
                0, origin, csys, 1, new Tag[] { aBody.Tag }, out instance);

        }

        theUFSession.Modl.Update();

    }

  
    public static int GetUnloadOption(string arg)
    {
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
    }
}

Comments