Book a Demo

Author Topic: Create object in simulation from other package doesn't work  (Read 5942 times)

dirk3

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Create object in simulation from other package doesn't work
« on: November 21, 2016, 12:39:04 am »
After creating an object in the effect textbox of an action using the CreateObject method:

sim.decisionMaker = sim.CreateObject("DecisionMaker");

, the object is not created if the Class of the object is not specified in a package resorting under the same package as the activity diagram containing the action. Further references to the object, for instance to methods result in "... is not a method".
If the class is under the same package as the activity diagram everything works fine.

Trying to avoid this problem by using the 'createobject'  special type of action, using an action pin to output the object gives you the opportunity to select the class of object from anywhere in the model. However.. using a class from a packages elsewhere in the model as classifier results in the same problem: the simulation just hangs. Using the class from an underlying package works fine again. This is a great drawback in using simulation, because it seems impossible to define your activities and class packages indepently.

Anyone who knows if this is by design, or perhaps a way to work around this problem?

Thanks,
Gerard.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Create object in simulation from other package doesn't work
« Reply #1 on: November 21, 2016, 08:51:59 am »
The simulator uses the XMI for the package to run.

I think you can add a Package Import from the simulation package to the package owning the types you need to use.

It's also possible to use a dependency to a single type. (I think still from the package)

gleeuw

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Create object in simulation from other package doesn't work
« Reply #2 on: November 22, 2016, 03:21:59 am »
Hi,
I have the same problem with simulation.
The class that is used in CreateObject("ClassName") must be in the same or under the package of the simulated diagram. Classes in the same model as the diagram can't be used if the're not under the diagram.
Please see this picture illustrating the problem: https://1drv.ms/i/s!ApKWkMQR4BolgaMmldJeWLMRCGd7sg
Using an xmi export/import as Simon suggests does not work, results in 'already existing class'  in the model.
Using a dependency to the class also doesn't work.

Any help or work around is much appreciated.
Regards,
Peter.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Create object in simulation from other package doesn't work
« Reply #3 on: November 22, 2016, 08:50:52 am »
My suggestion was not to do an XMI export/import.

Create a package import connector from the package you are simulating to the package containing the class you want to create.

From what I can see, support for that was added in 12.1.1223

gleeuw

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Create object in simulation from other package doesn't work
« Reply #4 on: November 22, 2016, 07:27:06 pm »
Adding a package import connector did the trick!
My suggestion for Sparx would be to add this info to the help page about using objects in simulations.

Simon, thank you much for the clarification!
Regards,
Peter.