AnsweredAssumed Answered

ModelDoc2 swDoc is null (C#)

Question asked by Dave Paul on Jul 22, 2015
Latest reply on Jul 22, 2015 by Dave Paul

Sorry, this is a newbee C# question.

I have the swApp object, but when I try to set the swDoc object to the ActiveDoc I get nothing.  For that reason, the GetLayerManager fails.


I have the feeling that I'm starting a difference instance of SW2013 than the one that's open and connecting to that one.


Thank you for your help - Dave


using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;

private void ToggleLayer(string strInLayerName)
            SldWorks swApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application.21"));
            if (swApp != null)
                ModelDoc2 swDoc = (ModelDoc2)swApp.ActiveDoc;
                LayerMgr swLayerMgr = (LayerMgr)swDoc.GetLayerManager();