Remove/release xrefs that are not active when baking

Hi! Is it possible to remove/release the xrefs that are unactive of that setup when baking/exporting to max files? Right now It’s exporting every scene with all the xrefs, instead of only the active ones… :frowning:

1 Like

I ended up coding a new full bake that stores all xref disabled/enabled info, removes them, saves new file and recover the xrefs, and it works pretty good, altho the ‘recover xrefs’ part is pretty slow, so maybe i should just reopen the file instead, but i think pulze interrupts on new file open. Idk, i’d have to test it out, but anyways, these functions worked on the enable/disable remove/recover xrefs:

-- Function to capture and remove all disabled XRef scenes
fn captureAndRemoveDisabledXRefs =
(
    print "Capturing XRefs..."
    local enabledXRefs = ""
    local disabledXRefs = ""
    removedXRefInfo = #()
    local xrefSceneCount = xrefs.getXRefFileCount()
    for i = xrefSceneCount to 1 by -1 do
    (
        local xrefScene = xrefs.getXRefFile i
        if xrefScene.disabled then
        (
            append removedXRefInfo #(xrefScene.filename, xrefScene.disabled)
            disabledXRefs += xrefScene.filename + "\n"
            delete xrefScene
        )
        else
        (
            enabledXRefs += xrefScene.filename + "\n"
        )
    )
    print ("Enabled XRefs:\n" + enabledXRefs)
    print ("Disabled XRefs:\n" + disabledXRefs)
    print "Removing disabled XRefs..."
)

-- Function to restore only the removed XRef scenes
fn restoreRemovedXRefScenes =
(
    print "Restoring disabled XRefs..."
    for xrefInfo in removedXRefInfo do
    (
        local filename = xrefInfo[1]
        local wasDisabled = xrefInfo[2]
        local newXrefScene = xrefs.addNewXRefFile filename
        newXrefScene.disabled = wasDisabled
    )
)