Author Topic: Question about DiagramObject  (Read 6449 times)

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Question about DiagramObject
« on: May 22, 2008, 10:14:37 pm »
Hello,

I would know if it's possible to move a DiagramObject from a diagram to an another diagram only changing the DiagramID of the DiagramObject. I try this but an exception is throw when i use the update method :

For Each selectedObject As EA.DiagramObject In Diagram.SelectedObjects

  Element = Repository.GetElementByID(selectedObject.ElementID)
  Element.PackageID = TasksGroup.PackageID
  Element.Update()
  selectedObject.DiagramID = NewDiagram.DiagramID
  selectedObject.Update()
      
Next

the error message is :

EA_menuClick: Object reference not set to an instance of an object

Someone has an idea why this exception is throw and if only it's possible to do it

Thanks you
Bye

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Question about DiagramObject
« Reply #1 on: May 22, 2008, 10:51:52 pm »
You should add the element to the Elements collection of the new package. When you Update() the element and refresh the collection EA should handle the adjustment to PackageID for the element.

[I was talking through my hat here. See below...]
« Last Edit: May 23, 2008, 12:22:55 am by Midnight »
No, you can't have it!

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Question about DiagramObject
« Reply #2 on: May 22, 2008, 11:58:11 pm »
But if i add the element with the addNew, the element will not be the same as the element i want to move and its diagrams,its  elements and its properties will not be copied

no ?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Question about DiagramObject
« Reply #3 on: May 23, 2008, 12:21:28 am »
Sorry, I was talking about the wrong thing and led you astray.

In your other thread I explained that a diagram object is merely an image of an element. The element itself does not belong to the diagram, and could 'reside' anywhere in your project. Each diagram object that references that image belongs to a diagram.

Create a new diagram object in your diagram, using AddNew. Set the ElementID of the new diagram object to your desired element. Now call Update on the diagram object.

Does this make sense when you look at the results?

David

PS: Sorry about the incorrect context the first time...
No, you can't have it!

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Question about DiagramObject
« Reply #4 on: May 23, 2008, 12:41:09 am »
no problem ^^

But my problem isn't to show element in another diagram, my problem is to move a element in another package. Because when i do this :

Element = Repository.GetElementByID(selectedObject.ElementID)
Element.PackageID = TasksGroup.PackageID
Element.Update()

the element in the project tree is in the new package but i realise that my element is always in the old package (package.elements) and not in the new package (package.elements).  But when i restart EA the element is in the good package.

I conclude i forget to call a method to update the two package but i try package.update and nothing change.



«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Question about DiagramObject
« Reply #5 on: May 23, 2008, 01:00:17 am »
Try calling Refresh on the Elements collection of each package. Until a refresh is called or a collection reloaded, EA does not (usually) have the current set of pointers.

You can sometimes see this happen when you create a new element (for example) and then try to retrieve it from the parent package with Elements.GetByName call. If you have not yet called Refresh the call will fail.

HTH, David

PS: While we're on the subject... If you don't see the new element position reflected in the UI - in case your EA application is visible - then you might need to reload the diagram, package or project, depending on the situation. There are calls available to do each of these.
« Last Edit: May 23, 2008, 01:02:20 am by Midnight »
No, you can't have it!

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Question about DiagramObject
« Reply #6 on: May 23, 2008, 01:19:05 am »
Thanks to you it's works

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Question about DiagramObject
« Reply #7 on: May 23, 2008, 01:34:37 am »
Now if only I hadn't wasted your time with the first answer...

At least you are moving forward now, though.
No, you can't have it!

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Question about DiagramObject
« Reply #8 on: May 23, 2008, 04:47:31 pm »
no problems you help me a lot.

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Question about DiagramObject
« Reply #9 on: May 23, 2008, 05:51:33 pm »
I always have the same problem, i thinks that when i modified a diagramObject i only need to update it and refresh the collection which contains it.

But when i want to delete a diagramObject from a diagram, the diagram isn't refresh but the diagramObject is successful deleted.

Sub test(ByVal Repository As EA.Repository)

        Dim Diagram As EA.Diagram = Repository.GetCurrentDiagram()

        For i = 0 To Diagram.DiagramObjects.Count - 1
            Diagram.DiagramObjects.Delete(i)
        Next
        Diagram.DiagramObjects.Refresh()
      
        Repository.SaveDiagram(Diagram.DiagramID)
        Repository.ReloadDiagram(Diagram.DiagramID)

End Sub

I try to refresh with methods :

update the diagram
Package.Diagrams.Refresh()
Package.Update()
Repository.RefreshOpenDiagrams(True)

But nothing change

Thanks you
Bye

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Question about DiagramObject
« Reply #10 on: May 23, 2008, 08:29:35 pm »
I'm not sure. Perhaps you need to reload (not refresh) the package or project. There are methods (of Repository or maybe Project) to handle this.
No, you can't have it!

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Question about DiagramObject
« Reply #11 on: May 23, 2008, 11:23:15 pm »
it doesn't work but i don't understand why when i add a new diagramObject, my code works and the element is on the diagram and when i delete it the element isn't deleted from the diagram.

Someone can explain to me ? Please


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Question about DiagramObject
« Reply #12 on: May 24, 2008, 12:23:08 am »
Remember that the index to a collection is a short (16-bit) integer. This can be important.

Try not saving the diagram, or reloading it. When you've returned from the call, make sure your project is visible, then right-click the diagram tab and reload the diagram.

Do you see the diagram object now?

If so, make the diagram visible earlier and put an pause of some kind in the subroutine - perhaps a message box - so you can reload the diagram after just before you return from the subroutine.

Can you see the diagram object now?
No, you can't have it!

damien

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Question about DiagramObject
« Reply #13 on: May 24, 2008, 01:02:18 am »
When i reload the diagram before saves it elements are deleted.

Thanks you for your help
I just need to reverse this lines :

Repository.SaveDiagram(Diagram.DiagramID)
Repository.ReloadDiagram(Diagram.DiagramID)

i do an error when i think the SaveDiagram method is used to update the diagram before reload it

Bye
« Last Edit: May 24, 2008, 01:02:53 am by damien »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Question about DiagramObject
« Reply #14 on: May 24, 2008, 01:35:27 am »
OK. Sounds like you're back in business...
No, you can't have it!