Lock layers to solve the problem is not short explicit graphics

Lock layers are our commonly used features, its code is as follows:

public static void LockLayer(LayerTableRecord layer, Document doc)
{
    using (var trans = doc.TransactionManager.StartTransaction())
    {
        layer.UpgradeOpen();
        layer.IsLock = true;
        trans.Commit();
    }
}

After testing found that the layer in the Layer Manager is locked, but the kind of model space, the corresponding layers of light but did not lock significant effect. I guess it needs to be regenerated graphics, so add the following code is regenerated Graphics:

doc.Editor.Regen();

However, the problem remains unresolved, the access to information, about the need to re-set the layer off before you can refresh the display. Increasing the code is as follows:

layer.IsOff = layer.IsOff;

The final problem is resolved. The complete code is as follows:

public static void LockLayer(LayerTableRecord layer, Document doc)
{
    using (var trans = doc.TransactionManager.StartTransaction())
    {
        layer.UpgradeOpen();
        layer.IsLock = true;
        layer.IsOff = layer.IsOff; // refresh the display 
        trans.Commit ();
        doc.Editor.Regen();
    }
}

Guess you like

Origin www.cnblogs.com/optimo/p/12059263.html