Modelio CSV Import Script

One of the most important feature which is missing on Modelio which is there in other tools is that there is no CSV import feature. For example if you want to create a class which has around 100 or more attributes then it will be very cumbersome. Am sure you will have this attributes listed somewhere in an Excel or a CSV and would like to import the same.

This script facilitate the import and allows you to import the attributes from a simple file.

##Get CSV File

from javax.swing import JFrame
from javax.swing import JFileChooser
import csv

frame = JFrame("File Chooser")
fileChooser = JFileChooser()

option = fileChooser.showOpenDialog(frame)

if option == JFileChooser.APPROVE_OPTION :
            selectedFile = fileChooser.getSelectedFile()
            print "Importing from file" + selectedFile.getAbsolutePath()
            #Open file for reading
            inputFile = csv.reader(open(selectedFile.getAbsolutePath()), delimiter=' ', quotechar='|')
            for row in inputFile :
                data = row[0].split(",")
                print "Importing Atrribute :" + data[0]

                dtType = Modelio.getInstance().getModelingSession().findByAtt(DataType,"Name",data[1])
                if dtType.size() == 0 :
                    print "Data type " + data[1] + " not found, so skipping " + data[0]
                    continue
                newAttr = Modelio.getInstance().getModelingSession().getModel().createElement("Attribute")
                newAttr.setName(data[0])
                newAttr.setType(dtType[0])
                newAttr.setOwner(elements[0])

This assumes the structure of the CSV file as below

Attribute NameData TypeLength
CSV Structure

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.