Topic
4 replies Latest Post - ‏2012-12-20T10:56:36Z by MerlinUK
SystemAdmin
SystemAdmin
1305 Posts
ACCEPTED ANSWER

Pinned topic How do you create an Object using the Java API?

‏2012-12-17T23:58:34Z |
I've attached a screen shot of the Rhapsody UI with the model element I want to create using the Java API. I know I need to use addNewAggr with a metaclass and a name. I've tried metaclass Object; it returns an IRPInstance that in the UI is a Part. Metaclass InstanceSpecification returns an IRPInstanceSpecification and in the UI is an InstanceSpecification. I've tried metaclass ObjectNode, but couldn't get that to create under a Package, so I know that is not it.
Updated on 2012-12-20T10:56:36Z at 2012-12-20T10:56:36Z by MerlinUK
  • SystemAdmin
    SystemAdmin
    1305 Posts
    ACCEPTED ANSWER

    Re: How do you create an Object using the Java API?

    ‏2012-12-18T12:58:58Z  in response to SystemAdmin
    I thought I included the file. Sorry!
    • MerlinUK
      MerlinUK
      106 Posts
      ACCEPTED ANSWER

      Re: How do you create an Object using the Java API?

      ‏2012-12-18T13:14:57Z  in response to SystemAdmin
      Your model is a SysML Model - hence Objects show up as Parts
      If you right-click your project and select Change To > Project then your Parts will become Objects

      You can use AddNewAggr to add Objects but you can also use Package.addGlobalObject()

      Cheers
      Andy
      • SystemAdmin
        SystemAdmin
        1305 Posts
        ACCEPTED ANSWER

        Re: How do you create an Object using the Java API?

        ‏2012-12-19T19:11:31Z  in response to MerlinUK
        Thanks for your reply. I know the SysML profile is in the model, but I didn't do a "Change to" SysML. It was still using the Developer "edition" when I was working in it and when I made the screen shot.
        • MerlinUK
          MerlinUK
          106 Posts
          ACCEPTED ANSWER

          Re: How do you create an Object using the Java API?

          ‏2012-12-20T10:56:36Z  in response to SystemAdmin
          OK I see. I created a project and added SysML to it - but made sure it was a 'Project' and not a 'SysML' and ran the following code: (Assuming that package exists and has a Class called Class1 in it)

          rpy = RhapsodyAppServer.getActiveRhapsodyApplication();
          prj = rpy.activeProject();
          IRPModelElement elt = rpy.getSelectedElement();
          IRPPackage pkg = (IRPPackage) rpy.getSelectedElement();
          pkg.addGlobalObject("newObject", "Class1", "DesignSynthesisPkg");

          I got an Object called newObject - not a Part (Screenshot attached)