Book a Demo

Author Topic: API to add external document (word/pdf etc) to model ?  (Read 5702 times)

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
API to add external document (word/pdf etc) to model ?
« on: February 20, 2018, 04:51:05 am »
Hi,

Anyone know if there is an API that can be used to add a document (as an artefact in t_object and corresponding extdoc entry in t_document) to a Sparx repository ? If there isn't' an API has anyone got a script that does this ?

Regards,

Jon.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: API to add external document (word/pdf etc) to model ?
« Reply #1 on: February 20, 2018, 09:11:53 am »
You're probably looking for EAElement.LoadLinkedDocument (string Filename)

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: API to add external document (word/pdf etc) to model ?
« Reply #2 on: February 20, 2018, 06:45:27 pm »
You're probably looking for EAElement.LoadLinkedDocument (string Filename)

q.

No, that's not it. That will only load the contents into the linked document of the element, not have it as external document.

I'm not aware of any API function to do so, but I never really had to look for it either.

Geert

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: API to add external document (word/pdf etc) to model ?
« Reply #3 on: February 22, 2018, 12:51:12 am »
Ok, thanks both - I think I might be able to hack my way around it with EAElement.LoadLinkedDocument (string Filename) - assuming it does the zipping/encoding of the document into t_document.strcontent ...

Regards,

Jon.

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: API to add external document (word/pdf etc) to model ?
« Reply #4 on: February 23, 2018, 10:44:11 pm »
Hi,

Turns out it is possible - but only if you generate the doc as PDF (extension = ".pdf" below) due to encoding/zipping... this code did the trick for me..

p.RunReport thePackage.PackageGUID, "DB Diagram and Element Details (A3)", fname & extension
            
            Set theElement = thePackage.Elements.AddNew ("Baseline Approval Document [" & theDate & "]" & extension, "Artifact")
            theElement.LoadLinkedDocument (fname & extension)
            theElement.Update
            sql = "UPDATE t_object SET style = 'ExtDoc=1;' WHERE object_id = " & theElement.ElementID
            Repository.Execute (sql)
            
            sql = "UPDATE t_document SET DocName = '" & theElement.Name & "', ElementType = '" & extension & "', DocType = 'ExtDoc' " &_
               "WHERE ElementID = '" & theElement.ElementGUID & "' AND ElementType = 'ModelDocument'"
            Repository.Execute (sql)
            

Regards,

Jon.