Showing results for 
Search instead for 
Do you mean 
Solved! Go to solution

NXOpen - Problems with NewPartFromTemplateBuilder and Session.Parts.FileNew

I'm creating an NXOpen application that automatically creates a drawing of the open work part. I'm trying to get the drawing to be created as a child of the original model, be properly named based on a template we have for the purpose, and be a spec file. I've had users journal the creation process several times with different files, the journals are more or less identical every single time, but when I try to adapt the code run dynamically on any part, it fails, always in the same spot in the same way.


I get the following error: "NXopen.NXException: Part is not currently loaded"


It occurs at "nXObject1 = fileNew1.Commit();", the last line of the code I've included at the bottom of this post. If I comment out this line, the rest of the application runs fine. Any idea what my issue is?


Thanks in advance.


Code (C#):


            string TCGNumber;
            string PartNumberNoTCG;
            string RevisionLetter;         

            Session theSession = Session.GetSession();
            Part workPart = theSession.Parts.Work;
            Part displayPart = theSession.Parts.Display;

            string[] SplitFullPath = workPart.FullPath.Split('/');

            TCGNumber = SplitFullPath[0];
            PartNumberNoTCG = TCGNumber.Substring(0,3);
            RevisionLetter = SplitFullPath[1];

            NXOpen.PDM.PartFromTemplateBuilder partFromTemplateBuilder1;
            partFromTemplateBuilder1 = theSession.Parts.PDMPartManager.NewPartFromTemplateBuilder();

(NXOpen.Session.MarkVisibility.Visible, "Start");

            FileNew fileNew1;
            fileNew1 = theSession.Parts.FileNew();

            NXOpen.PDM.PartBuilder.PartFileNameData partInfo1;
            partInfo1 = partFromTemplateBuilder1.AssignPartFileName(workPart.FullPath, RevisionLetter, "specification", TCGNumber + "-" + RevisionLetter + "-" + "DWG1");
(workPart.FullPath, RevisionLetter, "specification", TCGNumber + "-" + RevisionLetter + "-" + "DWG1");

            partFromTemplateBuilder1.CreatePartSpec("RR_Part", TCGNumber, RevisionLetter, "specification", null);

            NXOpen.PDM.DatabaseAttributeManager databaseAttributeManager1;
            databaseAttributeManager1 = partFromTemplateBuilder1.NewDatabaseAttributeManager();

                // The database attribute is not writable
                databaseAttributeManager1.SetAttribute("DB_PART_NAME", "TUBE ASSY AUTOMATION TEST " + PartNumberNoTCG);
            catch (NXException ex)


            fileNew1.TemplateFileName = "@DB/RR_Seed_Part_IN_ASME/E";

            fileNew1.Application = FileNewApplication.Drafting;

            fileNew1.Units = NXOpen.Part.Units.Inches;

            fileNew1.MasterFileName = workPart.FullPath;

            fileNew1.UseBlankTemplate = false;

            fileNew1.MakeDisplayedPart = true;

            NXObject nXObject1;
            nXObject1 = fileNew1.Commit();


Accepted by topic author AndrewLowe
‎08-26-2015 04:32 AM

Re: NXOpen - Problems with NewPartFromTemplateBuilder and Session.Parts.FileNew

[ Edited ]

Do your recorded journals replay correctly? If so, can you post it for comparison?


Are you creating your new file in TC? (it appears you are working with TC given the template name). If so, try echoing back the value of workPart.FullPath, it may not be what you think it is...



The FileNew builder also has a .Validate method, check the return value before you call the .Commit method.

Re: NXOpen - Problems with NewPartFromTemplateBuilder and Session.Parts.FileNew

It was indeed a problem with me not remembering correctly what Part.FullPath returns.


This line:


fileNew1.MasterFileName = workPart.FullPath;

needed to be this:


fileNew1.MasterFileName = "@DB/" + workPart.FullPath;