Book a Demo

Author Topic: VBscript to cpy elements from one diagram to anoth  (Read 2995 times)

joelsatheesh

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
VBscript to cpy elements from one diagram to anoth
« on: May 24, 2012, 04:56:27 am »
I'm writing a VB script to copy elements from one diagram to another based on some criteria. Unfortunately, there is no "copy" that I could use. Instead, I found this "AddNew" and I'm trying to make it work as seen in some samples - unfortunately, I'm failing. Can someone help?

Code: [Select]
     var element as EA.Element;
      element = fromDiagram.DiagramObjects.GetAt(1);
      
      var newElement as EA.Element;
      newElement = toDiagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;","table");
      newElement.ElementID = element.ElementID;
      newElement.Update();

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VBscript to cpy elements from one diagram to a
« Reply #1 on: May 24, 2012, 03:14:00 pm »
That code should give you a cast-exception because you are trying to fit an EA.DiagramObject into an EA.Element.
try this:
Code: [Select]
     var element as EA.DiagramObject;
      element = fromDiagram.DiagramObjects.GetAt(1);
      
      var newElement as EA.DiagramObject;
      newElement = toDiagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;","table");
      newElement.ElementID = element.ElementID;
      newElement.Update();

Geert