Author Topic: Possible to detect if current layer changed?  (Read 2411 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Possible to detect if current layer changed?
« 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.

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Possible to detect if current layer changed?
« Reply #1 on: August 16, 2015, 08:07:19 AM »
You can set an event handler for the system variable CLAYER.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Possible to detect if current layer changed?
« Reply #2 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.         }
« Last Edit: August 16, 2015, 04:37:53 PM by Alien »

BlackBox

  • King Gator
  • Posts: 3770
Re: Possible to detect if current layer changed?
« Reply #3 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
"How we think determines what we do, and what we do determines what we get."

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Possible to detect if current layer changed?
« Reply #4 on: August 17, 2015, 12:28:18 AM »
Thanks!

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Possible to detect if current layer changed?
« Reply #5 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.
Revit 2019, AMEP 2019 64bit Win 10

BlackBox

  • King Gator
  • Posts: 3770
Re: Possible to detect if current layer changed?
« Reply #6 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.
"How we think determines what we do, and what we do determines what we get."