Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: damien 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
-
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...]
-
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 ?
-
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 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.
-
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.
-
Thanks to you it's works
-
Now if only I hadn't wasted your time with the first answer...
At least you are moving forward now, though.
-
no problems you help me a lot.
-
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
-
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.
-
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
-
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?
-
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
-
OK. Sounds like you're back in business...