internal static ISwDMApplication ConnectToDm(SecureString dmKeySecure) { ISwDMClassFactory classFactory = null; var classFactoryType = Type.GetTypeFromProgID("SwDocumentMgr.SwDMClassFactory"); if (classFactoryType != null) { classFactory = Activator.CreateInstance(classFactoryType) as ISwDMClassFactory; } if (classFactory != null) { var dmKey = new NetworkCredential("", dmKeySecure).Password; try { var dmApp = classFactory.GetApplication(dmKey); if (dmApp != null) { var testVers = dmApp.GetLatestSupportedFileVersion(); return(dmApp); } else { throw new Exception("Application is null"); } } catch (Exception ex) { throw new SwDmConnectFailedException(ex); } } else { throw new SwDmSdkNotInstalledException(); } }
static void Main(string[] args) { ClasFact = new SwDMClassFactory(); dmDocMgr = (SwDMApplication4)ClasFact.GetApplication(SwDocumentMgr_Data.sLicenseKey); OpenFileDialog OFD = new OpenFileDialog(); OFD.Filter = "Excel (*.xlsx)|*.xlsx;"; try { if (OFD.ShowDialog() == DialogResult.OK) { if (File.Exists(OFD.FileName)) { Console.WriteLine("Reading file...."); List<FileData> Data = ImportData(OFD.FileName); if (Data.Count != 0) { foreach (FileData item in Data) { Console.WriteLine("Updating file : " + item.fileName); UpdateFiles(item); } } } else { Console.WriteLine("File not valid...."); } } else { Console.WriteLine("File not valid...."); } } finally { if (Errors.Count != 0) { Console.WriteLine("Errors :" + Errors.Count.ToString()); string Time = (DateTime.Now).ToString(); Time = Time.Replace("/", "-"); Time = Time.Replace(":", "-"); string FilePath = "C:\\Temp\\SolidworksAttsUpdate - " + Time + ".txt"; // System.IO.File.Create(FilePath); using (StreamWriter sw = new StreamWriter(FilePath, false)) { foreach (FileData item in Errors) { sw.WriteLine(item.fileName + "," + item.folderPath + "," + item.prefix + "," + item.result + "," + item.Message); } } System.Diagnostics.Process.Start(FilePath); } else { Console.WriteLine("No errors, Complete!"); } Console.WriteLine("Push any key to close"); Console.Read(); } }