Hide diagram elements with P4C

I am trying to modify a diagram from a Python4Capella script, what I want to do is:
-Clone a diagram with P4C
-Hide some diagram elements with P4C
Is it possible to perform these operations, or P4C doesn’t allow them?

For the second topic another possible way around that I imagined could be to hide the diagram elements basing on some property elements values or attributes values, obviously if it’s possible to set those values with P4C.

At the end what I am interested in are requirement elements in the diagram, I would like to clone a diagram where requirements are present, hide some requirements blocks (filtering on information that is in the code) either modifing directly the diagram if possible or modifiing a value that then will hide the requirement.

Is this achievable with P4C? Which of these things can be done and what cannot be done?

To hide and reveal elements on a diagram you can use:


You can use an instance of the Python class Diagram to get the list of diagram elements:


On a representation element you can use getTarget() to get the referenced semantic element (an element from the Capella model).

To copy a representation you can use:

e_object_query = org.eclipse.sirius.business.api.query.EObjectQuery(myDiagram.get_java_object())
org.eclipse.sirius.business.api.dialect.DialectManager.INSTANCE.copyRepresentation(myDiagram.get_java_object(), 'My representation Copy', e_object_query.getSession(), None)

And if I want to do that from inside a cycle that is iterating on Requirement elements: “for req in se.get_all_contents_by_type(Requirement)”
how do I get the the diagram (in your script “myDiagram”) from the “req” element of the cycle?

myDiagram should be the diagram you want to copy/edit.

From an element, you can list all diagrams it appears on:

for myDiagram in req.get_representing_diagrams():

You can open the capella.py and select the Diagram class, then use CTRL+SHIT+G to show all references to the Diagram class in the simplified Python API. That will give you all the methods that returns Diagram instances.