| Article | 70002561 |
| Type | HowTo |
| Product | WebJS |
| Version | 11 |
| Date Added | 9/3/2024 12:00:00 AM |
| Fixed | 11.2.3.0 (9/3/2024 12:00:00 AM) |
| Submitted by | Brendan Fry |
Summary
Example of select existing entities and create a block from them and replacing the existing entities with the newly created block
Solution
vdcanvas.scriptCommand.select(null, function (_vdcanvas) {
var selectedEntities = _vdcanvas.scriptCommand.ActiveSelection();
if (!selectedEntities || selectedEntities.length == 0) return;
var blk = _vdcanvas.AddBlock("mycustomblock");
for (var k = 0; k < selectedEntities.length; k++) {
var fig = selectedEntities[k];
var clone = vdConst.cloneEntity(fig); //add the clone of the existing object to the block entities
clone.HandleId = 0;//importand .Set the handle as undefined
var ret = _vdcanvas.AddFigureToCollection(blk.Entities, clone);
fig.Deleted = true; //delete existing object
}
var vdinsert = _vdcanvas.AddBlockSymbol("mycustomblock", [0, 0, 0], 1, 0); //insert the new created block at the same position
setTimeout(_vdcanvas.redraw);
});
