Thursday, September 10, 2015

How to export all private or shared projects with or without project definitions from a specified layer

I often have to switch development machines, and when I do, I lose all of my private or shared projects.  This is a good way to backup your projects and/or their definitions.

static void AKExportProjects(Args _args)
    TreeNodeIterator        tni;
    ProjectNode             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');;

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

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

        layer = exportFromLayer.value();
        switch (projectType.value())
            case ProjectSharedPrivate::ProjPrivate:
                tni = SysTreeNode::getPrivateProject().AOTiterator();

            case ProjectSharedPrivate::ProjShared:
                tni = SysTreeNode::getSharedProject().AOTiterator();

        projectNode = as ProjectNode;
        while (projectNode)
            if (projectNode.AOTLayer() == layer)
                projectNode.treeNodeExport(folderName.value() + '\\' + + '.xpo', exportFlag);

            projectNode = as ProjectNode;
        warning("No action taken...");

1 comment:

  1. Wow, what a great post for all the engineers out there especially the software and computer. I must say great skill of coding and arranging such data in a great format. Wonderful!