Optimizing Creating Instances and Initing Slots

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Optimizing Creating Instances and Initing Slots

Postby krausedj@gmail.com » Thu Feb 13, 2020 11:47 am

I am wondering if anyone has any feedback on how I could more efficiently add slot data to newly created instances. Right now I am using jython, and will probably look at migrating to a java plugin, but I expect I will see a similar bottleneck.

So first, here is the example code.

Code: Select all
      class_inst = AutomatonMacroAPI.createElement("InstanceSpecification")


      ModelHelper.createSlotsForDefaultValues(class_inst._getRepresentElement(), True)

      get_slot = class_inst.getSlot()
      total_slots = len(get_slot)

      for slot_index in range(total_slots):
         slot_item = get_slot.get(slot_index)

         if slot_item.getDefining_Feature().getName() in data_item:
            value_spec = ModelHelper.createValueSpecification(

So, in this example, most things don't take too long.
createSlotsForDefaultValues is %16 of the time
createValueSpecification and adding the spec is 12% of the time
get_slot.get(slot_index) is 72% of the time

It seems like there is probably a better way I could do this, instead of iterating through the defaulted slots, if I could do it however createSlotsForDefaultValues does it, that would save me a lot of time.

Scaled up, this macro is taking 20 minutes as I call getSlot().get() 25000 times. I can maybe look at manually creating the slot, and then adding it, but was struggling with setting the defining feature, and that made cameo mad at me.
Forum Newbie
Forum Newbie
Posts: 1
Posts Rating:0
Joined: Thu Feb 13, 2020 11:20 am

Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests