Book a Demo

Author Topic: Scripted way to update dynamic section in Custom documents  (Read 5371 times)

msandoval

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Scripted way to update dynamic section in Custom documents
« on: June 28, 2022, 08:24:38 am »
How can I update the dynamic section of custom documents via scripting?

Thanks!



msandoval

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Scripted way to update dynamic section in Custom documents
« Reply #1 on: August 24, 2022, 04:51:52 am »
I received the following from Sparx support:

"Unfortunately there is no way to update dynamic documents via Scripting at this time.
We have noted this as a feature request for future consideration, but can't say if/when it may be implemented. Thank you for your feedback. "

vsantos01

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Scripted way to update dynamic section in Custom documents
« Reply #2 on: September 06, 2022, 08:59:08 pm »
I just started with interops to do just this: update dynamic section in custom document.
As a workaround, I could define a report and generate it... Any idea how to request report generation from c# starting from the EA.Repository object?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Scripted way to update dynamic section in Custom documents
« Reply #3 on: September 06, 2022, 09:26:18 pm »
I just started with interops to do just this: update dynamic section in custom document.
As a workaround, I could define a report and generate it... Any idea how to request report generation from c# starting from the EA.Repository object?

See here: https://www.sparxsystems.com/enterprise_architect_user_guide/16.0/add-ins___scripting/document_generator_interface.html

Geert

vsantos01

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Scripted way to update dynamic section in Custom documents
« Reply #4 on: September 06, 2022, 11:26:24 pm »
Hi Geert

Thanks, that was great and I'm experimenting already with it. But if I get it correctly, this interface is useful to build a document. I already have the document template, the style sheet, the table of contents style and so defined in my repository file... how can I just generate the document associated?

Rgds
Victor

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Scripted way to update dynamic section in Custom documents
« Reply #5 on: September 06, 2022, 11:55:57 pm »

vsantos01

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Scripted way to update dynamic section in Custom documents
« Reply #6 on: September 07, 2022, 06:54:59 pm »

Thanks again! This seems to be what I need. Unfortunately, still not working.

Code: [Select]
repository.GetProjectInterface().RunReport("{43C1B678-456B-487a-B852-9504E09BBAE4}", "Standard Component Interface", "Report.rtf");
This pops up a window with the error message "Error creating output file".

I have set the EA window in visible mode to debug, and I see how the Run Report window opens with all the expected data in the different configuration fields but for the package, which appears empty. I'm expecting this to be set by means of the first parameter of RunReport, which is defined as string named PackageGUID.

I got the GUID by manually opening the EA file and copying it from the package context menu (Copuy/Paste -> Copy Node GUID to Clipboard). I also added code to my console application to read it and print it on screen and I'm getting the same value as the one I'm using in RunReport.

Any ideas what can be failing here?

BTW, manually opening the Run Report window allows me to generate the report for the package selected in the package tree.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Scripted way to update dynamic section in Custom documents
« Reply #7 on: September 07, 2022, 07:08:04 pm »
I'm pretty sure you need to supply a valid filename. You passed "Report.rtf", so EA can't create that file as it doesn't know where it should go.

Something like "c:\temp\Report.rtf" should work better (given that the directory "c:\temp" actually exists)

In C# you also need to either escape the backslashes, or tell the compiler to take the string literally

So either "c:\\temp\\Report.rtf" or @"c:\temp\Report.rtf"

Geert

vsantos01

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Scripted way to update dynamic section in Custom documents
« Reply #8 on: September 07, 2022, 08:43:30 pm »
I tried it, with the same outcome. I have uploaded a screenshot of the run report window I get when running the C# command supplied earlier. You will see the package is not being set.

https://imgur.com/a/H8WXEcS

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Scripted way to update dynamic section in Custom documents
« Reply #9 on: September 07, 2022, 09:56:31 pm »
Ah, I see what's going on.
In the Project Interfact, you have to use the XML format for all GUID's.  ???

You can convert regular GUID's to XML GUID's using the function GUIDtoXML()

Geert

vsantos01

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Scripted way to update dynamic section in Custom documents
« Reply #10 on: September 08, 2022, 05:23:21 pm »
Still an error, different, but an error. Anyway, I managed to do it by getting the GUID using PackageGUID instead of copy/pasting it:

Code: [Select]
EA.Package model = (EA.Package) repository.Models.GetAt(0);
EA.Package mainPackage = (EA.Package) model.Packages.GetAt(0);
string path = System.IO.Path.GetFullPath("Report.rtf");
repository.GetProjectInterface().RunReport(mainPackage.PackageGUID, "Standard Component Interface", path);

I have also checked that I can iterate through all the packages from the model , so instead of hardcoding getting the first one, I could search the needed one by name.

thanks for all your support!