Create New AOT Project From Template

// // Takes a Template Project Name and a Target Project Name // and automatically creates a new Project from a Template Project. // static void CreateNewAOTProjectFromTemplate(Args _args) {    ProjectNode     templateproject; ProjectNode    pretargetproject; ProjectNode    targetproject;

TreeNode       sharedProject;

UtilElements   utilElement;

str            templateprojectname; str            pretargetprojectname; str            targetprojectname       = 'AATest';

str pretargetprojectname {        return pretargetprojectname; }    ;

// Get the templateprojectname from someplace where the name of a Template project can be found. // NOTE: You'll need to change this Line and assign your own Template name. templateprojectname  = DPA_Parameters::find.AOTProjectTemplate; sharedProject  = SysTreeNode::getSharedProject; if (sharedProject.AOTfindChild(targetprojectname)) return;

// Find the Template Project and load it for inspection templateproject  = sharedProject.AOTfindChild(templateprojectname); if (!templateproject) return; templateproject.loadForInspection;

// Duplicate the Template Project using an intermediary ProjectNode pretargetproject  = templateproject.AOTDuplicate; pretargetproject.AOTsave; // Get the name of the duplicated project - CopyOf%1 (%1 = whatever the Template name is) pretargetprojectname   = pretargetproject.AOTname;

// Rename the duplicated Project to the desired project name. // NOTE: I tried other ways, but this is the only way that worked! //      And, it's fast! ttsbegin; select firstonly forupdate utilElement where utilElement.recordType == UtilElementType::SharedProject && utilElement.name      == pretargetprojectname; if (utilElement) {        utilElement.name = targetprojectname; utilElement.doUpdate; }    ttscommit;

// Have to refresh the SharedProject Node -  Very important! sharedProject.AOTrefresh;

// Now just get the new project and open it. targetproject  = sharedProject.AOTfindChild(targetprojectname); targetproject.AOTrun; }