Is there any way through wich the format (for instance the colour) of a block could be modified from a Python4Capella script?
My need would be to highlight some blocks/boxes/chains in PAB,SAB or LAB, changing their colours on the diagrams, depending on informations imported in Capella from external documents (for example an excel).
I don’t know if it’s feasible but i thought it was worth asking.
Thanks for any help.
It probably has to do with some elements mentioned here:
Graphical coordinates of a Capella Element inside a Diagram (Node/Edge…) - Scripting - Eclipse Capella Forum (mbse-capella.org)
I was not quite able to achieve it yet (Involving GMF stuff etc).
Anyway I am following your thread, this is interesting
As mentioned by Kabe, the Python API is not designed to handle this. I’m not exactly sure where this information is stored, but I think it’s in the GMF annotation model. So same as the linked thread above.
You can try to do it manually and see what difference you get in the .aird file. It should give you an idea how to access it. But the first step would be getting the GMF annotation model and the Python API wlll not help. Note that you can call Java methods on Java objects (pythonObject.get_java_object()). An other way to do this could be adding a method in the Sirius module to add a get_gmf_node() or something similar method. But then we would also need to add the GMF node in the simplified API and it’s not exactly the goal of this API.
As was gonna comment about this sentence:
I was going to say that it appers that indeed playing with graphics is a clear need and Python could be great for that oh well!
Yes, I agree that it is needed but for the moment developments focused on the simplified Capella API.
Some temporary workaround (this is probably not the right way to do it and the colouring is gone is you refresh your diagram):
se = model.get_system_engineering() #(hardcoded) gets a DRepresentation Descriptor for the first diagram of the first function.... diagram = se.get_all_contents_by_type(SystemFunction).get_representing_diagrams() #gets the representation representation = diagram.get_java_object().getRepresentation() model.start_transaction() try: for repElements in representation.getRepresentationElements(): #Gets its style# ElementStyle = repElements.getOwnedStyle() color = ElementStyle.getColor() color = color.create(100,100,100) ElementStyle.setColor(color) except: # if something went wrong we rollback the transaction model.rollback_transaction() raise else: # if everything is ok we commit the transaction model.commit_transaction() model.save()
Tested it out of curiosity, but the P4C seems to not like the use of the function (getColor()) in this example:
Tha diagrams are SDFB, if that’s relevant.
On EdgeStyle you need to use getStrokeColor() to get the color.