Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Import from CSV
* Requires jArchi -
* Requires PapaParse -
* Works with Export to CSV Script -
* Version 1: Import from CSV
* (c) 2018 Steven Mileham
var debug = true;;
console.log("> Import CSV");
load(__DIR__ + "lib/papaparse.min.js");
console.log("> Loaded Papa Parse");
var filePath = window.promptOpenFile({ title: "Open CSV", filterExtensions: ["*.CSV"], fileName: "default.archimate" });
if (filePath) {
var FileReader = Java.type("");
var theCSVFile = new FileReader(filePath);
var theCSV ="";
var data =;
console.log("> Please Wait...");
while(data != -1) {
var theCharacter = String.fromCharCode(data);
data =;
console.log("> File Loaded");
theDataFile = Papa.parse(theCSV);
theData =;
theDataHeaders = theData[0];
var commonProperties = ["UID","Name", "Documentation","Type"];
for (var i=1; i<theData.length-1; i++) {
var theConcept = null;
var theObject = [];
for (var j=0; j<theDataHeaders.length; j++) {
theConcept = $("#"+theObject.UID).first();
if (!theConcept) {
debug? console.log("> Missing UID, checking Name"):true;
theConcept = $("."+theObject.Name).first();
if (!theConcept || theConcept.length>1) {
debug? console.log("> Creating Concept"):true;
theConcept = model.createElement(theObject.Type,theObject.Name);
debug? console.log(theConcept):true;;
for (var j=0; j<theDataHeaders.length; j++) {
switch (theDataHeaders[j]) {
case "UID":
case "Name":
case "Documentation":
case "Type":
if (theObject[theDataHeaders[j]]) {
else {
console.log("> Parsing Complete")
else {
console.log("> Cancelled");

This comment has been minimized.

Copy link

rich-biker commented Mar 28, 2019

Hi Smileham. Thanks for this excellent script. I'm just wondering why you declared the commonProperties list as you don't reference it anywhere? Am I missing something?


This comment has been minimized.

Copy link
Owner Author

smileham commented Jan 29, 2020

(Better late than never)
You're right, I think at some point I was looping through these to "ignore" them when writing the properties out, and then ended up moving to a case statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.