Created
February 27, 2023 15:43
-
-
Save RemcoSchellekensNS/a528ba45bf1541920075c1504af975f4 to your computer and use it in GitHub Desktop.
#jarchi script to isolate single view to a new model containing only view and referenced elements in that view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
+++++++++++++++ +++++ | |
+++++++++++++++++ +++++ | |
+++++ +++++ +++++ | |
+++++ +++++ +++++ | |
++++++++++++++++ ++++++++++++++++++ | |
++++++++++++++++++ +++++++++++++++++ | |
+++++ +++++ ++++++ | |
+++++ +++++ ++++++ | |
+++++ ++++++++++++++++++ | |
+++++ +++++++++++++++ | |
Isolate view into separate model | |
Author : Remco Schellekens (remco.schellekens@ns.nl) | |
Licence: MIT https://mit-license.org/ | |
Copies selected view and all elements in model that is | |
being referenced in that view to a new separate model | |
*/ | |
const File = Java.type('java.io.File') | |
var view=null; | |
console.clear(); | |
console.log("Isolate view into separate model "); | |
selectedview=$(selection).first(); | |
if (selectedview.type!="archimate-diagram-model") { | |
window.alert("No view selected..") | |
exit(); | |
} | |
console.log("copying model into new model"); | |
current=model.getPath() | |
tmp=File.createTempFile("archimate",".archimate",null) | |
// Save temporary file for model | |
model.save(tmp.toString()) | |
// make sure save location is set back to original | |
model.save(current) | |
// Load back model from temporary file | |
$.model.load(tmp.toString()).setAsCurrent() | |
model.name=model.name+"-copy" | |
// remove temporary file | |
tmp.delete() | |
// Delete other views | |
console.log("Removing other views"); | |
$("view").each(function(view){ | |
if (selectedview.id != view.id) view.delete() | |
}) | |
// Delete all non-reffed objects | |
console.log("Removing all objects that isn't used by the view"); | |
$("concept").each(function(e) { | |
if($(e).objectRefs().isEmpty()) { | |
e.delete() | |
} | |
}) | |
// Get rid of empty folders | |
console.log("Removing empty folders"); | |
var found=true | |
while(found) { | |
found=false | |
$("folder").each(function (fname){ | |
children=$(fname).children() | |
above=$(fname).parent()[0] | |
if ((children.size()==0)&&(above.type=="folder")) { | |
$(fname).delete() | |
found=true | |
} | |
}) | |
} | |
console.log("Finished") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment