Showing posts with label Export. Show all posts
Showing posts with label Export. Show all posts

Tuesday, 22 May 2018

Export label files X++

Following job can be used to export multiple label files of a particular language to a folder. There is an option to save the files as a different language file as well (in case the files are to be used for translation or to be imported as different language)

static void LabelFileExport(Args _args)
{
    #File

    SysLabelFile    sysLabelFile;
    str             labelModule, labelFileName, labelLanguage;
    str             labelSaveAsLanguage, labelSaveAsFileName;
    container       labelModuleCon;
    int             i;
    FilePath        path;
    FileName        fileName;

    path                = @"D:\TempNav\LabelFiles"; // folder to export to
    labelModuleCon      = str2con("ASC,ASG"); // labels to export
    labelLanguage       = "en-us";
    labelSaveAsLanguage = "en-za"; // set as "" to export with original language name

    if (!strEndsWith(path, #FilePathDelimiter))
    {
        path += #FilePathDelimiter;
    }
    info(strFmt("Export path: %1", path));

    for (i = 1; i <= conLen(labelModuleCon); i++)
    {
        labelModule = conPeek(labelModuleCon, i);

        try
        {
            labelFileName = strFmt("Ax%1%2.ald", labelModule, labelLanguage);

            if (labelSaveAsLanguage != "")
            {
                labelSaveAsFileName = strFmt("Ax%1%2.ald", labelModule, labelSaveAsLanguage);
                fileName = path + labelSaveAsFileName;
            }
            else
            {
                fileName = path + labelFileName;
            }

            sysLabelFile = SysLabelFile::newFilename(labelFileName);
            sysLabelFile.toFile(fileName);

            if (labelSaveAsLanguage != "")
            {
                info(strFmt("Successfully exported label file %1 as %2", labelFileName, labelSaveAsFileName));
            }
            else
            {
                info(strFmt("Successfully exported label file %1", labelFileName));
            }
        }
        catch
        {
            info(strFmt("Failed to export label file %1", labelFileName));
        }
    }
}

This posting is provided "AS IS" with no warranties. Use code at your own risk.

Friday, 6 September 2013

Export all shared projects

Following code exports all projects in the Shared node. For each run it creates a new folder and then the projects are individually exported to xpo.

static void ExportAllProjects(Args _args)  
{  
 ProjectNode      sharedProject = Infolog.projectRootNode().AOTfindChild("Shared");  
 TreeNodeIterator   treeIterator;  
 TreeNode        childNode;  
 str           folderPath = @"C:\\AXProjects\\";  
 str           folderName;  
 System.DateTime    dateTime = DateTimeUtil::newDateTime(systemDateGet(), timeNow());  

 void exportProject(TreeNode _projectNode)  
 {  
  FileIoPermission   perm;  
  str           exportFileName;  

  if(_projectNode != null)  
  {  
   exportFileName = folderPath + folderName + "\\" + _projectNode.AOTname() + ".xpo";  
   perm = new FileIoPermission(exportFileName, "W");  
   perm.assert();  
   _projectNode.treeNodeExport(exportFileName);  
   CodeAccessPermission::revertAssert();  
  }  
 }  

 folderName = dateTime.ToString("yyyyMMdd_HHmmss");  

 if(sharedProject)  
 {  
  treeIterator = sharedProject.AOTiterator();  

  if(treeIterator)  
  {  
   if(!WinAPI::pathExists(folderPath + folderName))  
   {  
    info(strFmt('Creating the folder %1', folderPath + folderName));  
    WinAPI::createDirectoryPath(folderPath + folderName);  
   }  

   childNode = treeIterator.next();  
   while (childNode)  
   {  
    info(strFmt('Exporting %1', childNode.AOTname()));  
    exportProject(childNode);  

    childNode = treeIterator.next();  
   }  
  }  

  sharedProject.treeNodeRelease();  
 }  
}  

This posting is provided "AS IS" with no warranties. Use code at your own risk.