Author Topic: method LoadLinkedDocument  (Read 588 times)

BruceTOGAF2

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
method LoadLinkedDocument
« on: August 25, 2017, 01:33:11 am »
Pawel Zubkiewicz's post about linked documents is 120 days old, so I figured I had better start a new post. 
Geert Bellekens has answered Pawel's query, but I am stll failing to understand how to use a VBScript method LoadLinkedDocument
to create a linked document attached to a package.

My package has already been declared and created.

dim myDoc
myDoc = myPackage.LoadLinkedDocument("d:\Profiles\bsingleton\AppData\Local\Temp\82600.tmp")

The above code errors "Object doesn't support this property."

Where am I going wrong?  What is the correct syntax?

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: method LoadLinkedDocument
« Reply #1 on: August 25, 2017, 04:48:07 am »
Well, the V12 help mentions LoadLinkedDocument on http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/linking_documentation.html but it does not hold any API documentation. So I guess this is one of the hot air operations.

q.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 868
  • Karma: +11/-0
    • View Profile
Re: method LoadLinkedDocument
« Reply #2 on: August 25, 2017, 09:59:31 am »
LoadLinkedDocument is a method of class EA.Element, not EA.Package. However each Package has a corresponding Element class. You just need to reference it via the Package.Element attribute.

Example:
myDoc = myPackage.Element.LoadLinkedDocument("d:\Profiles\bsingleton\AppData\Local\Temp\82600.tmp")

@qwerty: It's documented on the Element Class, which is linked at the bottom of the help page you referenced.

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6200
  • Karma: +47/-5
    • View Profile
Re: method LoadLinkedDocument
« Reply #3 on: August 25, 2017, 12:19:14 pm »
However each Package has a corresponding Element class.
Except the root nodes of a project. But they can't have linked documents either.
Simon

support@sparxsystems.com

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: method LoadLinkedDocument
« Reply #4 on: August 25, 2017, 05:58:02 pm »
@Aaron, go figure and enter LoadLinkedDocument in the help's search field. It returns two results. None of them pointing to the operation in question. That's what I call "not documented"  :-X

q.

BruceTOGAF2

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: method LoadLinkedDocument
« Reply #5 on: August 25, 2017, 06:04:29 pm »
I am delighted that Aaron has replied instantly with a workable syntax for LoadLinkedDocument.  The following VBScript code works a treat.

dim myDoc
myDoc = repPackage.Element.LoadLinkedDocument("c:\Reports\Object_Text.docx")

I am trying to fill the Linked Document with text from an imported spreadsheet row. The following code creates var Object_Text
dim Object_Text
Set wsCell = wsSource.Cells(RowNumber, 11)
Object_Text = wsCell.Value

GetLinkedDocument() returns the content of the LinkedDocument. I need to do the opposite. I need to update the content of the LinkedDocument.

My next task is to follow Geert's idea ("create a temporary file with the contents ....") then use LoadLinkedDocument

How do I create the temporary file "c:\Reports\Object_Text.docx" with the contents of Object_Text?

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6200
  • Karma: +47/-5
    • View Profile
Re: method LoadLinkedDocument
« Reply #6 on: August 28, 2017, 01:26:22 pm »
@Aaron, go figure and enter LoadLinkedDocument in the help's search field. It returns two results. None of them pointing to the operation in question. That's what I call "not documented"  :-X

q.
What search function are you using?

We're in the process of migrating the search function on our website. I've seen cases before where the old one wouldn't return results. But both methods are returning the same two pages, which are both referencing this API function for me.

http://www.sparxsystems.com/search/sphider/search.php?catid=3&query=LoadLinkedDocument&search=1&tab=2
http://www.sparxsystems.com/cgi-bin/search/search.pl?Terms=LoadLinkedDocument&Realm=13.5+help
Simon

support@sparxsystems.com

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: method LoadLinkedDocument
« Reply #7 on: August 28, 2017, 06:26:29 pm »
The first does not return any results. I got the 2 results from the 2nd. However, I had been searching from here

http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/index/index.html with LoadLinkedDocument in the lower magnification glass search (I already mentioned the confusing duplication of the search fields - well)

to here

http://www.sparxsystems.com/cgi-bin/search/search.pl?Terms=LoadLinkedDocument&Realm=12.1+help

q.

Simon M

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6200
  • Karma: +47/-5
    • View Profile
Re: method LoadLinkedDocument
« Reply #8 on: August 29, 2017, 08:21:08 am »
qwerty, both of those pages are referencing the operation we are talking about. One is in a footnote about how to access it via the API. The other one you have to find the function in the table of all the operations available on the Element class.

Frankly, if they were missing from that search I would be guessing the API function didn't exist in that version of EA.
Simon

support@sparxsystems.com

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: method LoadLinkedDocument
« Reply #9 on: August 29, 2017, 08:48:48 am »
One is in a footnote about how to access it via the API.

Arrrggghh. What help is that to find the topic in a footnote but not the topic itself? That must be truly Sparxian logic, I guess.#

The V12 help finds exactly the same footnotes.

q.

BruceTOGAF2

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: method LoadLinkedDocument
« Reply #10 on: October 25, 2017, 01:35:55 am »
Success!  I needed to update the content of the LinkedDocument. I found a solution with Geert's inspiration.  I followed Geert's idea ("create a temporary file with the contents ....". See function storeArtiFile) then use LoadLinkedDocument. The following code works well.

var tempFileName = storeArtiFile(Absolute_Number, Object_Text);
// Attach linked document to Artifact element
var myDoc
myDoc = artifElement.LoadLinkedDocument(tempFileName);

function storeArtiFile(Absolute_Number, Object_Text)
{
   var tempFileName = "c:\Reports\\" + Absolute_Number + ".rtf";
   // Create a document generator object
   var docGenerator as EA.DocumentGenerator;
   docGenerator = Repository.CreateDocumentGenerator;
            
   // Create a new document
   if (docGenerator.NewDocument("")) {
      var generationSuccess;
      generationSuccess = false;
      generationSuccess = docGenerator.InsertText(Object_Text, "Normal");
               
      var saveSuccess;
      saveSuccess = false;
      saveSuccess = docGenerator.SaveDocument( tempFileName, DOCUMENTATION_TYPE );
   }
   if (saveSuccess) {
      return tempFileName;
   }
   else {
      return "";
   }
}