70002584 Merge specific entities between two vdCanvas Documents

Article 70002584
Type Wish
Product WebJS
Version 1102
Date Added 11/1/2024 12:00:00 AM
Fixed 11.3.1.0 (11/1/2024 12:00:00 AM)
Submitted by Brendan Fry

Summary

Merge specific entities between two vdCanvas Documents

Solution

In version 11.3.1 a new method MergeEntities was added to vdcanvas object
Function format: MergeEntities(sourceDocument, entities)
Add the clone of passed entities belong to sourceDocument to this document's active layout entities
layers linetypes images textstyles hatchpatterns and blocks reference passed entities are also added to this document

"sourceDocument">A document from an other canvas object whose objects will be addedto this canvas selected document
"entities">can be an array of figure objects or an array of figure handles
If it is undefined all sourceDocument.Model.Entities.Items are added to this document active layout entities

returns: The the new entities added to this document as an array of objects

MergeEntities example

        var vdcanvas;
        var vdcanvas2;
        function vdrawInitPageLoad() {
            vdcanvas = vdmanager.AttachCanvas("canvas");
            vdcanvas2 = vdmanager.AttachCanvas("canvas2");
        }
        ....
        vdcanvas.SelectDocument("drawing1.vds");
        vdcanvas2.SelectDocument("drawing2.vds");
        ......
        //add drawing2 model entities of vdcanvas2 to vdcanvas selected document active layout
        vdcanvas.MergeEntities(vdcanvas2.GetDocument());

        //add drawing2 model entities of vdcanvas2 to vdcanvas selected document active layout
        vdcanvas.MergeEntities(vdcanvas2.GetDocument(), vdcanvas2.GetDocument().Model.Entities.Items);

        //add the first two entities of drawing2 model entities of vdcanvas2 to vdcanvas selected document active layout
        vdcanvas.MergeEntities(vdcanvas2.GetDocument(), [vdcanvas2.GetDocument().Model.Entities.Items[0],vdcanvas2.GetDocument().Model.Entities.Items[1]]);

        //prompt the user to select entities on vdcanvas2 and copy them to vdcanvas document's active layout
        vdcanvas2.scriptCommand.select(null, function (_vdcanvas) { vdcanvas.MergeEntities(vdcanvas2.GetDocument(), _vdcanvas.scriptCommand.ActiveSelection()); });

Send comments on this topic.