Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: rmonangi on December 27, 2012, 10:00:29 am
-
How can we automate the publishing of models stored in the EA Sparx repository as HTML pages to an internal web server on a daily basis (so that non Sparx users can access the models from a browser)?
-
Create a task in the Windows Scheduler running a script that creates an instance of EA, connects to the model and runs a HTML report.
The main tricks are ensuring that the user you run on has permission to create COM objects and has a license for EA set up.
-
Are there any sample/example script you can share that can be used as a starting point?
-
There are code samples in the EA directory.
There are (a couple of) samples in the help.
A number of people have provided samples on the community site.
-
I am currently working on the same topic for my project: we would like to have a nightly HTML generation.
Unfortunately, even though I was searching for "RunHTMLReport"
- I don't find any explanation / examples on the forum neither in the EA Help
- I don't find any related code in the EA installation directory
I do found a little piece of code while searching the net: http://stackoverflow.com/questions/221654/how-to-automate-the-generation-of-html-output-in-enterprise-architect
Hence I was able to create this little script, but I am stuck on the PackageGUID (as now it renders an almost empty webpage and no XML files with content are in the directories). I found the used ID string in the XMI export...
Even using a local file on my C drive does not give me more, so may be the SQL connection string is not correct either as I was not able to test this yet...
FYI, we created a web style template "value chain" as well (4th parameter of the function).
import org.sparx.Repository;
public class valuecircle2html {
public static void main(String[] args) {
org.sparx.Repository r = new org.sparx.Repository();
r.OpenFile("SparxEa --- DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SparxEa;Data Source=SS-BXL-DBSQL10");
r.GetProjectInterface().RunHTMLReport("<packagedElement xmi:type=\"uml:Package\" xmi:id=\"EAPK_3C05F74F_D0A2_4a18_A38B_A32E95896923\" name=\"Value Circle\" visibility=\"public\">", "C:\\Users\\usjolb\\Desktop\\export", "PNG", "Value Circle", ".htm");
r.CloseFile();
}
}
Please help! :-/ :'(
-
No, that packageGUID format is definitely wrong.
What you should do is first use the repository object to get the package you want to report on.
If it is one of the root packages then you can use Repository.Models to select the one you need.
Once you have the package object you get its GUID using Package.PackageGUID.
Now in most cases that is the one you need, except when using the project interface. Then you need the GUID in xml format.
To convert a regular GUID into an xml-GUID you can use Project Interface.GUIDtoXML()
Geert
-
Hi rmonangi,
I posted this a while back http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1351579060/2#2 with limited response.
So had to teach myself VB and how to build exe's and got a little help from a mate. Here is my code set in VB
=============================================
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Imports System.Threading
Imports System.Configuration
Imports System.Diagnostics
Imports EA
Module Module1
Sub Main()
ShowRepository()
End Sub
Public Sub ShowRepository()
Dim EA As New EA.Repository
Dim SQL As String
SQL = "Insert Your SQL String"
EA.OpenFile(SQL)
EA.GetProjectInterface().RunHTMLReport(PackageGUID:="{Insert Your GUID - Make Sure you have the brackets}", ImageFormat:="PNG", ExportPath:="Your Path", Style:="<default>", Extension:=".htm")
EA.Exit()
End Sub
End Module
=============================================
As simon mention a EA key needs to be assigned to the User and they need a SQL DB account set up too.
I have the exe running on a schedule task but the user has to be logged on, but I might look into the post from Simon to see I can get it to run without being logged on.
Hope this helps
Stoppy ;)
-
Just FYI, this is how we did it here (I only have some Java knowledge from yeeeeeaaars ago at school, but it does the trick :) ).
import org.sparx.*;
public class valuecircle2html {
public static void main(String[] args) {
org.sparx.Repository repo = new org.sparx.Repository();
org.sparx.Package corporate = null;
org.sparx.Package bpm = null;
org.sparx.Package bpm_vc = null;
org.sparx.Package vc = null;
org.sparx.Package pack = null;
// Connect to database
String conn = "SparxEa --- DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SparxEa;Data Source=SS-BXL-DBSQL10";
repo.OpenFile(conn);
// Browse through structure
corporate = repo.GetModels().GetByName("Corporate");
bpm = corporate.GetPackages().GetByName("BPM");
bpm_vc = bpm.GetPackages().GetByName("BPM Value Circle)");
vc = bpm_vc.GetPackages().GetByName("Value Circle");
// Generate HTML Documentation
String guid = "" + vc.GetPackageGUID() + "";
String tmppath = "C:\\Users\\usjolb\\Desktop\\export";
String image = "PNG";
String template = "Value Circle";
String ext = ".htm";
repo.GetProjectInterface().RunHTMLReport(guid, tmppath, image, template, ext);
// Close connection to database
repo.CloseFile();
}
}
The connection string is easy to find by right clicking the project in the popup when starting EA.
We have a few models, my required package is in the "Corporate" model, then browsing through a few package directories until you got at the one you would be right clicking on when doing it yourself.
The tmppath is just to publish this locally (afterwards I have a scheduled bat-file that runs the java program and copy pastes the HTML files to our SharePoint).
The template is a copy of the default web template with a few modifications, called "Value Circle".
Hopefully it helps you, I would have been happy to find that kind of script when I was looking for it :)
-
Create a task in the Windows Scheduler running a script that creates an instance of EA, connects to the model and runs a HTML report.
The main tricks are ensuring that the user you run on has permission to create COM objects and has a license for EA set up.
Hi Simon,
We have our application running with the task scheduler, the task has to be set to logged on user and the user has to be logged onto the server at all times.
When we attempt to run the application running the task scheduler with the the user logged off, the application fails.
Do you have any suggestion or solution to this?
Stoppy
-
The two most common causes of that (as far as I know) are:
- Windows not allowing the user the script is running as to create COM objects.
- The user it is running as does not have a license for EA set up.
-
Hi Simon,
Thanks for the reply.
It is definately not item number 2.
I am not a techie, but if you could supply some reference documents/sites or further details for item 1 this would be appreciated.
Regards,
Stoppy
-
I am not sure how big your repos usually are, but the one I wanted to automate is quite big. I found that generating the HTML straight out of the DB was extremely slow. Instead I do a project transfer from DBMS to local EAP, and html the local file.
I cobbled my code together quickly borrowing snippets of code from all over the internet, so there are potentially even more improvements that could be made. (Not claiming ownership of this code, but it works which is all I cared about)
I thought I would share for the next person that could use a C# implementation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EA;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
EA.Repository repo = new EA.Repository();
EA.Package package = null;
// PARAMETERS !!!UPDATE THESE!!!
String conn = "Enterprise_Architect --- DBType=1... etc"; //PUT WHOLE SQL STRING IN
String username = "user";
String password = "pass";
//Transfer DBMS to EAP
String eapfile = "C:\\Temp\\html\\model.eap";
String eaplog = "C:\\Temp\\html\\transfer_log.log";
repo.GetProjectInterface().ProjectTransfer(conn, eapfile, eaplog);
// Browse through structure
repo.OpenFile2(eapfile, username, password);
package = repo.GetPackageByGuid("{HARDCODED_GUI}"); //I PUT MY NODE GUI HERE TO GET WHOLE MODEL
// Generate HTML Documentation
String guid = "" + package.PackageGUID + "";
String tmppath = "C:\\Temp\\html";
String image = "PNG";
String template = "Feedback";
String ext = ".htm";
repo.GetProjectInterface().RunHTMLReport(guid, tmppath, image, template, ext);
// Close connection to database
repo.CloseFile();
}
}
}
-
Is it possible using RunHTMLReport to specify a head graphic and title as you can on the html gen dialogue within Sparx itself ?
Regards,
Jon.
-
I haven't looked at this in a while, I think this is how I got it to work for the graphic. I suspect it's because it saves the image location in the registry.
I generate the website once interactively and set the 'Header Image' to point to my custom header and use my customized 'Style'. Running the job from the scheduler after that picks up the last used graphic assuming you have set the 'Style' to your custom one.
Stan.
-
Tried this and it doesn't appear to work; so i've copied my gif over the ea.gif in the images folder - not the most elegant solution - but seems to work.
-
Hello Stoppy,
Dit you get this to work already? I am having the same problem. When I have the "Run only when user is logged on" flag turned on in the Windows (2008) scheduler everything works fine. When I turn this off the application seem to get stuck. No output, nothing and the task doesn't end either.
Regards,
MBrandt
Hi Simon,
Thanks for the reply.
It is definately not item number 2.
I am not a techie, but if you could supply some reference documents/sites or further details for item 1 this would be appreciated.
Regards,
Stoppy
-
I finally had a need to review my old stuff. To get a custom header into the html published from the api with RunHTMLReport the registry key "HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\options\WEBDIRHEADERIMAGE" needs to be set to the path of the image file. The path should be exactly as typed in when generating manually.
I built a wrapper for RunHTMLReport callable from a batch file with the image header as a parameter. The function to update the registry is below (v10.0.1008).
private void SetHeaderImage(EA.Repository repository, InputParameters parms)
{
RegistryKey headerImageKey = Registry.CurrentUser.OpenSubKey("Software\\Sparx Systems\\EA400\\EA\\options", true);
headerImageKey.SetValue("WEBDIRHEADERIMAGE", parms.HeaderImage);
}
Stan.
-
Hello Stoppy,
Dit you get this to work already? I am having the same problem. When I have the "Run only when user is logged on" flag turned on in the Windows (2008) scheduler everything works fine. When I turn this off the application seem to get stuck. No output, nothing and the task doesn't end either.
Regards,
MBrandt
Hi Simon,
Thanks for the reply.
It is definately not item number 2.
I am not a techie, but if you could supply some reference documents/sites or further details for item 1 this would be appreciated.
Regards,
Stoppy
Not sure I can help, but maybe point out in right direction.
Have the exact same problem, and me and my colleague spent weeks in this issue. Everything from modifying user rights, to COM launching rights, etc, etc.
First it just "stopped" was because a user not logged in couldnt find the license file properly. It just stopped, since EA expects user inputs in prompting location of the license file.
Now it just stops of some other reason, and I'm pretty sure it requires some other user input, that I dont understand.
We simply gave this up by now, and living with the fact that the automation server needs a logged in user, until someone else figures it out...;-)
So - My best guess is that EA in the automation requires some user input, since I know for sure that for my case it results in "just stopping"...
If you guys finds it ... please let me know..
regards
Andreas
-
The suggestion above will generate either a fixed package identified by it's guid or a complete model.
For my solution, I used a tagged value to determine which package to take as a root. The app will scan the complete repository and only report the package(s) where rhrExport is defined to be 'true'.
Tagged values could also be used to determine other parameters used for RunHTMLReport like the path or template to use.
-
Hi MBrandt,
Sorry about the late reply.
Posted by: Andreas1975 Posted on: Aug 13th, 2013, 2:54pm
We simply gave this up by now, and living with the fact that the automation server needs a logged in user, until someone else figures it out...
This was my end game too.
The only issue I have now is when the Server Admins restart my box due to MS Updates or virtual machine shuffling and don't log my dedicated user back on to the server.
Regards,
Stoppy :D