Get the list of element owned by a package using a Macro

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Get the list of element owned by a package using a Macro

Postby Alban » Thu Jun 17, 2021 7:53 am

Hello everyone,
I am currently trying to access elements owned by a folder in order to change one of their properties using a macro in Jython. The goal is to change the default value (real value) of these elements with a value contained in an XML file that I have previously parsed.
Here is my code:

Code: Select all

import com
import java.util.Collection
from com.nomagic.magicdraw.automaton import AutomatonMacroAPI
from com.nomagic.magicdraw.core import Application
from com.nomagic.magicdraw.openapi.uml import SessionManager

import xml.etree.ElementTree as ET
tree = ET.parse('MyFile.xml')
root = tree.getroot()       

try:
   SessionManager.getInstance().createSession("Automaton_Macro_Script_Execute")
   ele0 = AutomatonMacroAPI.getModelData()
   ele1 = AutomatonMacroAPI.getOpaqueObject(ele0._getChild("main_Package")._getChild("Sub-Package"))
   
   for n in ele1.getOwnedElement():
       ele2 = n._getChild("CETOL Val").getDefault_Value()
       ele2.setValue(float(root[0][0].get('MyValue')))

except:
   SessionManager.getInstance().closeSession()
   raise
else:
   SessionManager.getInstance().closeSession()



Problem i'm not sure how to use the getOwnedElement() function...
If someone can enlighten me on the use of this function or on a code that would allow to get this list of element contained in a folder I would be very grateful.

Thank you in advance :D ,
Alban
Alban
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Thu Jun 17, 2021 7:28 am

Re: Get the list of element owned by a package using a Macro

Postby cfeperk@gmail.com » Fri Jul 23, 2021 5:23 am

You can use the macro recorder to record the macro or write your own macro script in VBA. Learn how to find help on Visual Basic elements.

My Card Statement
cfeperk@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Fri Jul 23, 2021 5:21 am

Re: Get the list of element owned by a package using a Macro

Postby graf@itemis.de » Mon Sep 06, 2021 7:36 am

getOwnedElement() just returns a collection of Element (s) owned by the package.
graf@itemis.de
Forum Newbie
Forum Newbie
 
Posts: 19
Posts Rating:0
Joined: Thu Dec 06, 2018 5:45 am

Re: Get the list of element owned by a package using a Macro

Postby mamedovivan695@gmail.com » Thu Sep 16, 2021 5:30 am

Thanks for the step by step tutorial.

omegle
mamedovivan695@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Thu Sep 16, 2021 5:29 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests