2 Replies Latest reply on Apr 9, 2014 2:44 PM by Todd Carpenter

    Layer Controls for C#

    Todd Carpenter

      I've been searching all over and I did see a couple of C# samples for C#, but they all seem to rely on getting a layer from an entity.

       

      I need to just turn a layer's visibility on and off, and I don't see anything like this, and the documentation is really sparse on this.  I see in C# there is a LayerManager and LayerManagerClass - but everything I try seems to error.

       

      Granted I'm a newbie to C#, so if I looked right at it, please point me in the right direction....

       

      TIA.

        • Re: Layer Controls for C#
          Jesse Seger

          Being new can be frustrating at times.

           

          To turn the layer's visibility on and off you need to set the Visible property on the Layer to false.  To get the correct Layer object, you need to call GetLayer("Layer 1") on the LayerMgr.  To get the LayerMgr object, you need to call GetLayerManager() on the ModelDoc object.

           

          Here is some sample code.

           

           

          public partial class SolidWorksMacro    {         public void Main()         {             IModelDoc2 swDoc = (IModelDoc2)swApp.ActiveDoc;             ILayerMgr layerMgr = (ILayerMgr)swDoc.GetLayerManager();             ILayer notes = (ILayer)layerMgr.GetLayer("Notes");             notes.Visible = false;             ILayer dims = (ILayer)layerMgr.GetLayer("Dimensions");             dims.Visible = false;         }         /// <summary>        ///  The SldWorks swApp variable is pre-assigned for you.        /// </summary>       

                  public SldWorks swApp;     }