.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fade the layer like lock effect

3 REPLIES 3
Reply
Message 1 of 4
NGM_AiYo
337 Views, 3 Replies

fade the layer like lock effect

I make a loop To choose layer. Each time I select a layer, fade it out.

At first I changed the Transparency.  It takes too much time running program.

Next I set layer's IsLocked, but I can't see the effect.

Is there any other way to do that?

 

the code below is my attempt of lock.

private void PickLayer(Dictionary<string, ObjectId> data)
        {
            Document doc = Common.GetActiveWindowDoc();
            Editor ed = doc.Editor;
            Database db = doc.Database;
            
            this.Hide();

            while (true)
            {
                PromptEntityOptions peo = new PromptEntityOptions("select layer");
                PromptEntityResult per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK)
                {
                    Common.Alert("quit");
                    break;
                }

                using (var lck = doc.LockDocument())
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        Entity ent = (Entity)per.ObjectId.GetObject(OpenMode.ForRead);
                        LayerTableRecord layerTR = (LayerTableRecord)ent.LayerId.GetObject(OpenMode.ForWrite);
                        TypedValue[] typedValues = { new TypedValue((int)DxfCode.LayerName, layerTR.Name) };
                        SelectionFilter filter = new SelectionFilter(typedValues);

                        if (!data.ContainsKey(layerTR.Name))
                        {
                            layerTR.IsLocked = true;
                            //layerTR.EntityColor = 
                            layerTR.DowngradeOpen();
                            ed.Regen();

                            Common.Alert("add data:" + layerTR.Name);
                            data.Add(layerTR.Name, layerTR.Id);
                        }

                        tr.Commit();
                    }
                }
                
            }

            //
            this.Show();

            //unlock
            if (data.Any())
            {
                try
                {
                    foreach (var item in data)
                    {
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            using (var lck = doc.LockDocument())
                            {
                                LayerTableRecord layerTR = (LayerTableRecord)item.Value.GetObject(OpenMode.ForRead);
                                layerTR.UpgradeOpen();
                                layerTR.IsLocked = false;
                                layerTR.DowngradeOpen();
                                ed.Regen();
                                Common.Alert(layerTR.Name + "unlock");
                            }

                            tr.Commit();
                        }
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }

 

3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: NGM_AiYo

This may be a stupid proposal, but... What about changing the layer color (or it's entities) to a darker color?

Message 3 of 4
HJohn1
in reply to: Anonymous

amanero, I am not an expert by any means, but I think your idea is brilliant.  If you take a layer color and multiply its RGB values by about 1/2, you will get a similar result.  This will help me, thanks.

Message 4 of 4
HJohn1
in reply to: HJohn1

I should add that the value of the fade should be based on your settings for LAYLOCKFADECTL to match the effect.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report