Book a Demo

Author Topic: DiagramObject.ElemenID Assignment  (Read 4034 times)

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • "There is no I in Team America"
    • View Profile
DiagramObject.ElemenID Assignment
« on: October 28, 2009, 03:23:37 pm »
I'm trying to direct the DiagramObjects in a particular diagram to a different Element in the model. I make the Assignment and call update ... no exceptions are thrown, but the newly assigned ElementID is not persisted.

We have made sure that all DiagramLinks also refer to the newly assigned ElementID if necessary ... and they are persisted with no problem.
« Last Edit: October 28, 2009, 03:24:40 pm by simon.leserve »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramObject.ElemenID Assignment
« Reply #1 on: October 28, 2009, 09:37:57 pm »
Hi,

I've encountered the same problem and reported the bug to Sparx.
My solution was:
(this code is an operation on my DiagramNode wrapper that wrapps the actual EA.DiagramNode)
Code: [Select]
/// <summary>
        /// set the element this node represents
        /// </summary>
        /// <param name="element">the element this node represents</param>
        public void setElement(UMLElement element)
        {
            // there seems to be a bug in the com object when calling update on the DiagramObject after setting the elementID
            // workaround could be to create a new diagramObject on the diagram and copy all the settings
            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);
            //reference the new diagram object
            this.wrappedDiagramNode = newDiagramObject;
            // bug reported to Sparx support. If they fix it this original code can be used again.
            //original code: this.wrappedDiagramNode.ElementID = element.getID();
            
        }
It ugly, wrong  and waaay too much code, but it works  ;D

Geert

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • &quot;There is no I in Team America&quot;
    • View Profile
Re: DiagramObject.ElemenID Assignment
« Reply #2 on: October 29, 2009, 09:54:05 am »
Thanks heaps Geert !!

MagnusH

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: DiagramObject.ElemenID Assignment
« Reply #3 on: February 01, 2010, 07:09:51 am »
This forum is great!

But the bug is really bad for me. All diagramlinks are of course destroyed when the original diagramobject is deleted and have to be rebuilt also. Any trick to do that in a good way without destroying custom line layout?

Thanks,
Magnus

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: DiagramObject.ElemenID Assignment
« Reply #4 on: February 01, 2010, 06:58:28 pm »
Magnus,

I don't see why the diagramlinks would be destroyed.
As far as I can see they relate to a connection, which isn't changed in any way.
As long as you make sure the connector points to the correct objects there shouldn't be a problem.

Geert

MagnusH

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: DiagramObject.ElemenID Assignment
« Reply #5 on: February 01, 2010, 08:09:11 pm »
Geert,

You're right. They were preserved as long as a a change the client/supplier on the connection before deleteing the diagramobject.

// magnus