Book a Demo

Author Topic: Difficulty creating correct ConstraintProperty  (Read 7547 times)

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Difficulty creating correct ConstraintProperty
« on: August 20, 2021, 01:38:52 am »
Hi all

I do not succeed in creating by scripting the same element as would be created in the GUI.

My target element is a ConstraintProperty that is automatically created when dragging a constraint property from the toolbox into a parametric diagram. The "Element" tab of the properties of the resulting element shows a "Part" section, in which I can select a Type and refer to an existing ConstraintBlock.

My script is trying to create the same by calling AddNew("name", "constraintProperty") and then setting the ClassifierID to the ElementID of an existing ConstraintBlock. If I inspect the properties of this new element in the GUI, the "Element" tab does not contain the "Part" section, and I find back the referred ConstraintBlock in the Type of the "Property" tab.

Apparently "Types" are existing in different contexts, which confuses a newbie like me. Also I don't know how the "Part" trait can be added to my element, and how to set everything correctly.

Thanks for all advice in this!




KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Difficulty creating correct ConstraintProperty
« Reply #1 on: August 20, 2021, 07:58:56 am »
Try passing "SysML1.4::constraintProperty" into AddNew(). Or "Part" and then set .StereotypeEx to "SysML1.4::constraintProperty".
The Sparx Team
[email protected]

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Difficulty creating correct ConstraintProperty
« Reply #2 on: August 20, 2021, 04:58:25 pm »
Thank you for the suggestions.
My SysML version is 1.5, so I try with "SysML 1.5::constraintProperty".

1) Passing "SysML 1.5::constraintProperty" into AddNew() gives an error "Invalid type".

2) Passing "Part" into AddNew() and afterwards setting StereotypeEx to "SysML 1.5::constraintProperty" doesn't give an error, but the resulting Type is "Property" and Stereotype is empty. So the new element did not become a ConstraintProperty. I suspect that under the hood the value for StereotypeEx is not accepted but no error is raised.

Until now, setting "constraintProperty" in AddNew() had the best effect, as the Stereotype in the "Element" tab of the properties is "SysML 1.5::constraintProperty", but I'm missing this "Part".

Any further thoughts?

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Difficulty creating correct ConstraintProperty
« Reply #3 on: August 20, 2021, 11:40:25 pm »
Finally found out the following works for me:
Code: [Select]
newElement = myBlock.Elements.AddNew("name", "constraintProperty")
newElement.PropertyType = myConstraintBlock.ElementID

It was not the ClassifierID but the PropertyType that I had to set.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Difficulty creating correct ConstraintProperty
« Reply #4 on: August 23, 2021, 08:15:28 am »
Thank you for the suggestions.
My SysML version is 1.5, so I try with "SysML 1.5::constraintProperty".

1) Passing "SysML 1.5::constraintProperty" into AddNew() gives an error "Invalid type".
That's because you need to do what KP says.

2) Passing "Part" into AddNew() and afterwards setting StereotypeEx to "SysML 1.5::constraintProperty" doesn't give an error, but the resulting Type is "Property" and Stereotype is empty. So the new element did not become a ConstraintProperty. I suspect that under the hood the value for StereotypeEx is not accepted but no error is raised.
Because once again, you didn't do what KP said.

Code: [Select]
newElement = myBlock.Elements.AddNew("name", "constraintProperty")
This code is finding the first stereotype with a matching metatype. You can expect it to start getting the stereotype from the wrong profile in the future.

It was not the ClassifierID but the PropertyType that I had to set.

The distinction comes from UML. The metaclass InstanceSpecification has a classifier that can be set. The difference is that InstanceSpecification represents a runtime/conceptual object, and allows you to specify what that actual object is. The metaclass Property (as well as others like Parameter) has a type that can be set. These are the containers to hold the objects, and you specify what type of object the container can hold.

In the EA GUI they function the same way, but the labels on the EA properties will show which one is relevant for any given metaclass.

JoostN

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: Difficulty creating correct ConstraintProperty
« Reply #5 on: August 24, 2021, 12:16:53 am »
Thank you Eve for the further explanation and for warning about the danger of specifying "constraintProperty".
It is indeed not specific enough and might result some day in another StereoType, so you made me try a bit harder, and finally it works. ;D

I was mislead by the stereotype "SysML 1.5::constraintProperty" reported in the GUI: It contains (1) a space and (2) a version 1.5.
I should not keep the space and rather use version 1.4, like "SysML1.4::constraintProperty" as was suggested by KP. Not completely logic for me, but it works now.

Thanks!