Export all private or shared projects with or without project definitions from a specified layer

Export all private or shared projects with or without project definitions from a specified layer

See more : http://www.alexondax.com/2015/09/how-to-export-all-private-or-shared.html

static void AKExportProjects(Args _args)
{
    #AotExport
    TreeNodeIterator        tni = SysTreeNode::getPrivateProject().AOTiterator();
    ProjectNode             projectNode = tni.next() as ProjectNode;
    int                     exportFlag;
    Dialog                  dialog = new Dialog();
    DialogField             folderName;
    DialogField             projectDefinitionOnly;
    DialogField             exportFromLayer;
    DialogField             projectType;
    UtilEntryLevel          layer;

    dialog.addText("This will export all projects (shared or private) that exist in a selected model.");
    projectType             = dialog.addFieldValue(enumStr(ProjectSharedPrivate), ProjectSharedPrivate::ProjPrivate);
    projectDefinitionOnly   = dialog.addField(extendedTypeStr(NoYesId), 'Project Definition Only');
    folderName              = dialog.addField(extendedTypeStr(FilePath));
    exportFromLayer         = dialog.addField(enumStr(UtilEntryLevel), 'Projects from layer');

    dialog.run();

    if (dialog.closedOk())
    {
        if (!folderName.value())
            throw error("Missing folder");

        exportFlag = #export;
        if (projectDefinitionOnly.value())
            exportFlag += #expProjectOnly;

        layer = exportFromLayer.value();
        while (projectNode)
        {
            if (projectNode.AOTLayer() == layer)
                projectNode.treeNodeExport(folderName.value() + '\\' + projectNode.name() + '.xpo', exportFlag);
            
            projectNode = tni.next() as ProjectNode;
        }
    }
    else
        warning("No action taken...");
}