70001683 Export AddFigureToCollection on WebControl

Article 70001683
Type Wish
Product WebJS
Version 8003
Date Added 2/4/2020
Fixed 8.8004.0.3 (2/4/2020)
Submitted by Kerry Smith


I would like to be able to add a new figure to a block entities collection.


In version 8004.0.3 a new AddFigureToCollection method was added in WebControl which adds a figure to the passed collection.
In the example bellow we prompt the user to select a rectangle,we create a new block, we clone the entity, we add it the block's entities and we insert it near the original rectangle in the same row with no gap.

        vdcanvas.scriptCommand.select(null, _myselectback);

         var countBlocks = 0;// used to every time change the name of the new block that we will create
         function _myselectback(vdcanvas) {
             var selectedEntity = vdcanvas.scriptCommand.ActiveSelection()[0];
             if (!(selectedEntity._t === vdConst.vdRect_code)) return;
             var customBlockName = 'myblock' + countBlocks.toString();
             var blk = vdcanvas.AddBlock(customBlockName);
             var clone = vdConst.cloneEntity(selectedEntity);
             var ret = vdcanvas.AddFigureToCollection(blk.Entities, clone);// returns true if succeded
             blk.Origin = [selectedEntity.InsertionPoint[0] - selectedEntity.Width, selectedEntity.InsertionPoint[1], selectedEntity.InsertionPoint[2]];//set the origin of the block
             vdcanvas.scriptCommand.blockref(customBlockName, [[selectedEntity.InsertionPoint[0], selectedEntity.InsertionPoint[1], selectedEntity.InsertionPoint[2]], 1.0, 0], entityAddedCallback);//insert the block

         function entityAddedCallback(vdraw, entity) {
             setTimeout(vdraw.redraw);//post a redraw in order to see the insert on the canvas

Send comments on this topic.