Note Image get name and save to property

Started by AG, February 09, 2023, 10:56:55 AM

Previous topic - Next topic

AG

Hi guy's, apologies if question miss-placed as new to forum. I couldn't get a hit on what I trying to do, but actually there could be a better of doing this as well!...

The goal is to us visual icons on top of an Archi View. Further the ability to show or hide any specific type of icon on a specific view.

The method is really straight forward if you just take a note element and colour code it, but this limits to just a square or a rectangle. You can show or hide the note buy toggling the opacity of the fill and line (a couple of smarts using properties allow you to focus on specific notes as well. The issue is to have many different icons you need to have multiple shapes not just colours. we can solve this by adding an image to the note, so if the image is the right shape and colour, we now have many different symbols. Now the issue is is we want to toggle showing and hiding a specific icon type, we need to be able to get and store the name of the image and replace it with no image. Then take the saved image and make it the shown image. To achieve this, we need to get and set the image by name. Getting and saving the image name is where I'm stuck. The image is already in the rep in a zip file, but I was looking to get the image name in JArchi and save to property. Then using the name set the image or remove the image. Am I missing something or is there no way to get the internal zip file name then use that to set? Thanks for any help, including alternate ways to solve this.

Jean-Baptiste Sarrodie

Hi,

Quote from: AG on February 09, 2023, 10:56:55 AMI was looking to get the image name in JArchi and save to property. Then using the name set the image or remove the image. Am I missing something or is there no way to get the internal zip file name then use that to set? Thanks for any help, including alternate ways to solve this.

The internal image name is of no use as it could differ from one model to another. You have to use another approach.

The important trick is that whenever you call the model.createImage() function, if the image you are creating already exist in the model, you won't import it again but get a reference to the already existing one. Thus, if you want to set the "cat.png" image to a note, then simply get the image by doing "var catImage = model.createImage('cat.png');".

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.

AG

Thanks JB that helps heaps. Re cross models, if the script always try's to create the image from a central location it will either create or return reference to existing image? I will test and see. Thanks again...

AG

Ok the following is a test that worked for toggling the image in notes from a blank(transparent) to the original. The aim is to layer icons on elements on a view to indicate certain things, e.g. impact, life cycle stage, health, etc. The reason to hide/show certain icons is so the same view can serve multiple viewpoints. The solution will have a property of note type so you can select which type of note to hide/show and of course you will need to map values to icons and their colours.

/*
 * Create Image Test Archi Script
 */

console.show();
console.clear();
console.log("Create Image Test Archi Script");
// need to change this to actual path could be
var imageExtPath = "/.../images";
var view = selection.filter("archimate-diagram-model").first();
if (view == null){
   window.alert("Please select a view to process in the explorer window");
}else{
   $(view).find("diagram-model-note").each(function(o) {
      var theImage = o.image;
      var theBlankImage = model.createImage(imageExtPath + "blank.png");
      var theOriginalImageExtPath = imageExtPath + $(o).prop("Note Image Name");
      // if this note doesn't have a property with its name then skip
      if (theOriginalImageExtPath !== null){
         var theOriginalImage = model.createImage(theOriginalImageExtPath);
         var theBlankImagePath = theBlankImage.path;
         var theImagePath = theImage.path
         // if the current image is the blank image
         //    if it is and the note had the name of the image saved then reset to original image
         // else set the image to blank image
         if (theBlankImagePath === theImagePath){
            if (theOriginalImage !== null){
               o.image = theOriginalImage;
            };
         }else{   
            o.image = theBlankImage;
         };
      };

   });
};