0

I have an Enterprise Architect project with some Diagram. I want to add them to an external Word document (which cannot be generated with EA). Moreover, other people may need to edit this word document without having the EA project. So here is what I did to do so :

I created an EA JavaScript file which generate rtf files (1 .rtf file for each diagram). In my main word document, whenever I wanted to insert the diagram, I added a link to the specific rtf file previously generated. Everything is working fine, except, after some times, I cannot generate the rtf file anymore (when running docGenerator.SaveDocument), it tells me "Failed to save the output file".

GenerateRTF :

function OnProjectBrowserScript()
{
    // Get the type of element selected in the Project Browser
    var treeSelectedType = Repository.GetTreeSelectedItemType();
    switch ( treeSelectedType )
    {
        case otPackage :
        {
            // Code for when a package is selected
            [...]
            packageDiagrams = thePackage.Diagrams; // Collection of all the Diagrams
            
            for ( var i = 0 ; i < packageDiagrams.Count ; i++ ) {
                var currentElement as EA.Diagram;
                currentDiagram = packageDiagrams.GetAt( i );
            
                // Document Generation using docGenerator
                var docGenerator as EA.DocumentGenerator;
                docGenerator = Repository.CreateDocumentGenerator();
                docGenerator.NewDocument("")
                docGenerator.DocumentDiagram(currentDiagram.DiagramID,1,"Diagram Report");
                var diagramName = currentDiagram.Name + ".rtf";

                //Save diagram into rtf document
                var saveSuccess = docGenerator.SaveDocument( diagramName, EA.DocumentType.dtRTF );
                if ( saveSuccess ) {
                    Session.Prompt( "Documentation complete!", promptOK );
                } else {

                    // -- > Error message saying file cannot be saved <--
                    Session.Prompt( "Error saving file " + diagramName + " : " + docGenerator.GetLastError(), promptOK );

                }
            
            }
            break;
        }
        [...]

This "problem" is that my RTF files are used/linked in another document (if I don't use them in another file as a link, I can generate as many times as I want the rtf files).

Moreover, I never open the generated rtf files with Word (as I don't want Word to lock them ....). Also, when generating the rtf files, my main word document is also closed. I think the problem comes from the EA rtf file generation as I already used this method with another tool generating rtf and I did not get any problem.

How could I pass by the protection when writing the rtf file ? Is there another method to export the file from EA which could be used instead of using docGenerator ?

4
  • If you think it's a problem in the SaveDocument, why don't you save it as a different file, and then use file operations to copy the new file over the existing one? Commented Dec 10, 2024 at 7:10
  • Well, I want an automatic process. It means I run the script and then my main document is up to date. Maybe I could add this trick in the JavaScript (and I may have the same problème, to be tested) but I don't undersrand why I would have to do so. I will try it just in case, to have a backup solution. Commented Dec 11, 2024 at 8:05
  • You should try that to figure out if indeed the SaveDocument operation is the problem. If you have the same problem with a file copy, then that indicates that the problem is elsewhere. Possibly some process that keeps your file locked. Commented Dec 11, 2024 at 8:27
  • Agreed. After some test the problem, ideed, whas not on the EA generation process. I will update my post. Commented Dec 12, 2024 at 8:50

1 Answer 1

1

Thanks for all your comments that lead me to the solution. Ideed, problem was not due to a file generation problem but was relater to Word wth its links between files.

What I previously did, in the main document to import my RTF file (sorry if the name are not identicial to what you can see in your version of Word, I don't have the english version) :

Insert > Object > From a file > I selected the file and checked the Link to the file box

However the solution below worked like a charm :

Insert > text from a file > I selected the file and the trick part : click on to arrow next to the Insert button in order to Instert as a Link

Be aware that, with this solution, you can now directly edit the inserted text in the main word document which was not possible with the pevious method. So methodology depends on what you need to do but I don't understand in which case you would use the first method with the links and locked files ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.