Author Topic: JScript - add LinkedDocument to element  (Read 4976 times)

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
JScript - add LinkedDocument to element
« on: July 04, 2016, 05:55:58 pm »
Hi all,

Once again, seeking your advise. I created simple script that creates number of elements and puts them on the diagram. Now I wonder whether it's possible to add LinkedDocument to one of those newly created elements. I have predefined template for LinkedDocument.

In API docs at http://sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/element2.html I see only 4 methods that operate with LinkdedDocuments.
  • GetLinkedDocument() -If the element contains no linked document, an empty string is returned.
  • LoadLinkedDocument(string Filename) - Notes: Loads the document from the specified file into the element's linked document
  • SaveLinkedDocument(string Filename) -Notes: Saves the linked document for this element to the specified file. Returns False if the element does not have a Linked document or fails to save the file.
  • DeleteLinkedDocument()

Looks like neither of them is useful for me right now.

Do you know any way to add linkeddocument to an element?

In theory, I could use LoadLinkedDocument and load docx from drive but it looks like very fragile solution... everyone would need to have the same file at the same location on his/her computer.
Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: JScript - add LinkedDocument to element
« Reply #1 on: July 04, 2016, 07:43:01 pm »
Can't you create a temporary file with the contents of you template and then use LoadLinkedDocument and pass the path to the temp file?

Geert

Pawel Zubkiewicz

  • EA User
  • **
  • Posts: 78
  • Karma: +2/-1
    • View Profile
    • zubkiewicz.com
Re: JScript - add LinkedDocument to element
« Reply #2 on: July 04, 2016, 09:06:58 pm »
That's a great idea. Thanks Geert.
Already implemented, although I don't know how to delete this temporary file from drive. Is is possible?

Enhanced Requirement Attributes Addin for Enterprise Architect (ERA Addin) - http://zubkiewicz.com/?p=239

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: JScript - add LinkedDocument to element
« Reply #3 on: July 04, 2016, 09:46:32 pm »
Yes, why wouldn't that be possible?
Here's the (VBscript) code I use in my textfile wrapper:
Code: [Select]
'delete the file
sub Delete
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(me.FullPath) then
fso.DeleteFile me.FullPath
end if
end sub

Geert