Altova MapForce 2023 Enterprise Edition

El siguiente fragmento de código en JScript muestra cómo abrir documentos, convertir un documento en el documento activo, iterar los documentos abiertos y cerrar documentos.

 

// Initialize application's COM object. This will start a new instance of the application and
// return its main COM object. Depending on COM settings, a the main COM object of an already
// running application might be returned.
try {   objMapForce = WScript.GetObject("", "MapForce.Application");   }
catch(err) {}
 
if( typeof( objMapForce ) == "undefined" )
{
  try   {   objMapForce = WScript.GetObject("", "MapForce_x64.Application")   }
  catch(err)
  {
     WScript.Echo( "Can't access or create MapForce.Application" );
     WScript.Quit();
  }
}
 
// if newly started, the application will start without its UI visible. Set it to visible.
objMapForce.Visible = true;
 
// **************************** code snippet for "Simple Document Access" ************************
 
// Locate examples via USERPROFILE shell variable. The path needs to be adapted to major release versions.
objWshShell = WScript.CreateObject("WScript.Shell");
majorVersionYear = objMapForce.MajorVersion + 1998
strExampleFolder = objWshShell.ExpandEnvironmentStrings("%USERPROFILE%") + "\\Documents\\Altova\\MapForce" + majorVersionYear + "\\MapForceExamples\\";
 
objMapForce.Documents.OpenDocument(strExampleFolder + "CompletePO.mfd");
//objMapForce.Documents.OpenDocument(strExampleFolder + "Altova_Hierarchical_DB.mfd");
objMapForce.Documents.NewDocument();
 
// **************************** code snippet for "Simple Document Access" ************************
 
// **************************** code snippet for "Iteration" ************************************
 
objText = "";
// go through all open documents using a JScript Enumerator and generate c++ code
for (var iterDocs = new Enumerator(objMapForce.Documents); !iterDocs.atEnd(); iterDocs.moveNext())
{
  objText += "Generated c++ code result for document " + iterDocs.item().Name + " :\";
  objErrorMarkers = iterDocs.item().generateCodeEx(1); // ENUMProgrammingLanguage.eCpp = 1
 
  bSuccess = true;
  for (var iterErrorMarkers = new Enumerator(objErrorMarkers); !iterErrorMarkers.atEnd(); iterErrorMarkers.moveNext())
  {
     bSuccess = false;
     objText += "\t" + iterErrorMarkers.item().Text + "\";
  }
 
  if (bSuccess)
      objText += "\tCode generation completed successfully.\";
     
  objText += "\";
}
 
WScript.Echo(objText);
 
// go through all open documents using index-based access to the document collection
for (i = objMapForce.Documents.Count; i > 0; i--)
  objMapForce.Documents.Item(i).Close();
 
 
// **************************** code snippet for "Iteration" ************************************
 
//objMapForce.Visible = false;      // will shutdown application if it has no more COM connections
objMapForce.Visible = true;   // will keep application running with UI visible

 

El fragmento de código anterior está disponible como archivo de ejemplo (véase Ejemplos en JScript). Para ejecutar el script, inícielo desde la línea de comandos o desde el explorador de Windows.

© 2017-2023 Altova GmbH