Page 1 of 1

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

PostPosted: Thu Jun 17, 2021 7:53 am
by Alban
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

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

PostPosted: Fri Jul 23, 2021 5:23 am
by cfeperk@gmail.com
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

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

PostPosted: Mon Sep 06, 2021 7:36 am
by graf@itemis.de
getOwnedElement() just returns a collection of Element (s) owned by the package.

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

PostPosted: Thu Sep 16, 2021 5:30 am
by mamedovivan695@gmail.com
Thanks for the step by step tutorial.

omegle