Problem
To refresh all UML Diagrams within an Formal Doors Module, a script is needed that imports all actual versions of a UML Diagram.
Approach
* Copy the GUID of the Diagram / Note
** right-click the project menu on the right side.
** Select „Copy Reference -> Copy Node GUID to clipboard“
* If not done before, create an Module attribute (here ATTRIBUT_WITH_GUID)
* Paste the GUID to the place in your doors module, where the diagram should be created
Solution
// Recommended as module plugin /** * Run through all objects of the current module * and watch for the attribute ATTRIBUT_WITH_GUID. * If it is not empty, fetch the diagram/note * from this attribute an load it into the * Object Text of Sparx Systems Enterprise Architect */ Object o Filter currentFilter, f Module m DB updateWin string guid string projectPath = "DP_ENTARCHITECT --- DBType=1;" //- "Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;" //- "Persist Security Info=False;Initial Catalog=DBNAME;" //- "Data Source=EA_DB_SERVER" OleAutoObj eaProject, eaRepository, diaObj, actObj OleAutoArgs autoArgs = create string diagramName, elementNotes void establishInterface() { eaProject = oleGetAutoObject("EA.Project") if(null(eaProject)) { eaProject = oleCreateAutoObject("EA.Project") } if(null(eaProject)) { ack "Creating OLE-Object 'EA.Project' not possible." progressStop halt } eaRepository = oleGetAutoObject("EA.Project") if(null(eaRepository)) { eaRepository = oleCreateAutoObject("EA.Repository") } if(null(eaRepository)) { ack "Creating OLE-Object 'EA.Repository' not possible." progressStop halt } put(autoArgs,projectPath) oleMethod(eaRepository,"OpenFile",autoArgs) clear(autoArgs) } void closeInterface() { oleMethod(eaRepository,"CloseFile",autoArgs) oleMethod(eaRepository,"Exit",autoArgs) delete(autoArgs) } void updateObjects() { int progessbarStep = 0 bool diagramCopied string fileName for o in m do { guid = o."BB_ImageFileName" diagramCopied = false if(guid != "" && guid[0:0] == "{") { progressMessage("Updating " identifier(o)) put(autoArgs, guid) /************************************************** * Gets a pointer to a diagram using an absolute * reference number (local ID). This is usually * found using the DiagramID property of an * element, and stored for later use to open a diagram * without using the * collection GetAt() function. **************************************************/ oleMethod(eaRepository, "GetDiagramByGuid", autoArgs, diaObj) /************************************************* * An Element is the main modeling unit. * It corresponds to (for example) a Class, * Use Case, Node or Component. * You create new elements by adding to the * Package Elements collection. * Once you have created an element, you can add it * to the DiagramObject * Class of a diagram to include it in the diagram. ****************************************************/ oleMethod(eaRepository, "GetElementByGuid", autoArgs, actObj) clear(autoArgs) // Wenn das Diagramm mit der GUID nicht gefunden wurde if(null(diaObj)) { // ... und auch kein Element mit der GUID gefunden wurde if(null(actObj)) { ack "GUID " guid " of object " identifier(o) "" //- " not found in EA as diagram or element." } else { // Es wurde kein Diagramm, aber ein Element // mit der GUID gefunden oleGet(actObj, "Notes", elementNotes) if(null(elementNotes)) { ack "Getting Notes of GUID " guid " failed." } else { o."Object Text" = elementNotes progressStep(++progessbarStep) } } } else // Es wurde ein Diagramm mit der GUID gefunden { /*************************************************** * EA.Project.PutDiagramImageOnClipboard: * ====================================== * Copies an image of the specified diagram to the * clipboard. * * Parameters: * • DiagramGUID: String - the GUID * (in XML format) * of the diagram * to copy * • Type: Long - the file type * • If Type = 0 then it is a metafile * • If Type = 1 then it is a Device * Independent Bitmap * *****************************************************/ put(autoArgs, guid) put(autoArgs, 0) oleMethod(eaProject, "PutDiagramImageOnClipboard", autoArgs, diagramCopied) clear(autoArgs) if(diagramCopied) { while(oleDelete(o)); if(olePaste(o)) { oleSetMaxWidth(o."Object Text", 400) progressStep(++progessbarStep) } else { ack "Pasting from clipboard of GUID " guid " failed." } } else { ack "Copying to clipboard of GUID " guid " failed." } } diaObj = null actObj = null } } } void main(DB updateWin) { int accepted, rejected currentFilter = current f = contains(attribute("ATTRIBUT_WITH_GUID"),"{", false) set(m, f, accepted, rejected) unApplyFiltering(m) progressStart(updateWin, "Executing update", "Processing...", accepted) establishInterface() updateObjects() if(!null(currentFilter)) set(m, currentFilter, accepted, rejected) closeInterface() progressStop refresh(m) hide(updateWin) destroy(updateWin) updateWin = null } m = current if(null(m)) { ack "Update can only be started within a module." } else { if(isEdit(m)) { updateWin = create("Update EA ", styleCentered|styleFloating) label(updateWin, "Do you wish to update?") ok(updateWin, main) show updateWin } else { ack "Module must be opend in 'Exclusive Edit'." } }
Line
guid = o."BB_ImageFileName"
should probably be
guid = o."ATTRIBUT_WITH_GUID"
(and by the way, adding an „E“ to „ATTRIBUT“ would fix that typo as well).
Nota bene: if you do not want to spawn a new EA instance but connect to your already running EA (e.g. to transfer unsaved diagrams), use this code instead of getting EA.Project and EA.Repository via oleCreateAutoObject():
OleAutoObj eaApp = oleGetAutoObject(„EA.App“)
// do not forget to check null(eaApp)
oleGet(eaApp, „Repository“, eaRepository)
// check if null(eaRepository)
clear (autoArgs)
oleMethod (eaRepository, „GetProjectInterface“, autoArgs, eaProject)
And perhaps do not close the existing EA instance in closeInterface(). 😉