PC created through Script do not behave like the ones created manually

I created several PC using the sample script “Import_physical_components_from_xlsx.py”.
These are automatically added to my [PCBD], which is good.

When I try to assign them to a NodePC as a container, weird things start happening:

  • if I use the “contained in” option from the Palette, nothing happens;
  • if I drag the new PC onto the NodePC in the Project Explorer, the PC moves into the NodePC as far as the Project Explorer is concerned, but the arrows still don’t appear
  • in the Mass Visualization View, I can see that manually created items which are contained into a PC, have this PC listed as “Parent” and as “Referencing Component”, while script-created ones do not, even if they are contained into another PC in the project explorer
  • if I run a script which identifies the container of each PC through the function “get_container()”, this works the same for all contained PC, wether they are manually or script-created.

Is there an explanation for this phenomenon? A way to avoid it? … Would this be easier using the Java API directly?

Many thanks

I think the script is not creating all model elements like Capella does, for instance the Part object. By looking a the Java code the CapellaElementExt.creationService() method is called. We should probably add a call to this method in the script to:

            #add the new PhysicalComponent

Let me know if it fix this issue.

1 Like

Hello Yvan, thank you very much for answering.
I don’t think the Python interpreter can deal with that expression. It returns an error:
“Undefined variable: org”.
Or am I missing some library?

Thank you

The PyDev editor and Python can’t deal with this, but EASE can. You can run the script as an EASE script. You can also remove the error shown by PyDev by adding org to the list of known symbols in the preference page of PyDev.

OOoooh yes… true, I forgot that sometimes errors can be ignored in this setup.
This does solve the problem, as long as it is the last operation that is done on the PC in the Script.
Thank you very much for this solution!
Could you also point me towards how you knew what to add? I think this kind of problems might be encountered in other cases too, right?

Anyways, thank you very much!


Thank you for reporting this issue.

I looked at the diagram definition (.odesign files) and what services they use to create PhysicalComponent. Then I followed Java calls…

And yes I think this call could be made whenever an object is created. The thing is, the object must be already connected to the model (added to a containment reference) for this call to work.

1 Like