Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JDT

Pages: [1]
1
Automation Interface, Add-Ins and Tools / Re: ActiveXObject is not defined
« on: February 14, 2020, 01:24:04 am »
Instead of this (JScript):

Code: [Select]
var xmlDOM = new ActiveXObject("MSXML2.DOMDocument.6.0");
try this (JavaScript) instead:

Code: [Select]
var xmlDOM = new COMObject("MSXML2.DOMDocument.6.0");
That should work.


2
Hey there,

as I've been looking all over the place for a solution to create links to diagrams on an existing diagram, and only kept being pointed to this (unsanswered) post, I thought I'd actually post the solution when I found it.. And I did!

First things first: Diego's script actually *does* make a hyperlink. If you click it, the diagram gets selected in the project browser. However, what he wanted to achieve, is to make a diagram hyperlink that actually opens the diagram. The solution below manages to do so.

Analysis steps
  • Create a Diagram hyperlink manually by dragging the target diagram onto the diagram and selecting "Drop As..." -> Hyperlink.
  • Find the element ID of the created link
Code: [Select]
var diagram as EA.Diagram; // Set diagram to your current diagram

var diagramObject as EA.DiagramObject;
var element as EA.Element;

for (var index = 0; var index < diagram.DiagramObjects.Count; index++) {
  diagramObject = diagram.DiagramObjects.GetAt(index);
  element = Repository.GetElementByID(diagramObject.ElementID);

  Session.Output("Element: " + element.ElementID);
}

  • Analyse the element in the database
Code: [Select]
select * from t_object where object_id = '<insert ElementID here>'

Solution

What I found out, was that the Text element actually isn't a hyperlink (so setting the Subtype is not a good idea). It's a "normal" text element, but it has PDATA1 set to the DiagramID. I tried to set PDATA1 via script (some property?), but haven't yet found a "non-SQL" way of doing so. So here's the solution with a little bit of SQL to update PDATA1 at the end.. (If I find out how to get it done without SQL I will post it)

Code: [Select]
/**
 * Creates a link to a target diagram on a diagram.
 *
 * @param package Package where the source diagram is located.
 * @param diagram Source diagram onto which the link is created.
 * @param targetDiagram Target diagram for which the link that is creatde points.
/*
function createDiagramHyperlink(package, diagram, targetDiagram) {
// Make a hyperlink element
var hyperlink as EA.Element;
hyperlink = package.Elements.AddNew(targetDiagram.Name, "Text" );
hyperlink.Notes = targetDiagram.Name;
hyperlink.Update();

// Add the hyperlink to the diagram
var diagramObject as EA.DiagramObject;
diagramObject = diagram.DiagramObjects.AddNew("", "" );
diagramObject.ElementID = hyperlink.ElementID;
diagramObject.Update();
diagram.Update();

// Update the PDATA1 and set it to the target diagram's ID
Repository.Execute( "UPDATE t_object SET PDATA1='" + targetDiagram.DiagramID + "' where object_ID = '" + hyperlink.ElementID + "'" );
}

I hope this solution is useful to someone out there, even if it is an old post :-). Errors and ommissions excepted.

Cheers,
JDT

Pages: [1]