private string SwAttach()
        {
            string strMessage;

            //bool blnStatus = true;

            //Check for the status of existing solidworks apps
            if (System.Diagnostics.Process.GetProcessesByName("sldworks").Length < 1)
            {
                strMessage = "Solidworks instance not detected.";
                //blnStatus = false;
            }
            else if (System.Diagnostics.Process.GetProcessesByName("sldworks").Length > 1)
            {
                strMessage = "Multiple instances of Solidworks detected.";
                //blnStatus = false;
            }
            else
            {
                strMessage = null;
                //swApp = System.Diagnostics.Process.GetProcessesByName("SldWorks.Application");
                swApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
                //swApp = (SolidWorks.Interop.sldworks.Application)
            }

            SwDMClassFactory swClassFact;

            swClassFact = new SwDMClassFactory();

            return(strMessage);
        }
Пример #2
0
        static void Main(string[] args)
        {
            SwDMClassFactory classFactory = Activator.CreateInstance(
                Type.GetTypeFromProgID("SwDocumentMgr.SwDMClassFactory")) as SwDMClassFactory;

            if (classFactory != null)
            {
                SwDMApplication dmApp = classFactory.GetApplication(SW_DM_KEY);
                Console.WriteLine(dmApp.GetLatestSupportedFileVersion());
            }
            else
            {
                throw new NullReferenceException("Document Manager SDK is not installed");
            }
        }
Пример #3
0
        public override Boolean connect()
        {
            try
            {
                // replace licenseKey with your license key
                SwDMClassFactory swClassFact = default(SwDMClassFactory);
                String licenseKey = "<Your License Key>";

                swClassFact = new SwDMClassFactory();
                app = (SwDMApplication)swClassFact.GetApplication(licenseKey);

            }
            catch
            {
                app = null;
            }
            return (app != null);
        }
Пример #4
0
        public void GetProperty(string filePath, string configName, string fieldName, out string value, out string nPropTypeStr)
        {
                //OpenDoc
                var swClassFact = new SwDMClassFactory();
                var swDocMgr = swClassFact.GetApplication("82EC0E04A67C7A48A3AB757A947C507A8210C1E87738B58E");
                //_nDocType = SwDocMgrDocType(filePath);
                const SwDmDocumentType nDocType = SwDmDocumentType.swDmDocumentPart;
                var swDocument15 = (SwDMDocument15) swDocMgr.GetDocument(@filePath, nDocType, true, out _nRetVal);
                var swDocument13 = (SwDMDocument13) swDocument15;
                var swCfgMgr = swDocument13.ConfigurationManager;
                var swCfg = (SwDMConfiguration13) swCfgMgr.GetConfigurationByName(configName);

                SwDmCustomInfoType nPropType;
                value = swCfg.GetCustomProperty(fieldName, out nPropType);
                nPropTypeStr = nPropType.ToString();

                // CloseDoc
                swDocument15.CloseDoc();
        }
Пример #5
0
        public void SetProperty(string filePath, string configName, string fieldName, out string value, out string nPropTypeStr)
        {
            nPropTypeStr = "";
            value = "";

            //OpenDoc
            var swClassFact = new SwDMClassFactory();
            var swDocMgr = swClassFact.GetApplication("82EC0E04A67C7A48A3AB757A947C507A8210C1E87738B58E");
            //_nDocType = SwDocMgrDocType(filePath);
            const SwDmDocumentType nDocType = SwDmDocumentType.swDmDocumentPart;
            var swDocument15 = (SwDMDocument15)swDocMgr.GetDocument(@filePath, nDocType, true, out _nRetVal);

            var swDocument13 = (SwDMDocument13)swDocument15;

            var swCfgMgr = swDocument13.ConfigurationManager;
            var swCfg = (SwDMConfiguration13)swCfgMgr.GetConfigurationByName(configName);

            ProcessConfigCustomProperties(swCfg);
            try
            {
                SwDmCustomInfoType nPropType;
                value = swCfg.GetCustomProperty("Материал", out nPropType);
                swCfg.SetCustomProperty("Материал", "Лист Оцинковка");
                MessageBox.Show(value);
                value = swCfg.GetCustomProperty("Материал", out nPropType);
                MessageBox.Show(value);
                nPropTypeStr = nPropType.ToString();
            }
            catch (Exception e)
            {

                MessageBox.Show(e.Message);
            }
            // CloseDoc
            swDocument15.CloseDoc();
        }
Пример #6
0
 internal static SwDMApplication GetSwDmApp()
 {
     var swDocMgrClsFactory = new SwDMClassFactory();
     return swDocMgrClsFactory.GetApplication("7DBAB8BFA71BAA4AD7A88E1ABC12D7437FE07A00F33DAAB0");
 }
Пример #7
0
        static void Main(string[] args)
        {
            // get args
            string strBasePath = args[0];
            string strOutFile = args[1];
            string strLicenseKey = args[2];

            // get SW document manager application
            SwDMApplication swDocMgr;
            SwDMClassFactory swClassFact = new SwDMClassFactory();

            try
            {
                swDocMgr = swClassFact.GetApplication(strLicenseKey);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to get an instance of the SolidWorks Document Manager API: " + ex.Message);
                return;
            }

            // get list of potential parent files
            string[] strFiles = Directory.GetFiles(strBasePath, "*.*", SearchOption.AllDirectories);

            // get dependencies from SW
            List<string[]> lstDepends = GetDependencies(strFiles, swDocMgr);

            // write to csv
            StringBuilder sb = new StringBuilder();
            foreach (string[] row in lstDepends)
            {
                sb.AppendLine("\"" + string.Join("\",\"", row) + "\"");
            }
            File.WriteAllText(strOutFile, sb.ToString());
        }
        protected bool TraverseCore(string assemblyPath, string configurationName)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                return(false);
            }
            if (!File.Exists(assemblyPath))
            {
                return(false);
            }
            string           originalExt;
            SwDmDocumentType docType = SldFileExtentionChecker.CheckDM(assemblyPath, out originalExt);

            if (docType != SwDmDocumentType.swDmDocumentAssembly && docType != SwDmDocumentType.swDmDocumentPart)
            {
                return(false);
            }
            SwDMClassFactory swDMClassFactory = new SwDMClassFactory();
            //this.AllComObjects.Enqueue(swDMClassFactory);
            SwDMApplication swDMApp = swDMClassFactory.GetApplication(GetDocumentPropertiesViaDM.LinktronLicenseKey);

            this.GlobalSearchOption = swDMApp.GetSearchOptionObject();
            //this.AllComObjects.Enqueue(swDMApp);
            SwDmDocumentOpenError returnValue = 0;
            SwDMDocument17        swDoc       = (SwDMDocument17)swDMApp.GetDocument(assemblyPath, docType, true, out returnValue);

            if (swDoc == null || returnValue != SwDmDocumentOpenError.swDmDocumentOpenErrorNone)
            {
                return(false);
            }
            //this.AllComObjects.Enqueue(swDoc);
            SwDMConfigurationMgr dmConfigMgr = swDoc.ConfigurationManager;

            //this.AllComObjects.Enqueue(dmConfigMgr);
            string[] configurationNames = (string[])dmConfigMgr.GetConfigurationNames();
            if (configurationNames == null || configurationNames.Length <= 0)
            {
                return(false);
            }
            string configNameToOpen = null;

            if (string.IsNullOrEmpty(configurationName))
            {
                configNameToOpen = dmConfigMgr.GetActiveConfigurationName();
            }
            else
            {
                configNameToOpen = configurationName;
            }
            SwDMConfiguration14 activeCfg = (SwDMConfiguration14)dmConfigMgr.GetConfigurationByName(configNameToOpen);

            if (activeCfg == null)
            {
                return(false);
            }
            //this.AllComObjects.Enqueue(activeCfg);
            int topId = this.GetTopDocumentInfo(assemblyPath, swDoc, activeCfg);

            if (topId <= 0)
            {
                return(false);
            }

            if (docType == SwDmDocumentType.swDmDocumentAssembly)
            {
                try
                {
                    object[] allComponents = activeCfg.GetComponents();
                    if (allComponents != null)
                    {
                        foreach (object o in allComponents)
                        {
                            SwDMComponent9 subComponent = o as SwDMComponent9;
                            this.TraverseRecursively(subComponent, 1, topId);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(string.Format("TraverseCore:exception:{0}", ex.Message));
                }
            }
            return(true);
        }