Exporting diagrams as images

Hello,
I noticed that the function called “export_as_image()” inside the diagram class was “KO”.
Any idea how to fix it?

Here it is:

    def export_as_image(self, file_path):
        """
        status: KO
        """
        Sirius.export_image(self.get_java_object(), file_path)

Thank you.

Well, in fact, it works.
You can try with a model with diagrams in Physical Architecture Structure:

project_name = "C2M_TEST_01" # Change for your model
model = CapellaModel()
model.open(f'/{project_name}/{project_name}.aird')

folder = CapellaPlatform.getFolder(CapellaPlatform.getProject(project_name), "images")
folder_path = CapellaPlatform.getAbsolutePath(folder)

for diagram in (model
        .get_system_engineering()
        .get_physical_architecture()
        .get_physical_component_pkg()
        .get_owned_diagrams()):
    print("Export diagram", diagram.get_name())
    diagram.export_as_image(folder_path + "/" + diagram.get_name() + ".jpg")
    
CapellaPlatform.refresh(folder)

I don’t know what this comment means.
However, this function is limited when compared to the one in diagram: default resolution, only jpg.

1 Like

This comment is added to the specification Capella model by generated unit test, but in this case the generated test fails… but the method works. The API is then generated from the specification model.

1 Like

Thanks a lot to both.
I have few questions:
For this function:

def get_diagrams(self, diagram_type):
        """
        status: OK
        """
        res = []
        descriptors = Sirius.get_diagrams(self.session, diagram_type)
        for descriptor in descriptors:
            res.append(Diagram(descriptor))
        return res

What type of “diagram_type” are we talking about?
I can simply write A=CapellaModel.get_diagrams(LAB)?
Or is it A=CapellaModel.get_diagrams(“LAB”)
Or: A=CapellaModel.get_diagrams(Logical Architecture Blank)
Or: A=CapellaModel.get_diagrams(“Logical Architecture Blank”)
I was wondering what is exactly a “diagram type”, is it a “string”?

Now question about the rest of the functions:

  • We have (get_owned_diagrams()), i tried this on a Logical Component Package, and it worked fine.
  • What about (def get_representing_diagrams(self)) what differntiate it from the rest?
  • What does (def get_element_of_interest_for_diagrams(self): ) do compared to others?
  • Same for (def get_contextual_element_for_diagrams(self): ) ?

It’s the name of the representation description, for instance “Logical Architecture Blank”. The implementation is available here. And it will return all LAB diagrams from the given Session.

  • get_owned_diagrams() will return all diagrams defined on the given object. The object is represented by the background of a diagram for instance.
  • get_representing_diagrams() will return all representations where the given element appears. At least one DRepresentationElement is visible on the representation for this element.
  • get_element_of_interest_for_diagrams() is a concept defined by Capella. It returns what is returned by the “Element of Interest for Diagram” query, It is shown in the contextual explorer. From the Capella documentation: " The Elements of Interest property allows to associate a Diagram with an arbitrary list of model elements that are of special interest to the diagram. The Semantic Browser view displays the relation between a Diagram and its Elements of Interest.".
  • get_contextual_element_for_diagrams() its a concept defined by Capella. it call the org.polarsys.capella.core.semantic.queries.sirius.annotation.eoi.RepresentationToContextualElement query. In the Capella documentation there is a section “Diagram Concepts” they are some explanations.
1 Like

Hello, I have another question regarding Diagram Python Objects.
I Noticed they had this form:
<main.Diagram object at 0x000001B3FCC961C8
This Java object form:
org.eclipse.sirius.viewpoint.impl.DRepresentationDescriptorImp…
And this eClass form:
org.eclipse.emf.ecore.impl.EClassImpl@45e49d3d (name: DRepresentationDescriptor)…

Question: Is there a way to find the type of the diagram held on one of this variables without its name? Meaning is there a way to find if a diagram is a LAB (Logical Architecture Blank Diagram) without checking its name ([LAB] …diagramName)
Let’s imagine we don’t have ([LAB]) At the beginning thus the name cannot tell us if it’s an LAB or not.

Edit: sorry too many questions about diagrams today

Yes, There is no Python API for that, but you can use the Java API for that:

diagram.get_java_object().getDescription().getName()
1 Like