Advanced Management of Project Usages via MagicDraw OpenAPI

openAPI API  

This post regards the MagicDraw OpenAPI as shipped with Cameo Enterprise Architecture 2024x/2026x.

Top-level question: 

How can I change the URI of an unloaded attached project / used project / module using the MagicDraw OpenAPI?

Essentially, when attempting to open a MagicDraw project, the user may be prompted with "the used projec xyz cannot be found. Would you like to select it?", and then the user can select the correct used project from the file system, which updates the used projects name and location. How can this be done using the OpenAPI?

Context (The problem I am trying to solve): 

Imagine that I have a hundred Cameo/MagicDraw models (.mdzip files) from my organization and numerous others. A large number of these models have dependencies amongst each other through project usages. I need to organize and publish this collection of models for stakeholders (Teamwork Cloud is not an option- the publication is done to a file-hosting system).

Prior to publication, the project usages must all be reconfigured, as the names and storage locations of the models change when they are transferred to my organization. 

For example, two models may have had this notional folder structure originally, with primaryProject.mdzip using usedProject.mdzip:

C:/Users/randomUser/Documents/primaryProject.mdzip
C:/Users/randomUser/Documents/usedProject.mdzip

However, when I receive these models into my org and I am organizing these models for publication, they get renamed and have different file paths, with the folder ModelCollection containing the folder structure that will be published: 

C:/Users/myUser/Documents/ModelCollection/FolderA/xyz_PrimaryProject_20260831.mdzip
C:/Users/myUser/Documents/ModelCollection/FolderA/FolderB/FolderC/xyz_UsedProject_20260831.mdzip

This means that, for each model with usages that is getting published, I must open it, re-configure the used project name and location, and modify the project's used project search directories (using relative paths). Without doing this, stakeholders that download the collection of models will be met with a huge number of "cannot find used project xyz" warning when opening the models, and the names they are told to look for won't match the names of the files they have been provided.

This process is incredibly time-intensive, and has to be done and re-done often.

The Goal and What has been Tried:

I am trying to create a Command Line Interface (CLI) Jython script that extends com.nomagic.magicdraw.commandline.CommandLine (or ProjectCommandLine). Given a target folder, it iterates through subfolders and finds all .mdzip files that are present, and then automatically re-maps project usages for each .mdzip project that has project usages. 

I have the CLI Jython script working and running Cameo headlessly. 

I am able to build a list of all used project IDs for a given project and locate the name-changed .mdzip's containing those used projects. 

I am able to update the project's module search directories with relative file paths.

What I am unable to do is to change the URI of an attached project. 

I have read through the OpenAPI documentation for 2021x, 2024x, and 2026x extensively.

useModule(),  attachModule(), and findOrLoadLocalModule() cannot be used because an attached project with the same Project ID is already attached to the primary project. 

ProjectsManager.reloadModule() cannot be used with a new ProjectDescriptor because the original module is unable to be opened/loaded. 

ModulesService.findOrLoadModule() cannot find the new-name used project from the context of the parent project.

The ProjectAttachmentConfiguration has only getters for the protected locationURI, no setters, so it cannot be changed directly. I did try to use the ProjectAttachmentConfiguration constructor that took a ProjectAttachmentConfiguration and a new URI as arguments and to use that updated ProjectAttachmentConfiguration in various ways, but without success.

I have tried ModulesService.detachModules() and removeModules() followed by attaching the updated-name used project, but this damages relations and diagrams in the primary model (appears destructive). The documentation is also not clear on the difference between detach and remove.

I have tried more than I am writing up here, but I wanted to show at least some homework. 

Essentially, when attempting to open a MagicDraw project, the user may be prompted with "the used project xyz cannot be found. Would you like to select it?", and then the user can select the correct used project from the file system, which updates the used projects name and location. How can this be done using the OpenAPI?