Book a Demo

Author Topic: Unhandled COM exception at DiagramObject.Update  (Read 4795 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Unhandled COM exception at DiagramObject.Update
« on: May 14, 2009, 06:24:23 pm »
When I try to update my diagramObject afer changing its ElementID I get an Unhandled Com exception:
Quote
System.Runtime.InteropServices.COMException was unhandled
  Message=""
  Source=""
  ErrorCode=-2147221504
  StackTrace:
       at EA.IDualDiagramObject.Update()
  InnerException:

My litte C# program does following:
- Find all diagramObjects with a specific elementID
- Replace elementID with another elementID
- Update diagramObject.

It is in the update method that I get the unhandled COM exception. I'm testing this using EA v 7.5 b844 on an access backend.

As a workaround I'm going to try to create e new DiagramObject with the correct ID and the same settings, and then delete the old one.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Unhandled COM exception at DiagramObject.Updat
« Reply #1 on: May 14, 2009, 08:43:03 pm »
The workaround actually worked, witht the exception of the style.
Here is the original code:
Code: [Select]
this.wrappedDiagramNode.ElementID = element.getID();
this.wrappedDiagramNode.Update();

and here the workaround code
Code: [Select]
           EA.Diagram parentDiagram = model.getWrappedModel().GetDiagramByID(this.wrappedDiagramNode.DiagramID);
            //get the index of this diagramnode in the collection of diagramobjects of the parent
            short index = -1;
            for (short i = 0; i < parentDiagram.DiagramObjects.Count; i++)
            {
                if (((EA.DiagramObject)parentDiagram.DiagramObjects.GetAt(i)).InstanceID == this.wrappedDiagramNode.InstanceID)
                {
                    //found the correct one.
                    index = i;
                }
            }
            //create a new diagramobject
            EA.DiagramObject newDiagramObject = (EA.DiagramObject)parentDiagram.DiagramObjects.AddNew("", "DiagramObject");
            //set the new elementid
            newDiagramObject.ElementID = element.getID();
            //copy position attributes
            newDiagramObject.bottom = this.wrappedDiagramNode.bottom;
            newDiagramObject.left = this.wrappedDiagramNode.left;
            newDiagramObject.right = this.wrappedDiagramNode.right;
            newDiagramObject.top = this.wrappedDiagramNode.top;
            //delete the old diagram object
            parentDiagram.DiagramObjects.Delete(index);
            //save the new diagram object
            newDiagramObject.Update();
            //reference the new diagram object
            this.wrappedDiagramNode = newDiagramObject;

pff... Its ugly, but it works.  :-/

ChrisM

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Unhandled COM exception at DiagramObject.Updat
« Reply #2 on: June 03, 2009, 06:40:24 pm »
Hi there. I had a similar problem trying to resize diagram objects.
Not sure if its the same issue but the diagram objects didn't change after the resize. It turns out my issue was that the diagram was open. Closing the diagram, making the changes, then opening the diagram worked for me.

I had originally gone down the same route of deleting the old diagram object and creating a new one too, until I found the close diagram command  :).

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Unhandled COM exception at DiagramObject.Updat
« Reply #3 on: June 03, 2009, 08:24:57 pm »
Did either of you try calling the Repository.ReloadDiagram, Repository.RefreshOpenDiagrams or Repository.RefreshModelView methods? Or as a last resort, did you try Project.ReloadProject?
No, you can't have it!

ChrisM

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Unhandled COM exception at DiagramObject.Updat
« Reply #4 on: June 16, 2009, 02:44:54 am »
I think I tried most of the Refresh* and Reload* commands but they didn't work. Only closing the diagram first worked.