How to add/create a Node to a Model from OpenAPI
Hi
I am adding a Node in my model using OpenAPI,I have used the following code
but I am getting illegal model access exception and cannot be able to add the node in the model .So can you please suggest a way to add a node and its propeties to a model programatically. Thanks in advance
I am adding a Node in my model using OpenAPI,I have used the following code
Add Node
MPSModuleRepository.getInstance().getModelAccess().runWriteAction(new Runnable() { public void run() { for (SModule sModule : MPSModuleRepository.getInstance().getModules()) { if (sModule.getModuleName().equalsIgnoreCase(" my module name")) { smodule = sModule; modelaccess = smodule.getRepository().getModelAccess(); info "modelaccess" + modelaccess.canWrite(); break; } } } \\it has only one model for (SModel Model : smodule.getModels()) { if (Model instanceof EditableSModel) { smodel = Model as EditableSModel; } SNode snode = new SNode("ACBLKBSD"); smodel.addRootNode(snode); } } });
but I am getting illegal model access exception and cannot be able to add the node in the model .So can you please suggest a way to add a node and its propeties to a model programatically. Thanks in advance
Please sign in to leave a comment.
Can you please suggest any other way for adding the node
we tried it with modelacces.execute command still we are getting java.lang.UnsupportedOperationException ,are we missing anything ?
Thanks in advance
Vaclav
Thanks for your quick reply ,I am sharing you entire class (I have added in the project component because i want my node to be added as soon as model is created in project .Can you please help me in this aspect
I am getting the following Exception
This is the exception trace i have got ,can you please help me in adding a node from OpenAPI
Instead of MPSModuleRepository, please use ProjectRepository(myProject). You can either instantiate it or use ProjectHelper.getProjectReposiory() or ProjectHelper.getModelAccess() right away.