Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Jamo on July 30, 2020, 12:20:38 am

Title: Custom Metamodel Diagram View
Post by: Jamo on July 30, 2020, 12:20:38 am
Hi all.

I've been trying to build a custom metamodel diagram view according to the documentation (https://sparxsystems.com/enterprise_architect_user_guide/14.0/modeling_tools/custommetamodelview.html) but I can't get it to work and I wonder why. Maybe I'm misunderstood or overlooked something.
My Model is built as follows

Model
-Package1
--(PackageDiagram) Package1
--<<profile>> MyProfile
---(PackageDiagram) MyProfile
---<<profile>> MyView
----(ClassDiagram) MyView
----<<view specification>> MyView
----<<stereotype>> SysML1.4::Block
----<<stereotype>> SysML1.4::Block Definition

MyView extends SysML1.4::Block Definition and exposes SysML1.4::Block as shown in the documentation in the last row of the table. Both stereotypes are abstract. I omitted the other elements, since they are just more extensions for elements in the toolbox.

I saved all diagrams and then exported the profile MyProfile via "Publish Package as UML Profile". Then I generated the MDG file and included the profile. I did not select any other functions like Toolboxes etc. When I import the MDG, I can find the technology in the MDG Technologies overview and I can also select it in the toolbox (Although no toolbox is defined for it, it just shows Common, Common Relationships, and Artifacts all folded in). When I try to create a new diagram, my custom view should appear under SysML 1.5, Block Definition as MyProfile::MyView, but it is not there.

I also tried out the instructions to "Create Custom Diagram Profiles" (https://www.sparxsystems.com/enterprise_architect_user_guide/15.1/modeling/custom_diagram_types.html, which seems really similar Custom Metamodel Diagram Views), but did not have any success with it either.

Any suggestions?
Title: Re: Custom Metamodel Diagram View
Post by: Jamo on July 30, 2020, 01:56:40 am
Addition to the Custom Diagram Profile:

Managed to make it work after all, but have a follow-up question. In step 5 of the documentation it is described how to set the properties of the custom diagram. With the attribute "toolbox", you can select the default toolbox that is displayed when switching between different diagrams.

Setting this value to UML::Component or Extended::Construction correctly leads to the Class or Component toolboxes being displayed when selecting the diagram. However, this does not seem to work with "non-basic" toolboxes such as SysML 1.5::SysML 1.5 Internal Block. (All toolbox references where taken from the Find Toolbox Item tool)

I was wondering if this finding is correct and the normal user cannot set custom toolboxes for custom diagrams or if, once again, I'm just missing something.

Documentation: https://www.sparxsystems.com/enterprise_architect_user_guide/15.1/modeling/custom_diagram_types.html
Title: Re: Custom Metamodel Diagram View
Post by: Eve on July 30, 2020, 07:21:45 am
Both parts of the name you have used there are the "friendly" names. The actual id is SysML1.4::InternalBlock.

PS. The linked help includes the following hint to find the id to use for non-uml diagrams.

Quote
Note: If you do not know the fully qualified name of the diagram type you are extending, query the API to get the 'Metatype' field. In a Javascript console you can use:
?GetCurrentDiagram().MetaType
Title: Re: Custom Metamodel Diagram View
Post by: Jamo on July 30, 2020, 08:04:27 pm
Thanks for the clarification. A bit confusing, but it's good to know how to find the "true names" of diagrams.

But how do I find the true name of a toolbox? I couldn't find a corresponding console query.
Especially if I built the toolbox myself, I figured it should just be name I've given it. If I check the xml file for my toolbox I don't see any metatype attribute.
Title: Re: Custom Metamodel Diagram View
Post by: Eve on July 31, 2020, 08:27:16 am
There's no direct query for getting a toolbox name. In most circumstances you are referring to a toolbox you are creating.
Title: Re: Custom Metamodel Diagram View
Post by: Jamo on July 31, 2020, 06:15:31 pm
Indeed. While going through all the different possibilities to refer to a custom toolbox, I figured out that it was in fact just the toolbox name I had to refer to, without the name of the profile or the MDG technology.

So instead of MyProfile::MyToolbox, the string MyToolbox is sufficient. That's a bit confusing since you cannot refer to the UML Component toolbox with Component but have to use UML::Component.
Title: Re: Custom Metamodel Diagram View
Post by: Eve on August 03, 2020, 08:12:44 am
So instead of MyProfile::MyToolbox, the string MyToolbox is sufficient. That's a bit confusing since you cannot refer to the UML Component toolbox with Component but have to use UML::Component.
Within your technology you are already in your namespace. UML isn't the default namespace.
Title: Re: Custom Metamodel Diagram View
Post by: Plonka on February 27, 2025, 02:58:26 am
Can someone please explain how this works? 
I opend a diagram and then went to Specialize -> Tools -> JavaScript and entered the command.
Result was: GetCurrentDiagram(...) is undefined.
I think I need to define which Diagram I want the Metatype from but I don't know how...


Both parts of the name you have used there are the "friendly" names. The actual id is SysML1.4::InternalBlock.

PS. The linked help includes the following hint to find the id to use for non-uml diagrams.

Quote
Note: If you do not know the fully qualified name of the diagram type you are extending, query the API to get the 'Metatype' field. In a Javascript console you can use:
?GetCurrentDiagram().MetaType
Title: Re: Custom Metamodel Diagram View
Post by: Takeshi K on February 27, 2025, 09:36:19 am
Hello,

The reason of the error is that the current diagram is 'null' because the JavaScript console is active (the 'current'). I guess that there is no way to run the command without activating the JavaScript console tab.

If you enter ?GetCurrentDiagram(123).MetaType (which 123 should be the Diagram ID of the target diagram) to the console command area, the console returns the value of the MetaType correctly.

HTH,

Title: Re: Custom Metamodel Diagram View
Post by: Plonka on February 27, 2025, 08:03:31 pm
Thanks Takeshi,

I found this Link: https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/javascrip_console_the.html

The commands are working for a SysML Block Element I selected in the tree

currentElement = Repository.GetTreeSelectedObject()
Session.Output("Selected ElementID: "+currentElement.ElementID)
->Selected ElementID: 12


But this does not work for diagrams I select in the browser tree.

And I can not find the diagram ID. Only the GUID but this is the wrong one.

Maybe you know where I am wrong or what I am misssing.

Kind regards

Plonka

Title: Re: Custom Metamodel Diagram View
Post by: Elpis on February 28, 2025, 12:20:42 am
currentElement = Repository.GetTreeSelectedObject()
Session.Output("Selected ElementID: "+currentElement.ElementID)
->Selected ElementID: 12

But this does not work for diagrams I select in the browser tree.

And I can not find the diagram ID. Only the GUID but this is the wrong one.

If you are referring to *diagram* selected in the Browser, this works in Javascript console:
currentDiagram = Repository.GetTreeSelectedObject()
? currentDiagram.DiagramID +"; "+currentDiagram.MetaType +"; "+ currentDiagram.Name


Title: Re: Custom Metamodel Diagram View
Post by: Plonka on February 28, 2025, 07:10:37 pm
Ah thanks!
That makes sense.
One problem less on my list.