Article | 70002444 |
Type | HowTo |
Product | WebJS |
Version | 10 |
Date Added | 11/23/2023 12:00:00 AM |
Fixed | 10.1005.0.4 (11/24/2023 12:00:00 AM) |
Submitted by | Sefa |
Summary
How can I delete layer in weblibrary
Solution
In order to delete a layer you must first delete all entities in the drawing that reference this layer
Example deleted all entities that belong to layer with name "ALayerName" and final the layer itself
var layername = "ALayerName"; var layer = vdcanvas.FindLayer(layername); var layerHandle = 'h_' + layer.HandleId.toString(); if (!layer) return; var vddoc = vdcanvas.GetDocument(); //Warning ActiveLayer must not be deleted.If you want to delete a layer that is Active then change the ActiveLayer with an other one if (vddoc.ActiveLayer === layerHandle) return; //WARNIG you can not delete the default standard layer '0' if(layername =="0") return; //enumerate all document properties and check those that represent drawing entities that can be reference to a layer for (prop in vddoc) { if (!prop.substr(0, 2) == 'h_') continue; var obj = vddoc[prop]; //if the object reference to the layer mark it as deleted if (!obj.Layer) continue; if (obj.Layer !== layerHandle) continue; obj.Deleted = true; } //finally delete the layer itself layer.Deleted = true; setTimeout(vdcanvas.redraw());//post a redraw to see the changes in the drawing