Author Topic: Write scripts to run in EA  (Read 2038 times)

Risikat

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Write scripts to run in EA
« on: July 11, 2012, 09:25:45 pm »
Hi,

I can connect to EA through Java

// Import Clases
import org.sparx.Repository;


class ea0 {

   public static void main(String[] args) {      
      // Output some Java Information
      JavaInfo();
        
      //
      OpenRepository();        
    }

    
 /**
  * JavaInfo
 */  
   public static void JavaInfo () {
      PrintHeader("JAVA Runtime information");
      String sTmp0 = System.getProperty("java.class.path");
      
      System.out.println("Java ClassPath = " + sTmp0);
   }
  
  
 /**
  * OpenRepository
 */
   public static void OpenRepository() {
      PrintHeader("Connecting to EA");
      org.sparx.Repository r = new org.sparx.Repository();
    
       r.OpenFile("S:\\risikat.seriki\iVX8000 backup.eap");
    
      System.out.println("Done.");
   }

   public static void PrintHeader (String sMsg) {
      System.out.println("\n#===============================================================================");
      System.out.println("# " + sMsg);
      System.out.println("#===============================================================================");
   }

   public static void PrintSubHeader (String sMsg) {
      System.out.println("\n#-------------------------------------------------------------------------------");
      System.out.println("# " + sMsg);
      System.out.println("#-------------------------------------------------------------------------------");
   }
  
}
This code works.

For the open line function what if you wanted to open from a database instead what would you replace “r.OpenFile("S:\\risikat.seriki\iVX8000 backup.eap");” in the code with.
And how would you go about interrogating EA to extract information from the database, like commands you could write in VB or Java.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13274
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Write scripts to run in EA
« Reply #1 on: July 12, 2012, 04:47:47 pm »
You should really read the documentation of the API before spamming the forum with your questions.
From the documentation of Repository.OpenFile()
Quote
This is the main point for opening an Enterprise Architect project file from an automation client, and working with the contained objects.

If the required project is a DBMS repository, and you have created a shortcut .EAP file containing the database connection string, you can call this shortcut file to access the DBMS repository.

You can also connect to a SQL database by passing in the connection string itself instead of a filename. A valid connection string can be obtained from the Open Project dialog by selecting a recently opened SQL repository.

Parameters:

· Filename: String - the filename of the Enterprise Architect project to open.
 
 
To extract information from the model, either use some kind of visitor, or use Repository.SQLQuery()

Geert