Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
VisualBasic.net script to Convert an Aras Innovator datamodel to a graphml file
Imports Aras.IOM
Imports System.Xml
Imports System.Xml.Schema
Imports System.Linq
Imports System.Xml.Linq
Imports <xmlns="http://graphml.graphdrawing.org/xmlns">
imports <xmlns:java="http://www.yworks.com/xml/yfiles-common/1.0/java">
Imports <xmlns:sys="http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0">
imports <xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/2.0">
Imports <xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Imports <xmlns:y="http://www.yworks.com/xml/graphml">
Imports <xmlns:yed="http://www.yworks.com/xml/yed/3">
Public Class exportDM
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Instanciate Innovator
Dim localInn As Innovator = mainPage.connection.inn
' create the graphML document
Dim graphML As XDocument = New XDocument()
' add the graphml top element
Dim graphMlElem As XElement = <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:java="http://www.yworks.com/xml/yfiles-common/1.0/java" xmlns:sys="http://www.yworks.com/xml/yfiles-common/markup/primitives/2.0" xmlns:x="http://www.yworks.com/xml/yfiles-common/markup/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xmlns:yed="http://www.yworks.com/xml/yed/3" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd"></graphml>
' defining graphical configuration elements to visualize in yed
Dim keyGraph As XElement = <key for="node" id="d6" yfiles.type="nodegraphics"/>
Dim keyEdgeGraph As XElement = <key for="edge" id="d10" yfiles.type="edgegraphics"/>
graphMlElem.Add(keyGraph)
graphMlElem.Add(keyEdgeGraph)
graphML.Add(graphMlElem)
' add the main graph element
Dim graphElem As XElement = <graph edgedefault='directed' id='G'></graph>
graphMlElem.Add(graphElem)
' start browsing the datamodel
Dim myitems As Item = localInn.newItem("Itemtype", "get")
myitems.setAttribute("select", "name")
myitems.setProperty("is_relationship", "0")
Dim myitemsProperty As Item = myitems.createRelationship("Property", "get")
myitemsProperty.setProperty("data_type", "item")
myitems = myitems.apply()
Dim i As Integer = 0
' loop through itemtypes to build graph nodes
While (i < myitems.getItemCount())
Dim myitem As Item = myitems.getItemByIndex(i)
Dim relname As String = myitem.getProperty("name", "")
' for each non-relationship itemtype create an element
Dim nodeData As XElement = <data key="d6">
<y:ShapeNode>
<y:Geometry height='60.0' width='150.0'/>
<y:Fill color="#FFCC00" transparent="false"/>
<y:BorderStyle color='#000000' raised='False' type='line' width='1.0'/>
<y:NodeLabel alignment='center' autoSizePolicy='content' fontFamily='Dialog' fontSize='12' fontStyle='plain' hasBackgroundColor='False' hasLineColor='False' height='18.701171875' horizontalTextPosition='center' iconTextGap='4' modelName='custom' textColor='#000000' verticalTextPosition='bottom' visible='True' width='78.021484375' x='32.4892578125' y='22.1494140625'>
<%= myitem.getProperty("name", "") %>
<y:LabelModel>
<y:SmartNodeLabelModel distance='4.0'/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX='0.0' labelRatioY='0.0' nodeRatioX='0.0' nodeRatioY='0.0' offsetX='0.0' offsetY='0.0' upX='0.0' upY='-1.0'/>
</y:ModelParameter>
</y:NodeLabel>
<y:Shape type='rectangle'/>
</y:ShapeNode>
</data>
Dim nodeElement As XElement = <node id=<%= myitem.getID() %>></node>
nodeElement.Add(nodeData)
graphElem.Add(nodeElement)
i = i + 1
End While
' Query for the relationships
Dim myrels As Item = localInn.newItem("RelationshipType", "get")
myrels = myrels.apply()
i = 0
' loop through relationships to build graph edges
While (i < myrels.getItemCount())
Dim myrel As Item = myrels.getItemByIndex(i)
Dim source_id As String = myrel.getProperty("source_id", "")
Dim related_id As String = myrel.getProperty("related_id", "")
Dim relname As String = myrel.getProperty("name", "")
'create relationship Itemtype
Dim edgeNodeElement As XElement = <node id=<%= myrel.getProperty("relationship_id", "") %>></node>
Dim nodeData As XElement = <data key="d6">
<y:ShapeNode>
<y:Geometry height="60" width="150"/>
<y:Fill color="#00CCFF" transparent="false"/>
<y:BorderStyle color='#000000' raised='False' type='line' width='1.0'/>
<y:NodeLabel alignment='center' autoSizePolicy='content' fontFamily='Dialog' fontSize='12' fontStyle='plain' hasBackgroundColor='False' hasLineColor='False' height='18.701171875' horizontalTextPosition='center' iconTextGap='4' modelName='custom' textColor='#000000' verticalTextPosition='bottom' visible='True' width='78.021484375' x='32.4892578125' y='22.1494140625'>
<%= myrel.getProperty("name", "") %>
<y:LabelModel>
<y:SmartNodeLabelModel distance='4.0'/>
</y:LabelModel>
<y:ModelParameter>
<y:SmartNodeLabelModelParameter labelRatioX='0.0' labelRatioY='0.0' nodeRatioX='0.0' nodeRatioY='0.0' offsetX='0.0' offsetY='0.0' upX='0.0' upY='-1.0'/>
</y:ModelParameter>
</y:NodeLabel>
<y:Shape type='hexagon'/>
</y:ShapeNode>
</data>
edgeNodeElement.Add(nodeData)
graphElem.Add(edgeNodeElement)
'create edge in
Dim edgeEdgeElementIn As XElement = <edge source=<%= source_id %> target=<%= myrel.getProperty("relationship_id", "") %>>
<data key="d10">
<y:PolyLineEdge>
<y:LineStyle color="#000000" type="line" width="1.0"/>
<y:Arrows source="none" target="standard"/>
</y:PolyLineEdge>
</data>
</edge>
If (source_id <> "") Then
graphElem.Add(edgeEdgeElementIn)
End If
'create edge out
Dim edgeEdgeElementOut As XElement = <edge source=<%= myrel.getProperty("relationship_id", "") %> target=<%= related_id %>>
<data key="d10">
<y:PolyLineEdge>
<y:LineStyle color="#000000" type="line" width="1.0"/>
<y:Arrows source="none" target="standard"/>
</y:PolyLineEdge>
</data>
</edge>
If (related_id <> "") Then
graphElem.Add(edgeEdgeElementOut)
End If
i = i + 1
End While
' add the item property links
i = 0
While (i < myitems.getItemCount())
Dim myitem As Item = myitems.getItemByIndex(i)
Dim j As Integer = 0
Dim propertiesAvoided As String() = {"created_by_id", "id", "config_id", "source_id", "related_id", "owned_by_id", "locked_by_id", "managed_by_id", "current_state", "team_id", "modified_by_id", "permission_id"}
While (j < myitem.getRelationships("Property").getItemCount())
Dim myprop As Item = myitem.getRelationships("Property").getItemByIndex(j)
If Not (propertiesAvoided.Contains(myprop.getProperty("name", ""))) Then
Dim edgeprop As XElement = <edge source=<%= myitem.getID() %> target=<%= myprop.getProperty("data_source", "") %>>
<data key="d10">
<y:PolyLineEdge>
<y:LineStyle color="#0000FF" type="dashed" width="1.0"/>
<y:Arrows source="none" target="standard"/>
<y:EdgeLabel alignment="center" configuration="AutoFlippingLabel" distance="2.0" fontFamily="Dialog" fontSize="12" fontStyle="plain" hasBackgroundColor="false" hasLineColor="false" height="18.701171875" horizontalTextPosition="center" iconTextGap="4" modelName="custom" preferredPlacement="anywhere" ratio="0.5" textColor="#000000" verticalTextPosition="bottom" visible="true" width="104.0546875">
<%= myprop.getProperty("name", "") %>
<y:ModelParameter>
<y:SmartEdgeLabelModelParameter angle="6.283185307179586" distance="59.707561268278965" distanceToCenter="true" position="right" ratio="-12.44489993553995" segment="-1"/>
</y:ModelParameter>
<y:PreferredPlacementDescriptor angle="0.0" angleOffsetOnRightSide="0" angleReference="absolute" angleRotationOnRightSide="co" distance="-1.0" frozen="true" placement="anywhere" side="anywhere" sideReference="relative_to_edge_flow"/>
</y:EdgeLabel>
</y:PolyLineEdge>
</data>
</edge>
If (myprop.getProperty("data_source", "") <> "") Then
graphElem.Add(edgeprop)
End If
End If
j = j + 1
End While
i = i + 1
End While
' saving the ouput
Dim saveFileDialog1 As SaveFileDialog = New SaveFileDialog()
saveFileDialog1.Filter = "GraphML|*.graphml"
saveFileDialog1.Title = "Save the Aras Innovator Graph"
saveFileDialog1.ShowDialog()
' If the file name Is Not an empty string open it for saving.
If (saveFileDialog1.FileName <> "") Then
graphML.Save(saveFileDialog1.FileName)
End If
End Sub
End Class
@YoannArasLab

This comment has been minimized.

Copy link
Owner Author

@YoannArasLab YoannArasLab commented Feb 22, 2018

I need to add the polyitemtypes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment