Setting the an Image Asset as an Alternate Image using Sparx’s API

I’ve also been experimenting with image assets, this is what I’ve found so far:

  1. You can use the image assets directly in diagrams, they seem to be treated as class elements…. I’ve been in contact with Sparx, and they don’t recommend using image assets directly in you diagram, the intent is to use them as an alternate image
  2. You can use image assets as the “alternate” image for an element, but you have to set this for each diagram the element appears in… a bit of a pain
  3. Once you set the image asset as the alternate image, you can update the image linked to the image asset and all you diagrams and elements pointing to it are updated.

What I’d like is a way to set the image asset as the “default” appearance for the element, but that doesn’t seem to be possible yet.

So I’m trying to see if I can make a script work around for step 2.

At the moment this is what I’ve figured out:

  • Each image file is stored in the table t_documents that references the GUID of the image asset Element
  • Each image asset element is stored in the t_objects table (like all other elements), element’s GUID = {5E923B0A-B2C7-4761-9739-480DA752DCAE}

When you want to use the image asset for an element in the diagram:

  1. You select an element, then select “appearance->select image asset as alternate image
    Sparx EA updates t_diagramobjects and the ObjectStyle field for the diagramobject representing the element: DUID=608EC5C1;
  2. Sparx EA then updates t_diagram and the StyleEx field for the diagram: OPTIONS_608EC5C1=AIG={5E923B0A-B2C7-4761-9739-480DA752DCAE}:;

So it seems to be that a script could be created that would work by:

  1. Select an Element in a diagram that has already had it’s appearance linked to the image asset
  2. The Script identifies all the diagramobjects for the Element
  3. The Script identifies all diagrams that contain these diagramobjects
  4. The Script would update the in each diagramobject
  5. The Script would update the diagram.styleEx for each diagram contain each diagramobject

Will experiment and post once I figure things out.
What I don’t know right now is how Sparx EA generates the value DUID=608EC5C1;

Leave a Reply

Your email address will not be published. Required fields are marked *