check [Solved] How to iterating through packages

1 month 4 weeks ago - 1 month 4 weeks ago #5328 by Ralf Ebert
Hi,

to generate the necessary tables for my finite state machines I'll l try to find all diagrams which are reachable in a package and its sub packages. I tried to find a wayby reading the API guides but I'm not able to find it. Are there code snippets for modelio 3.7.1 available which can help me to iterate throught the packages?

Best regards
Ralf Ebert

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

1 month 4 weeks ago #5329 by Ralf Ebert
Hi,

meanwhile I've found it:
for ownedElement in package.getOwnedElement():
	print("- " + ownedElement.getName())	

Best regards
Ralf Ebert

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

1 month 4 weeks ago #5330 by ebr
Hi Ralf,

Just a little tip which, I hope, would be useful.

Let's imagine you have the following model.



The following code:
for ownedElement in elt.getOwnedElement():
	print("- " + ownedElement.getName())

will return all "ModelElement" (this includes, Packages, Classes, Interfaces, etc.) owned by the selected Package cf. below

- Package
- Package1
- Class


But you can filter the returned list by a given Metaclass. For example:
for ownedElement in elt.getOwnedElement(Package):
	print("- " + ownedElement.getName())

will return only package elements i.e.

- Package
- Package1


Hoping it helps,
EBR
Attachments:
The following user(s) said Thank You: Ralf Ebert

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

1 month 3 weeks ago #5332 by Ralf Ebert
Hi ebr,

Thank you for your tip.

Best regards
Ralf Ebert

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

Moderators: chmcma
Time to create page: 0.151 seconds
^ Back to Top