Book a Demo

Author Topic: Javascript function that accepts an element & a diagram and must merge  (Read 3470 times)

rchalleray

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Respected Sirs,

I would like to write a JavaScript function that does the following:
1.   it accepts 2 inputs namely
(a)   A diagram (that was created in the main programme)
(b)   An EA element (that already exists in the model)
the objective of the function would be to simply add the elements to the diagram (i.e. which was cost to the JavaScript function in question).

I have written the following script but I'm getting an error in execution

function add_element_dia(input_element, theDiagram)
 {
      // Add the element to the diagram
      var diagramObjects as EA.Collection;
      var testDiagram as EA.Diagram
      testDiagram = theDiagram;
      diagramObjects=testDiagram.DiagramObjects; // Error Occurs here
   
      var testDiagramObject as EA.DiagramObject;
      testDiagramObject = theDiagram.DiagramObjects.AddNew( "l=200;r=400;t=200;b=600;", "" );
      testDiagramObject.ElementID = input_element.ElementID;
      testDiagramObject.Update();   
 }

Can anyone direct me to a previous thread that can explain clearly what I'm trying to do (ie referring to the objectives mentioned above) or alternatively if they can comment on my script clarifying what I'm doing wrong then that would be most appreciated.
if my question is unclear in any aspect then please feel free to seek any clarification.

I look forward to a prompt clarification on this topic

Best regards
Rob

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Rob,

What error are you getting? and how are you calling this function?

Geert

rchalleray

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Hi Geert

Thank you for your kind response.

By the way, we missed you on the 24th of May 2022 in Reading. I heard that you could not make it because of the ID card issues after Brexit.

I was really looking forward to listening to your presentation. It came highly recommended by a colleague.

I look forward to speaking to you someday.

Regards
Rob

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Hi Geert

Thank you for your kind response.

By the way, we missed you on the 24th of May 2022 in Reading. I heard that you could not make it because of the ID card issues after Brexit.

I was really looking forward to listening to your presentation. It came highly recommended by a colleague.

I look forward to speaking to you someday.

Regards
Rob
Yeah, that was really stupid.
Since October 2021 EU citizens are no longer allowed entry with only their ID cards; and I somehow missed that memo  :(

Hopefully there will be a another occasion soon. We've done some pretty cool stuff with EA lately.

Geert

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1405
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Digressing from the topic, like Rob it was a unfortunate I couldn't see you at the EAUG.
It was a great event and the first opportunity since covid to meet everyone again.

As an EU citizen travelling within Europe, I don't use much my passport either and was relieved mine had not expired.


Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com