Book a Demo

Author Topic: Change diagram types via script  (Read 11371 times)

Polymorph

  • EA User
  • **
  • Posts: 136
  • Karma: +4/-0
    • View Profile
Change diagram types via script
« on: August 17, 2016, 08:30:31 am »
I have created an MDG that extends the SysML sequence diagram and need to change some of my sequence diagrams to this new type. Unfortunately, EA won't let me change a sequence diagram to any other type of diagram (that option is greyed out in the menu).

I am guessing that it must be possible somehow but that it might need to be done using a script...

From digging around in the SQL database it seems that the following field in the t_diagram.StyleEx table makes reference to the type of diagram. For example, on my standard SysML Sequence diagram this field reads:
Quote
ExcludeRTF=0;DocAll=0;HideQuals=0;AttPkg=1;ShowTests=0;ShowMaint=0;SuppressFOC=0;INT_ARGS=;INT_RET=;INT_ATT=;SeqTopMargin=30;MatrixActive=0;SwimlanesActive=1;KanbanActive=0;MatrixLineWidth=1;MatrixLineClr=0;MatrixLocked=0;TConnectorNotation=UML 2.1;TExplicitNavigability=0;AdvancedElementProps=1;AdvancedFeatureProps=1;AdvancedConnectorProps=1;ProfileData=;MDGDgm=SysML1.3::Sequence;STBLDgm=;ShowNotes=0;VisibleAttributeDetail=0;ShowOpRetType=0;SuppressBrackets=0;SuppConnectorLabels=0;PrintPageHeadFoot=0;ShowAsList=0;Whiteboard=1;SuppressedCompartments=;SaveTag=4B2FDBD8;

So, I was thinking that it might be possible to write a script to change this value

I am very new to EA scripting and have very little VB experience, but have managed to get a script to to a find-and-replace within this field using the following code:

Code: [Select]
sub OnDiagramScript()

' Get a reference to the current diagram
dim currentDiagram as EA.Diagram
set currentDiagram = Repository.GetCurrentDiagram()

 

'declare variable to store style string
dim DiagramStyleString
'store style string
DiagramStyleString = currentDiagram.StyleEx
'do a find a replace
DiagramStyleString=replace(DiagramStyleString,"MDGDgm=SysML1.3::Sequence;","MDGDgm=Protean Architecture Framework::System Interaction View;")


    currentDiagram.StyleEx=DiagramStyleString
end sub

But that didn't work - not that I'm surprised!

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Change diagram types via script
« Reply #1 on: August 17, 2016, 09:01:22 am »
currentDiagram.Update() to save the changes
The Sparx Team
[email protected]

Polymorph

  • EA User
  • **
  • Posts: 136
  • Karma: +4/-0
    • View Profile
Re: Change diagram types via script
« Reply #2 on: August 17, 2016, 05:10:45 pm »
So that's the only thing I need to do to change a diagram type? Really??? I'm not complaining if that's right but I'm frankly amazed (given my lack of experience with VB scripts) that I hit on the right idea straight away! Beginner's luck perhaps?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Change diagram types via script
« Reply #3 on: August 18, 2016, 08:24:21 am »
Except that you can't change it via scripting in the current version.

There is a change coming that will allow writing to Diagram.Metatype, it's just not available yet.

Polymorph

  • EA User
  • **
  • Posts: 136
  • Karma: +4/-0
    • View Profile
Re: Change diagram types via script
« Reply #4 on: August 18, 2016, 10:08:48 pm »
And there's no other way to change it?!?  :-\

I have tried creating a new Sequence diagram (using our MDG technology) and then copy-pasting elements between the current diagram and the new one but that only copies the lifelines and any diagram fragments - the message lines are not duplicated.

I don't really care how I do it - I just need a way to take the contents of a standard Sequence diagram and then produce a version that conforms to our company standard

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change diagram types via script
« Reply #5 on: August 19, 2016, 08:08:44 am »
You can change it with a SQL through Repository.Execute. This is an undocumented and unsupported feature, but it works. Of course you need to be extra careful since you can simply clobber your whole repository.

q.

Polymorph

  • EA User
  • **
  • Posts: 136
  • Karma: +4/-0
    • View Profile
Re: Change diagram types via script
« Reply #6 on: August 19, 2016, 05:34:04 pm »
Gulp!

So I guess I have to ask myself the question: do I feel lucky?... Well do I? PUNK!

(No I don't feel lucky - not given my lack of experience with VB script writing)

And no one knows a way of copying the contents of a Sequence Diagram into clipboard and then pasting those elements including messages between lifelines-lines onto a new diagram?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change diagram types via script
« Reply #7 on: August 19, 2016, 07:54:50 pm »
In the browser right click the diagram/Copy/Copy Diagram. Right click package: Copy/Paste Diagram (and choose a new name)

q.

Polymorph

  • EA User
  • **
  • Posts: 136
  • Karma: +4/-0
    • View Profile
Re: Change diagram types via script
« Reply #8 on: August 19, 2016, 07:55:55 pm »
I have found an alternate solution too!

The process I was using to copy the elements on a sequence diagram is:
  • Selecting all the elements on the diagram (CTRL + A).
  • Using CTRL + C to copy to clipboard
  • Creating a new sequence diagram (with my custom MDG extensions including a bespoke diagram frame tag)
  • Ctrl +V to paste the elements on the diagram

The result of this process was a complete mess - and none of the messages between lifelines were recreated in the diagram and all of the diagram fragments were all over the place  ::)

The way to do it is to follow steps 1-3, but when you have created a new diagram either
  • Right click on the diagram canvas and select Paste Elements as New
  • Use the keyboard shortcut (CTRL + SHIFT + V)

Now EA will replicate all the original features of the diagram in a new diagram perfectly.

Not the first time I've been caught out with differences between pasting as links and pasting as new elements :o