TheSwamp

Code Red => .NET => Topic started by: nobody on August 16, 2015, 05:21:36 AM

Title: Possible to detect if current layer changed?
Post by: nobody on August 16, 2015, 05:21:36 AM
Is it possible to detect if the current layer changed? I'd like to update a form to show the current layer and want to make sure it stays correct.
Title: Re: Possible to detect if current layer changed?
Post by: huiz on August 16, 2015, 08:07:19 AM
You can set an event handler for the system variable CLAYER.
Title: Re: Possible to detect if current layer changed?
Post by: nobody on August 16, 2015, 04:25:30 PM
For anyone else who might want to do this, below is how I accomplished it. I'm sure things are wrong with it but it works for now. Thanks Huiz for the advice.

Code - C#: [Select]
  1.        public void layerchangedmonitor()
  2.         {
  3.             acApp.SystemVariableChanged += new Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventHandler(SysVariableChange);
  4.         }
  5.  
  6.  
  7.         void SysVariableChange(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
  8.         {
  9.             if (e.Name == "CLAYER")
  10.             {
  11.                 //do anything you want here. I got the current layer then updated a text box with its name and another with the color that matched its values.
  12.                 string currentWorkspaceName = (string)acApp.GetSystemVariable(e.Name);
  13.                 LayerTableRecord mylayer = MyCollectors.GetCurrentLayer();
  14.                 CurrentLayerBox.Text = mylayer.Name.ToString();
  15.                 CurrentLayerColorBox.BackColor = mylayer.Color.ColorValue;
  16.             }
  17.  
  18.         }
Title: Re: Possible to detect if current layer changed?
Post by: BlackBox on August 16, 2015, 07:03:02 PM
Nothing to add to Henrique's apt post, however should you need to know more about Layer changes, you can use Bindable Object Layer (BOL), just mind the additional overhead:

http://through-the-interface.typepad.com/through_the_interface/2012/07/finding-out-about-changes-to-autocad-layers-via-the-bindable-object-layer-using-net.html
Title: Re: Possible to detect if current layer changed?
Post by: nobody on August 17, 2015, 12:28:18 AM
Thanks!
Title: Re: Possible to detect if current layer changed?
Post by: MexicanCustard on August 17, 2015, 07:49:34 AM
Nothing to add to Henrique's apt post, however should you need to know more about Layer changes, you can use Bindable Object Layer (BOL), just mind the additional overhead:

http://through-the-interface.typepad.com/through_the_interface/2012/07/finding-out-about-changes-to-autocad-layers-via-the-bindable-object-layer-using-net.html

Not sure this method incurs much additional overhead.  AutoCAD is creating the observable collection whether you ever use it or not. Subscribing to its events is no more overhead than subscribing to Application.SystemVariableChanged.
Title: Re: Possible to detect if current layer changed?
Post by: BlackBox on August 17, 2015, 02:49:18 PM
Nothing to add to Henrique's apt post, however should you need to know more about Layer changes, you can use Bindable Object Layer (BOL), just mind the additional overhead:

http://through-the-interface.typepad.com/through_the_interface/2012/07/finding-out-about-changes-to-autocad-layers-via-the-bindable-object-layer-using-net.html

Not sure this method incurs much additional overhead.  AutoCAD is creating the observable collection whether you ever use it or not. Subscribing to its events is no more overhead than subscribing to Application.SystemVariableChanged.

Correct; it's not the event subscription that can consume more overhead.

It's the per-document storage of a given LayerTabelRecords's settings before a change, a subsequent store after changes, and the comparative functionality thereafter if needing to identify which LayerTableRecord Property(s) have been changed to what values (from what values?) that would require additional overhead - and again, only if such reporting is even needed.