Book a Demo

Author Topic: changing diagramobjects style  (Read 9491 times)

malmoth

  • EA User
  • **
  • Posts: 49
  • Karma: +0/-0
  • On ne réveille pas un malmoth qui dort
    • View Profile
changing diagramobjects style
« on: March 13, 2006, 09:34:27 am »
Hi everyone,

I'm trying to change the line thickness of diagram objects but it doesn't seem to work.

Here is my code

Code: [Select]

for each aDiagObj in MyDiagram.diagramobjects
     aDiagObj.Style = "LWth=3;"
     MyDiagram.update
     MyRepository.ReloadDiagram(MyDiagram.DiagramID)
Next


I may have not respected the upper/lower case in this example, but VB doesn't care. My program is running, but there is no change in my diagram.
Regards,

Malmoth

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: changing diagramobjects style
« Reply #1 on: March 13, 2006, 10:17:29 am »
AFAIK you have to provide all the (pseudo)parameters in the .Style string, even if you are using the defaults or what's already there. Otherwise EA seems to ignore whatever you try to add.
No, you can't have it!

malmoth

  • EA User
  • **
  • Posts: 49
  • Karma: +0/-0
  • On ne réveille pas un malmoth qui dort
    • View Profile
Re: changing diagramobjects style
« Reply #2 on: March 13, 2006, 12:00:20 pm »
OK, then I've tried this

Code: [Select]

For Each aDiagObj In MyDiagram.DiagramObjects
       aDiagObj.Style = "BCol=35723;BFol=9342520;LCol=9342520;LWth=3;"
       MyDiagram.Update
       MyRep.ReloadDiagram (MyDiagram.DiagramID)
Next

with no more succes.

Can someone give me the parameters in the .Style string ?
« Last Edit: March 13, 2006, 10:01:34 pm by rejaudry »
Regards,

Malmoth

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: changing diagramobjects style
« Reply #3 on: March 13, 2006, 02:03:41 pm »
Hi again Malmoth,

Wonders never cease...

Since I wrote my earlier answer someone asked if I could highlight one element per diagram, and suggested a heavier border. I was successful, and did it as I had suggested.

Here's some brute force code (written in VB.Net 2003):
Code: [Select]
Dim eaDO As EA.DiagramObject
eaDO = DirectCast(eaDiag.DiagramObjects.AddNew("", "DiagramObject"), EA.DiagramObject)
eaDO.ElementID = elemId
eaDO.Style = "BCol=" & (Color.Beige.R + Color.Beige.G * 256 + Color.Beige.B * 256 * 256).ToString _
   & ";BFol=0;LCol=255;LWth=2;"
eaDO.Update()
I ended up with a beige background, black forground (i.e. the text), and a red border two pixels thick.

Remember the following:
  • Do not attempt to read the "current" Style() attribute and modify it; as the documentation says, this "will give undefined results" (darn!)
  • [AFAIK] You must[/] provide the entire string, in the format and order they define, for this to work. If EA cannot understand, or does not accept, all the values you provide, it will use the default values for all style attributes.

HTH,
David
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: changing diagramobjects style
« Reply #4 on: March 13, 2006, 03:28:43 pm »
Hi Malmoth,

Try calling update on aDiagObj.

malmoth

  • EA User
  • **
  • Posts: 49
  • Karma: +0/-0
  • On ne réveille pas un malmoth qui dort
    • View Profile
Re: changing diagramobjects style
« Reply #5 on: March 13, 2006, 10:26:15 pm »
Right ! You need to update the DiagramObject before updating the diagram itself.

But now there is something else. I can't see any change if I don't reload the project in EA. Am I compelled to do this ? I thought that was what all this diagram.update and diagramobject.update was about : update the diagram without reloading the project.

I was trying to "animate" the diagrams for execution purpose. So if there is a way to change the diagramobjects style without reloading the projet, please let me know.
« Last Edit: March 14, 2006, 12:49:44 am by rejaudry »
Regards,

Malmoth

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: changing diagramobjects style
« Reply #6 on: March 14, 2006, 04:40:14 am »
This is a somewhat good news, somewhat bad news situation.

First the somewhat bad news:

To the best of my knowledge you will not get the 'near real time' behaviour you seek. EA can recognize and warn you, depending on various settings, that the background model has changed. However, (at least some) things that are happening in an open session of EA will not be updated in real time.

In particular, diagrams that are open on your desktop will not automatically update themselves. [I keep thinking there's a setting for this but cannot remember what it was; it was probably only a dream.] You can reload an individual diagram - just right click on the diagram tab (usually at the bottom of my screen, but configurable) and select the appropriate context menu entry. There does not seem to be an easy way to do this from the main menu. [Again, I may be missing something here, but I never seem to find it anywhere other than the context menu.]

Another area where you may experience problems is the project view tree. I have found that removing and replacing a package and its internal structure - which you might do with a working copy, or an internal reference model - can cause a 'phantom' entry in the tree. You might have two "Working" packages side by side, one is the 'real' one, and the other is the one you deleted. The tree will not update itself unless and until you reload the project.

Now the somewhat good news:

You can call Repository.ReloadDiagram(DiagramID) from the automation interface, this will clean things up in the instance of EA you are connected to. This works fine for an add-in, but does not solve the problem if you have EA open on your desktop and a concurrent connection to a (shared) model from an external automation client.

You can call Repository.RefreshModelView(PackageID) to refresh a package hierarchy in the tree (and perhaps more). This can also be called with a PackageID of 0, which will refresh the entire model.

You can call Project.ReloadProject() to reload the entire project. [Remember, you can obtain a refernce to the project interface via Repository.GetProjectInterface()] Once again, this affects only the instance of EA you are connected to via automation. If you have another session going from the desktop that session will continue to experience double vision until you manually reload.

Please let me know how you make out with this.

HTH,
David
No, you can't have it!

malmoth

  • EA User
  • **
  • Posts: 49
  • Karma: +0/-0
  • On ne réveille pas un malmoth qui dort
    • View Profile
Re: changing diagramobjects style
« Reply #7 on: March 15, 2006, 07:54:02 am »
I could be satisfied with the Repository.ReloadDiagram(DiagramID) method, but this doesn't work either.

This may be because I'm running a vb macro from ms word and not from a DLL.

Anyway, there is my code


Code: [Select]
Public Sub ChangeLine(pDiagObj As EA.DiagramObject, pStyle As String)
   pDiagObj.Style = pStyle
   pDiagObj.Update
End Sub

Public Sub ChangeLineInDiagram()
   
   Dim MyRep As New EA.Repository
   MyRep.OpenFile "J:\EA MODEL\EA MODEL.EAP"
   
   Dim myDiagram As EA.Diagram, MyPackage As EA.Package, aDiagObj As EA.DiagramObject
   Dim idx As Integer, DefCol As Long
   Dim aString As String
                   
   Set MyPackage = MyRep.Models.GetAt(1).Packages.GetAt(0)
   Set myDiagram = MyPackage.Diagrams.GetAt(0)
   
   DefCol = 14938876 ' (252 + 242 * 256 + 227 * 256 * 256)
   aString = "BCol=" & DefCol & ";BFol=0;LCol=0;LWth=1;"
   
   For Each aDiagObj In myDiagram.DiagramObjects
       Call ChangeLine(aDiagObj, aString)
       myDiagram.Update
   Next
   
   MsgBox aString
   aString = "BCol=" & DefCol & ";BFol=0;LCol=0;LWth=3;"
   
   Set aDiagObj = myDiagram.DiagramObjects.GetAt(1)
   Call ChangeLine(aDiagObj, aString)
   myDiagram.Update
   MyRep.ReloadDiagram (aDiagObj.DiagramID)
   MsgBox "ok"  
End Sub


Anytime I get a message box, I can see that the diagram is not refreshed. Still, I can refresh it by right clicking on the diag tab and chosing 'reload diagram' manually.

If anyone have an (other) idea why I can't automatically refresh the diagram, please let me know.
Regards,

Malmoth

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: changing diagramobjects style
« Reply #8 on: March 15, 2006, 09:09:28 am »
Two ideas:

Try calling ReloadProject. I think this is overkill, but it would be interesting to know if this solves the problem.

Try changing the appropriate line to:
Code: [Select]

DefCol = "14938876" ' (252 + 242 * 256 + 227 * 256 * 256)

I'm not sure if VBA will insert a space before or after it converts the numeral to a string, and formatting is very critical in the Style() string.

Please let me know if either work.I've just gone through something similar, but cannot (yet) see either the same issues in your code (which looks pretty good at first glance) or your situation. I'll write back if I catch on.

David
No, you can't have it!

malmoth

  • EA User
  • **
  • Posts: 49
  • Karma: +0/-0
  • On ne réveille pas un malmoth qui dort
    • View Profile
Re: changing diagramobjects style
« Reply #9 on: March 15, 2006, 01:53:56 pm »
Man, I've tried both ideas. None of them is working. Defining DefCol as a string was not the problem anyway, since my diagramobject.style changes. The only thing is I HAVE to refresh the diagram with the manual command.

As for the reloadProject function, it doesn't seem to have any effect in my code. Usually, reloading the project would make the EA interface blink, but I have nothing of that  kind.

I've also tried to set the enableUIUpdates to true, but with no more succes.

I'm at a loss.
Regards,

Malmoth

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: changing diagramobjects style
« Reply #10 on: March 15, 2006, 03:07:23 pm »
No ideas here either. Nor can I find anything in your code that looks wrong. I've programmed EA from a Word macro in VBA some time ago, and would have gone about this in pretty much the same way.

I have just worked through the same process via VB.Net (2003), which is why I had a code snippet earlier. Still, there does not seem to be much that is wrong with what you are doing.

For now I guess you are stuck with the current behavior. Still, I'm sure you should be able to do this. I am going to be delving into some relatively similar code over the next few days (including the weekend), and will fire off an update to this thread if I think of anything new.

David
No, you can't have it!