file How to access the root package in modelio 3.3

4 years 11 months ago - 4 years 11 months ago #3250 by ebr
Hi ua138,

If we imagine that you have the following structure.



The following line will give you acces to the package named project1
print modelingSession.getModel().getModelRoots().get(0).getModel()

Hoping it helps,

EBR
Attachments:

Please Log in or Create an account to join the conversation.

4 years 5 months ago - 4 years 5 months ago #3596 by asefth
Hi,

I'm surprised not to be able to do very simple things.
As concepts are clear for me, I must be on a wrong way with using incorrect syntax.

e.g. model navigation:

I can get the session in an object session
IModelingSession session = Modelio.getInstance().getModelingSession();

But I can't get the root package for navigating in the model, with the following code:
Package root = session.getModel().getRoot();

As exactly expressed in the wiki Developer Manual-API :
http://forge.modelio.org/projects/modelio3-moduledevelopersmanuals-api/wiki/Model_services

The same with
getModel().getModelRoots().get(0).getModel()

as described in
Modelio Dev Manual API

Can you pls. indicate me what is the right way for doing that and where is the reference up-to-date documentation (API, reference examples, targeted tutorials)?
EDIT : API is fine. Small validated examples with clear indication about the setup used for the example would be appreciated.
(purpose: developping a module)

Thanks
Regards

Please Log in or Create an account to join the conversation.

4 years 5 months ago - 4 years 5 months ago #3597 by ua138
.
The following user(s) said Thank You: asefth

Please Log in or Create an account to join the conversation.

4 years 5 months ago #3598 by pan
Hi asefth,

It's pretty random to use get($i) because we don't know necessarily the position of the target model.

I suggest you to test the name of the project.
IModelingSession session = Modelio.getInstance().getModelingSession();

for rootObj in session.getModel().getModelRoots(){
	if (rootObj instanceof Project) {
		root = rootObj.getModel();
		if (root.getName().equals("A Project name")) {
			//Do something
		}
	}
}

Hope this helps

Please Log in or Create an account to join the conversation.

4 years 5 months ago - 4 years 5 months ago #3601 by asefth
Hi pan,

starting from your code, I finally get to the following with no error (with the relevant import org.***)
import org.modelio.api.model.*;
import org.modelio.api.modelio.Modelio;
import org.modelio.metamodel.mda.Project;
import org.modelio.metamodel.uml.statik.Package;
import org.modelio.vcore.smkernel.mapi.MObject;

public class Test {
	
	public static void getRootOfMyModel() {
		IModelingSession session = Modelio.getInstance().getModelingSession();
		for (MObject rootObj : session.getModel().getModelRoots() ) {
			if (rootObj instanceof Project) {
				Package root = ((Project) rootObj).getModel();
				if (root.getName().equals("A Project name")) {
					//Do something
				}
			}
		}
	}
}

PS : 'for' requires parenthesis in my seutp (it may be a meaningless error in your quick example; or you have a library that allows not to use parenthesis!)

So, it appears to be a problem that could be avoided thanks to:
- an accurate knowledge about the top elements (I understand: Project and Models and Models'root within Modelio)
- the strict respect of object's type declaration (e.g. MObjet rootObj instead of rootObj)
- and about the required packages (which is the easiest requirement)

In order to avoid to lose time with that kind of problem, what is the "central point" to look at ?
Is it the Metamodel user guide ?

Thanks
Regards

Please Log in or Create an account to join the conversation.

4 years 5 months ago #3604 by pan
Hi asefth,

sorry for my code. It was a mix of python and Java :whistle:

I'll try to make clear the steps to create a module. Maybe you already know some steps but I prefer to give each steps so it can help other users.

1 - Create a module
It is the starting point. It allows to understand how to package a module and which tools to use.

2 - Understand the main concepts of a Module and the integration with Modelio
It explains the main concepts for developing a module. It presents a complete example for creating a module with detailed steps (More complete than a simple tutorial).

3 - Description of the API
It explains how to access different parts of Modelio (model, diagrams, audit, log, ...).
In the Accessing the Modelio API services section, it is possible that the code is not up-to-date with Modelio 3.3. I think it should be updated.

4 - [url=Modelio 3.3 - Metamodel documentation]Metamodel 3.3 documentation[/url] and [url=JavaDoc documentation of the API]Modelio 3.3 Javadoc documentation of the API[/url]
It is documentation for advanced users. It is up-to-date. If some calls used in previous steps are deprecated, you can find the updated calls on these documentations.

Hope this helps,
BR

Please Log in or Create an account to join the conversation.

Moderators: tmachmaab
Time to create page: 0.164 seconds
^ Back to Top