How to extract part of your model based on folder structure

Started by bigyin, March 15, 2022, 14:58:16 PM

Previous topic - Next topic

bigyin

I have a model with the views and elements structured in folders, any idea or script available that will allow me to select the part of the folder structure I would like to extract, and create a new file with all the relevel elements and the folders the they were originally in etc.

In effect a copy / paste by including the structure.

I know it can be done manually deleting all that you don't want, leaving the bit that you do, but its time consuming.

Jean-Baptiste Sarrodie

Hi,

This can be done through a script but this is not straightforward and I didn't do it myself.

I think it requires the following steps:
1. Make sure some folders are selected and save the list (i.e. the collection) in a variable
2. Make sur the current model is saved. For this, prompt the user to confirm and then call model.save(). Save the path to the model into a variable.
3. Prompt the user to get the name of the target model file. Now save the model into this new file using model.save("path/test.archimate")
4. Now that we are working on a copy of the model, iterate on all views: get their parents through $(viewObject).parents() and check if the parents' list includes some of your selected folders. If not, delete the view.
5. Now iterate on all concepts: if they don't belong to any remaining view, then get their parents through $(someConcept).parents() and check if the parents' list includes some of your selected folders. If not, delete the concept.
6. Now iterate on all folders: get their parents through $(someFolder).parents() and check if the parents' list includes some of your selected folders. If not, delete the folder (of course exclude default top-level folders).
7. Rename the model (maybe add "(filtered)" to the current name)
8. Save the model
9. Reopen the original model into the UI using: $.model.load("/path/test.archimate").setAsCurrent(); model.openInUI()

Regards,

JB
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

bigyin