How to Let Users Choose the Target Project in a Python4Capella Script?

Hello,

When creating a script that interacts with a model using Python4Capella, we usually specify which Capella project the script should target through a “path” variable, such as path = "Project/Project.aird".

However, I would like to avoid having the user manually change the project name each time they run the script. I looked into this, and it seems that I cannot use the input() function in Capella to let the user type directly into the console.

Would you have any idea how I could handle this? Ideally, a dropdown menu listing the available projects would be the best solution.

Thank you in advance,

You can create a menu that can be launched from the Capella IProject or the *.aird IFile

# name                 : My Logic
# script-type          : Python
# description          : Does My Logic
# popup                : enableFor(org.eclipse.core.resources.IFile)

path = CapellaPlatform.getFirstSelectedElement().getFullPath().toString()[1:]
my_logic(path)

You might want to check if the selected file is an *.aird file.

Thank you for the answer, it works!

1 Like