NX Journal Create a new model

2019/12/10 categories:NX Journal| tags:NX Journal|Python|

I created a program to create a new model.

Create a “FileNew” object with “FileNew ()” from “theSession”. Then, set the required values for the acquired object.

theSession.Parts.FileNew()

It seems that you need to use “theSession.PdmSession.CreateCreateOperationBuilder ()” when creating a model on Teamcenter.

You can specify the file to use as a template by entering the file path for the template in “TemplatePresentationName”.

Python Code

import NXOpen
import NXOpen.PDM
 
def main():
 
    theSession  = NXOpen.Session.GetSession()
 
    fileNew1 = theSession.Parts.FileNew()
    fileNew1.TemplateFileName = "_TemplateFileName_"
    fileNew1.UseBlankTemplate = False
    fileNew1.ApplicationName = "ModelTemplate"
    fileNew1.Units = NXOpen.Part.Units.Millimeters
    fileNew1.RelationType = "master"
    fileNew1.UsesMasterModel = "No"
    fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
    fileNew1.TemplatePresentationName = "_TemplatePresentationName_"
    fileNew1.ItemType = "Item"
    fileNew1.Specialization = ""
    fileNew1.SetCanCreateAltrep(False)
    fileNew1.MasterFileName = ""
    fileNew1.MakeDisplayedPart = True
    fileNew1.DisplayPartOption = NXOpen.DisplayPartOption.AllowAdditional
 
    partOperationCreateBuilder1 = theSession.PdmSession.CreateCreateOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.Create)
    partOperationCreateBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCreateBuilder.OperationSubType.FromTemplate)
    partOperationCreateBuilder1.SetModelType("master")
    partOperationCreateBuilder1.SetItemType("Item")
    partOperationCreateBuilder1.DefaultDestinationFolder = ":Newstuff"
    partOperationCreateBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCreateBuilder.OperationSubType.FromTemplate)
    partOperationCreateBuilder1.ValidateLogicalObjectsToCommit()
    partOperationCreateBuilder1.CreateSpecificationsForLogicalObjects( [partOperationCreateBuilder1.CreateLogicalObjects()] )
 
    fileNew1.SetPartOperationCreateBuilder(partOperationCreateBuilder1)
 
    fileNew1.Destroy()
    theSession.ApplicationSwitchImmediate("UG_APP_MODELING")
 
if __name__ == '__main__':
    main()

Share post

Related Posts

コメント