Macro for Redefining Generalized Value Properties

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Macro for Redefining Generalized Value Properties

Postby » Sun May 12, 2019 7:17 pm

I am trying to automate the 'Redefining' of 'Value Properties' of a Block which is 'Generalized' from another block and could use help with the code

The current process is as follows:
1. Create a 'Generalize' relationship between the 'Master' block and 'Generalized Block' as shown in figure 'Generalize_relationship.png'

2. Go to 'Generalized' Block properties and Redefine the Value Properties to remove the '^' symbol as shown in 'Redefine_property.png'

We could have up to 100 blocks, and I am trying to create a macro that does the above for all selected blocks (Generalization to the Master Block can be assumed to be done via Common Properties). I have the attached code:

Code: Select all
from com.nomagic.magicdraw.core import Application
from com.nomagic.uml2.ext.magicdraw.classes.mdkernel import NamedElement;
from com.nomagic.magicdraw.openapi.uml import SessionManager
from com.nomagic.magicdraw.automaton import AutomatonMacroAPI

project = Application.getInstance().getProject()   #get the project
factory = project.getElementsFactory() #Get Elements

if not(SessionManager.getInstance().isSessionCreated(project)):
    SessionManager.getInstance().createSession(project, "Edit");

#Get selected Node
selectedNode = Application.getInstance().getMainFrame().getBrowser().getContainmentTree().getSelectedNode()

if selectedNode is not None:
     selectedElement = selectedNode.getData()
#Get Parameter to inherit from
ParamTuning = project.getElementByID("2. MCA Apps::1 - App generic::app tuning parameter::ParamName")

#AutomatonMacroAPI functions to replace with OpenAPI
ele0 = AutomatonMacroAPI.getModelData()
ele1 = AutomatonMacroAPI.createElement("Property")

#Attempt (Failed) at using OpenAPI to do above
valueProperty = factory.createPropertyInstance()
valueProperty.setName("my value property")
#valueProperty.getRedefinedProperty().add(ParamTuning)  #This is where it errors out


Here is where I am stuck and could use help.
1. Trying to replace the Automaton with OpenAPI. The AutomatonAPI seems to really slow things down, and I am not 100% sure what it is doing. Any suggestions?
2. Still not sure how to do this for all selected blocks. Right now the code is doing it for one selected element.

P.S. Any recommendations for an IDE for Jython Macro scripting? Right now using the Notification Window, but getting types etc. is quite cumbersome.
You do not have the required permissions to view the files attached to this post.
Forum Newbie
Forum Newbie
Posts: 2
Posts Rating:0
Joined: Fri Feb 15, 2019 8:00 am

Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests