Remove all payloads from flattened scene

I want to remove all payloads from a usd stage and write a flattened layer for debugging. I saw previous topics on this but wasn’t convinced this was a bad idea. This function eliminates 90% of the payloads but not all of them. Does this need a change in my understanding or a change in the code (or both)?

def minibake(src, dst):
    stage = Usd.Stage.Open(src)
    clobber = []
    for prim in stage.TraverseAll():
        for spec in reversed(prim.GetPrimStack()):
            if spec.payloadList.GetAddedOrExplicitItems():
                clobber.append(spec)

    for spec in reversed(clobber):
        spec.payloadList.ClearEditsAndMakeExplicit()
        spec.payloadList.explicitItems = []

    stage.Flatten().Export(dst)
1 Like

I think it would be much easier to just open the stage with nothing loaded (InitialLoadSet::LoadNone), and then export it? (You can call Stage.Export() directly - it will flatten for you!)