Submit a problem

In order to provide you the best help possible to analyze and debug your problems please provide us some information about your environment.
When you submit a problem, please indicate:
- The Version, Build Id, Core Id, System and Architecture (You can get these information in the Help/About menu entry)
- The Modelio Edition (Modelio Open Source or Modelio by Modeliosoft)
- Your Operating System

file Script for export diagram to other project

1 year 5 months ago #4066 by Keitarosama

I'm relatively new to Modelio and right now I'm trying to copy a diagram to other project, but I didn't know how to do that.

I'm checking that I can export it to an image, but I can't find where I could export it to another project. I know too, that an export in XMI can pass the elements but not the diagrams.

So, can you explain me a way to do that?, if I make a script, could I make the exportation? Do you have an example to do that?

Please help!

Please Log in or Create an account to join the conversation.

1 year 4 months ago #4083 by pan

There is no standard way to copy specifically a diagram to another project. Eventually, you can import a project content using the Modelio import feature .

You can develop a module or a Jython script in order to export diagram data. This is an example how you can do it with Jython :
from import *
from javax.xml.parsers import *
from javax.xml.transform import *
from javax.xml.transform.dom import *
from import *
from org.xml.sax import *
from org.w3c.dom import *

session = Modelio.getInstance().getModelingSession()
diagramservice = Modelio.getInstance().getDiagramService()

outputDirectory = "C:\\tmp"

element = selectedElements.get(0)

if (isinstance(element,StaticDiagram)):
	dh = diagramservice.getDiagramHandle(element)
	diagramnode = dh.getDiagramNode()
	nodes = diagramnode.getNodes()
		dbFactory = DocumentBuilderFactory.newInstance()
		dBuilder = dbFactory.newDocumentBuilder()
		doc = dBuilder.newDocument()
		# root element
		rootElement = doc.createElement("diagrams")
		# insert a diagram element
		diagram = doc.createElement("diagram")
		attrName = doc.createAttribute("name")

		# insert nodes
		for node in nodes:
			nodeElt = doc.createElement("node")
			attrUuid = doc.createAttribute("uuid")
			attrName = doc.createAttribute("name")
			attrEltMClass = doc.createAttribute("eltMClass")
			nodeBounds = node.getBounds()
			attrX = doc.createAttribute("x")
			attrY = doc.createAttribute("y")
			attrW = doc.createAttribute("width")
		transformerFactory = TransformerFactory.newInstance()
		transformer = transformerFactory.newTransformer()
		transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8")
		transformer.setOutputProperty(OutputKeys.INDENT, "yes")
		source = DOMSource(doc)
		result = StreamResult(File(outputDirectory+"\\outputdiagram.xml"))
		transformer.transform(source, result)
	except Exception, exc:
		print "Exception: ", str(exc)

You can export diagram(s) data from your source project as an xml file then build a diagram on your destination project by importing the xml data.
In this example, I only handled the export process. To work, you have to select a diagram then run this script. Of course, it can be modified so you can manage the selection of several diagrams.

You can consult the Javadoc API to obtain more information about the needed methods and classes.
More specifically you can consult the API of IDiagramNode, IDiagramDG, IDiagramHandle, IDiagramService for more information about diagrams' methods.
This is the wiki about Diagrams services .

Let us know if it helps.


Please Log in or Create an account to join the conversation.

Moderators: chmcma
Time to create page: 0.028 seconds
^ Back to Top