Skip to content

Instantly share code, notes, and snippets.

@RemcoSchellekensNS
Created February 27, 2023 15:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RemcoSchellekensNS/a528ba45bf1541920075c1504af975f4 to your computer and use it in GitHub Desktop.
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
/*
+++++++++++++++ +++++
+++++++++++++++++ +++++
+++++ +++++ +++++
+++++ +++++ +++++
++++++++++++++++ ++++++++++++++++++
++++++++++++++++++ +++++++++++++++++
+++++ +++++ ++++++
+++++ +++++ ++++++
+++++ ++++++++++++++++++
+++++ +++++++++++++++
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