Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export assembly as single part (collection of solid bodies without parameters) python 1

Status
Not open for further replies.

Guttikar

Automotive
Dec 7, 2021
11
0
0
IN
Hello,

I am trying to export an assembly as a single part - I need this to run a journal that performs Boolean operations on the solid bodies in the assembly (which can be done only if the solid bodies are subparts of the same part). I tried using NXOpen.UF.Part.ExportWithOptions but that doesn't work with assemblies.

Is there a way to do this?
 
Replies continue below

Recommended for you

You should be able to 'Promote' all of the Components into the Assembly part file as Solid Bodies. Then break all of the links and delete the Components and you should have what you want.

John R. Baker, P.E. (ret)
EX-'Product Evangelist'
Irvine, CA
Siemens PLM:
UG/NX Museum:

The secret of life is not finding someone to live with
It's finding someone you can't live without
 
Hi @John R. Baker,

Thanks for your input. I tried to do it but I was getting an error saying promoting is disabled in customer defaults. I tried to go to preference>customerDefaults to change the setting but couldn't find anything there to change that would allow me to promote. Could you explain how to do this?
 
Hi Ehaviv and TheTick,
Thanks for your input. But file > export > Part does not get recorded with the record journal button so I need to know the API to use to do this programmatically.
 
The code below doesn't do much error checking, but it shows the overall process.

Code:
#
import NXOpen
import NXOpen.UF

theSession = NXOpen.Session.GetSession()
theUfSession = NXOpen.UF.UFSession.GetUFSession()
theLw = theSession.ListingWindow
    
def AskAllBodies(thePart):

    NULLTAG = 0
    objectTag = 0
    theBodies = []

    objectTag = theUfSession.Obj.CycleObjsInPart(thePart.Tag, NXOpen.UF.UFConstants.UF_solid_type, objectTag)

    while objectTag != NULLTAG:
        objType = 0
        objSubType = 0

        objType, objSubType = theUfSession.Obj.AskTypeAndSubtype(objectTag)
        if objSubType == NXOpen.UF.UFConstants.UF_solid_body_subtype:   
            nxBody = NXOpen.TaggedObjectManager.GetTaggedObject(objectTag)
            theBodies.append(nxBody)
        objectTag = theUfSession.Obj.CycleObjsInPart(thePart.Tag, NXOpen.UF.UFConstants.UF_solid_type, objectTag)
        
    return theBodies

def PartExport(exportFileName, theBodies):

    options = NXOpen.UF.Part.ExportOptions()
    options.NewPart = True
    options.ParamsMode = NXOpen.UF.Part.ExportParamsMode.REMOVE_PARAMS
    
    objTags = []
    for x in theBodies:
        objTags.append(x.Tag)
    
    theUfSession.Part.ExportWithOptions(exportFileName, len(objTags), objTags, options)


def main(): 
    
    theLw.Open()
    
    if theSession.Parts.Work is None:
        #no active part
        theLw.WriteLine("no active part")
        return

    undoMarkName = "export assembly bodies"
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, undoMarkName)
    
    asmBodies = AskAllBodies(theSession.Parts.Display)
    PartExport("C:\\temp\\export_test.prt", asmBodies)

    
    theLw.Close()
    
    
if __name__ == '__main__':
    main()

www.nxjournaling.com
 
Guttikar said:
I tried to do it but I was getting an error saying promoting is disabled in customer defaults. I tried to go to preference>customerDefaults to change the setting but couldn't find anything there to change that would allow me to promote.

Customer defaults -> assemblies -> general -> interpart modeling -> allow promote body
The exact location may depend on the version of NX you are running.

If the allow promote body option is turned off and you cannot (or don't want to) turn it on, you can use wave linking to copy the bodies up to the assembly level and then unite them. Wave linking is very similar to promote body.

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top