Book a Demo

Author Topic: System.Runtime.InteropServices.COMException on DiagramObject.Update()  (Read 3053 times)

NinaN

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Hello everyone,

im having a problem with adding a port or interface to a diagram. Am I doing something wrong here?
I already generated a package named "Runnables" which contains Propertys with Ports. I want to add them to a Diagram. On Port.Update() the following error occurs:
Exception thrown: 'System.Runtime.InteropServices.COMException' in SolutionName.dll
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in SolutionName.dll
The server threw an exception. (0x80010105 (RPC_E_SERVERFAULT))

Thanks a lot in advance  :)

EA Version: 14
Visual Studio 2019
Enterprise Architect Object Model 2.10


Code: [Select]
EA.Diagram Diagram = (EA.Diagram)diagrams_package.Diagrams.AddNew("CompositeDiagram", "CompositeStructure");

EA.Package runnable_package = getPackageByName("Runnables"); // own created package search
for (short i = 0; i < runnable_package.Elements.Count; i++)
{
EA.Element runnable = (EA.Element)runnable_package.Elements.GetAt(i);
EA.DiagramObject runnabledia = (EA.DiagramObject)Diagram.DiagramObjects.AddNew("", "Property");
runnabledia.ElementID = runnable.ElementID;
Diagram.DiagramObjects.Refresh();
runnabledia.Update();
                                Diagram.Update();
                                for (short n = 0; n < runnable.Elements.Count; n++)
{
EA.Element port = (EA.Element) runnable.Elements.GetAt(n);
                                        EA.DiagramObject portobj = (EA.DiagramObject)Diagram.DiagramObjects.AddNew("", "Port");
                                        portobj.ElementID = port.ElementID;
                portobj.Update(); // Exception occurs
                                }
                   }


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: System.Runtime.InteropServices.COMException on DiagramObject.Update()
« Reply #1 on: September 23, 2020, 04:13:03 pm »
A few things seem a bit weird

EA.DiagramObject runnabledia = (EA.DiagramObject)Diagram.DiagramObjects.AddNew("", "Property");
and
EA.DiagramObject portobj = (EA.DiagramObject)Diagram.DiagramObjects.AddNew("", "Port");

You can't define the type of a diagramObject.
If you want to add an element as property or port on a diagram, you first need to create this Port or Property (in the collection of embedded elements) and then add that to a diagram.

Diagram.DiagramObjects.Refresh();
Is not needed, you can remove that

Diagram.Update(); is in a weird place.
I would move that outside of the loops, right after creating the diagram, and then possibly, if needed, a the end of the whole thing. But I think this should not be needed anymore.


Geert



Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: System.Runtime.InteropServices.COMException on DiagramObject.Update()
« Reply #2 on: September 23, 2020, 05:29:08 pm »
Hello,


When you create a DiagramObject, the first argument must contain the dimensions, as in "l=100;r=200;t=50;b=150;". The second should be empty (diagram objects don't have types).
You then set the diagram object's .ElementID to the .ElementID of the element you want to show.

This stuff is all in the code samples.


/Uffe
My theories are always correct, just apply them to the right reality.