I am trying to get all ID's from objects in a single view
These are the elements in the XML:
<folder name="Technology & Physical" id="74461ad6-1717-4fa4-befb-0312a1a89b6f" type="technology">
<element xsi:type="archimate:Node" name="SRVAPP1" id="2ab17f17-ad9c-4a81-9206-1de36127aa35"/>
<element xsi:type="archimate:Device" name="end" id="b7b4df71-ae9f-490c-a18a-f4416c299358"/>
<element xsi:type="archimate:TechnologyService" name="Start" id="2af42d3a-c3b7-4807-bf5a-a3d864bc4f0d"/>
</folder>
And this is the XML part containing that particular view, it has 3 elements and 2 relations. The ID's Im looking for are in a field called archimateElement
<element xsi:type="archimate:ArchimateDiagramModel" name="SQL View Name" id="3e1e88db-1679-417a-b432-b942bd3d8b28">
<child xsi:type="archimate:DiagramObject" id="e1c7dd4b-8365-49e6-bb67-fa4affbee3cd" archimateElement="2ab17f17-ad9c-4a81-9206-1de36127aa35">
<bounds x="288" y="120" width="120" height="55"/>
<sourceConnection xsi:type="archimate:Connection" id="5c34f93d-80bc-4c59-9ff3-f2c74dc0b5ec" source="e1c7dd4b-8365-49e6-bb67-fa4affbee3cd" target="d10ed04f-b702-405f-ae3a-076acf70a3eb" archimateRelationship="d230a85b-f864-4b97-9687-25df78ad594b"/>
<sourceConnection xsi:type="archimate:Connection" id="bac703f8-d24f-463c-9823-fbd4509314e9" source="e1c7dd4b-8365-49e6-bb67-fa4affbee3cd" target="6bea61ff-b810-4172-8403-fc338261df72" archimateRelationship="2a42b1d2-7f69-497c-b457-ebc0e7080036"/>
</child>
<child xsi:type="archimate:DiagramObject" id="d10ed04f-b702-405f-ae3a-076acf70a3eb" targetConnections="5c34f93d-80bc-4c59-9ff3-f2c74dc0b5ec" archimateElement="b7b4df71-ae9f-490c-a18a-f4416c299358">
<bounds x="588" y="132" width="120" height="55"/>
</child>
<child xsi:type="archimate:DiagramObject" id="6bea61ff-b810-4172-8403-fc338261df72" targetConnections="bac703f8-d24f-463c-9823-fbd4509314e9" archimateElement="2af42d3a-c3b7-4807-bf5a-a3d864bc4f0d">
<bounds x="24" y="120" width="120" height="55"/>
</child>
</element>
Using this piece of code I try to achieve this:
function getArchiElementsFromView (view_Parameter)
{
//this function gets all Child ID on a view (from parameter) ->>>> these are not the ID's of the elements
allChildObjectOnView = view_Parameter.children();
console.log("Length of allChildObjectOnView: " + allChildObjectOnView.length);
for (i=0; i< allChildObjectOnView.length; i++)
{
console.log (
"ID: " + allChildObjectOnView[i].id + " | "
+ "Name: " + allChildObjectOnView[i].name + " | "
+ "archimateElement: " + allChildObjectOnView[i].archimateElement + " | "
+ "Bound: " + allChildObjectOnView[i].bounds + " | "
);
}
return null;
}
with this result:
D: e1c7dd4b-8365-49e6-bb67-fa4affbee3cd | Name: SRVAPP1 | archimateElement: undefined | Bound: {x=288, width=120, y=120, height=55} |
ID: d10ed04f-b702-405f-ae3a-076acf70a3eb | Name: end | archimateElement: undefined | Bound: {x=588, width=120, y=132, height=55} |
ID: 6bea61ff-b810-4172-8403-fc338261df72 | Name: Start | archimateElement: undefined | Bound: {x=24, width=120, y=120, height=55} |
ID: 5c34f93d-80bc-4c59-9ff3-f2c74dc0b5ec | Name: Relation 2 | archimateElement: undefined | Bound: undefined |
ID: bac703f8-d24f-463c-9823-fbd4509314e9 | Name: Relation1 | archimateElement: undefined | Bound: undefined |
The ID field dies not contain the ID of the element, but another ID. This matches the XML logic
The name field contains the object name as desired, although it is not noted in that part of the XML
the bounds field returns the values as found in the xml field (if they are present)
The archimateElement field in the XML contains the ID Im looking for, but returns undefined when I query it like all other fields in the collection
If I use this line to look at the object
console.log (allChildObjectOnView);
I get this as a result, most of the data, not the ID I'm looking for, also not the bounds (I don't need them)
[node: SRVAPP1, device: end, technology-service: Start, composition-relationship: Relation 2, realization-relationship: Relation1]
I could switch strategies and work with the names, but ID's have more guarantees to be unique...
How do I extract the elements ID's from a single view??
The ID for a visual object (box or connection) will be the ID of that visual object, not the concept that it references (if it is an ArchiMate diagram object or connection)
To access the underlying concept of an ArchiMate type graphical object use the .concept field:
allChildObjectOnView.concept
And once you have that, you can access the ID of the concept:
allChildObjectOnView.concept.id
More info:
https://github.com/archimatetool/archi-scripting-plugin/wiki/jArchi-Object#concept
Thanks again Phil