Hello folks!
I would like to perform a simple task. I have a package with elements which I'd like to copy to a newly created or an existing diagram.
First I thought this would be a simple task - the documentation includes an example where a similiar task is performed, I'm quoting:
Add and Manage Diagrams
public Object
''an example of how to create a diagram and add an element to it
''note the optional use of element rectangle setting using
''left,right,top and bottom dimensions in AddNew call
Sub DiagramLifeCycle
Dim diagram as object
Dim v as object
Dim o as object
Dim package as object
Dim idx as Integer
Dim idx2 as integer
package = m_Repository.GetPackageByID(5)
diagram = package.Diagrams.AddNew("Logical Diagram","Logical")
If not diagram.Update Then
Console.WriteLine(diagram.GetLastError)
End if
diagram.Notes = "Hello there this is a test"
diagram.update()
o = package.Elements.AddNew("ReferenceType","Class")
o.Update
'' add element to diagram - supply optional rectangle co-ordinates
v = diagram.DiagramObjects.AddNew("l=200;r=400;t=200;b=600;","")
v.ElementID = o.ElementID
v.Update
Console.WriteLine(diagram.DiagramID)
End Sub
-- end of example
This looks very promising, however to my surprise this example is simply wrong! The attribute ElementID of the Element interface is read-only, which means that the assigment from the example will not work!
So, my question is, how to add an existing element from a package to a diagram? Do I have to deepcopy all the writeable attributes and collections from the package-element to a newly cerated diagram-element? Would it even work this way?
Thanks for help.
Hynek Cihlar
A && L Soft
www.alsoft.czwww.flexlanguage.com