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(); }
void OpenDoc() { _swDocMgr = _swClassFact.GetApplication(SLicenseKey); _nDocType = SwDocMgrDocType(); _swDocument10 = (SwDMDocument10)_swDocMgr.GetDocument(SDocFileName, _nDocType, false, out _nRetVal); _swDocument13 = (SwDMDocument13)_swDocument10; }
private static SwDMApplication ConnectoToDm(string licKey) { var classFact = new SwDMClassFactory(); var docMgr = classFact.GetApplication(licKey) as SwDMApplication; return(docMgr); }
public bool ExistSheetMetalDM() { var result = false; try { var sLicenseKey = LicenseKeyDM; var nDocType = SwDmDocumentType.swDmDocumentPart; var swClassFact = new SwDMClassFactory(); var swDocMgr = swClassFact.GetApplication(sLicenseKey); var nRetVal = default(SwDmDocumentOpenError); var swDocument10 = (SwDMDocument10)swDocMgr.GetDocument(filePath, nDocType, true, out nRetVal); // true - если файл только для чтения if (swDocument10 != null) { var swDocument13 = (SwDMDocument13)swDocument10; if (swDocument13 != null) { var CutListItems = (object[])swDocument13.GetCutListItems2(); if (CutListItems != null) { result = true; } } } } catch (Exception ex) { //Logger.ToLog($"ERROR SHEET METAL: {ex.ToString()}, {ex.StackTrace}", 10001); } return(result); }
static void Main(string[] args) { var dirPath = args[0]; var filter = args[1]; var outCsvFilePath = args[2]; var classFact = new SwDMClassFactory(); var app = classFact.GetApplication(LICENSE_KEY); using (var csvFileWriter = File.CreateText(outCsvFilePath)) { csvFileWriter.WriteLine("File Path, Configuration Name, X, Y, Z, Volume, Surface Area, Mass, XX, YY, ZZ, XY, ZX, YZ"); foreach (var filePath in Directory.GetFiles(dirPath, filter, SearchOption.AllDirectories)) { try { ProcessFile(app, filePath, csvFileWriter); } catch (Exception ex) { csvFileWriter.WriteLine($"\"{filePath}\",,{ex.Message}"); } } } }
static void Main(string[] args) { var filePath = args[0]; var outImgFilePath = args[1]; var classFact = new SwDMClassFactory(); var app = classFact.GetApplication(LICENSE_KEY); var docType = SwDmDocumentType.swDmDocumentUnknown; switch (Path.GetExtension(filePath).ToLower()) { case ".sldprt": docType = SwDmDocumentType.swDmDocumentPart; break; case ".sldasm": docType = SwDmDocumentType.swDmDocumentAssembly; break; case ".slddrw": docType = SwDmDocumentType.swDmDocumentDrawing; break; } SwDmDocumentOpenError err; var doc = app.GetDocument(filePath, SwDmDocumentType.swDmDocumentPart, true, out err); if (doc != null) { var activeConfName = doc.ConfigurationManager.GetActiveConfigurationName(); var conf = doc.ConfigurationManager.GetConfigurationByName(activeConfName) as ISwDMConfiguration14; SwDmPreviewError previewErr; var imgBytes = conf.GetPreviewPNGBitmapBytes(out previewErr) as byte[]; if (previewErr == SwDmPreviewError.swDmPreviewErrorNone) { using (var memStr = new MemoryStream(imgBytes)) { memStr.Seek(0, SeekOrigin.Begin); var img = Image.FromStream(memStr); img.Save(outImgFilePath); } } else { Console.WriteLine($"Failed to extract preview from the document: {previewErr}"); } } else { Console.WriteLine($"Failed to open the document: {err}"); } }
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"); } }
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); }
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(); }
// constructor public SWDocMgr(string strLicenseKey) { SwDMClassFactory swClassFact; swClassFact = new SwDMClassFactory(); try { swDocMgr = swClassFact.GetApplication(strLicenseKey); } catch (Exception ex) { DialogResult dr = MessageBox.Show("Failed to get an instance of the SolidWorks Document Manager API: " + ex.Message, "Loading SW", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } }
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(); }
static void Main(string[] args) { //Takes Care of input checking and input parsing string docPath; bool quietMode; switch (args.Length) { case 1: quietMode = false; if (args[0].Contains("*") || args[0].Contains("?")) { inputError(quietMode); return; } docPath = Path.GetFullPath(args[0]); break; case 2: if (args[0] != "/q") { quietMode = false; inputError(quietMode); return; } quietMode = true; if (args[1].Contains("*") || args[1].Contains("?")) { inputError(quietMode); return; } docPath = Path.GetFullPath(args[1]); break; default: quietMode = false; inputError(quietMode); return; } //Get Document Type SwDmDocumentType docType = setDocType(docPath); if (docType == SwDmDocumentType.swDmDocumentUnknown) { inputError(quietMode); return; } //Variable initialization SwDMDocument15 dmDoc; SwDmDocumentOpenError OpenError; ////Prerequisites dmClassFact = new SwDMClassFactory(); dmDocManager = dmClassFact.GetApplication(SolidWorksDocumentManagerKey) as SwDMApplication3; //Open the Document dmDoc = dmDocManager.GetDocument(docPath, docType, true, out OpenError) as SwDMDocument15; //Check that a SolidWorks file is open if (dmDoc != null) { try { GetRefs(ref dmDoc); } catch (Exception e) { Console.WriteLine("\"" + dmDoc.FullName + "\"\t\"" + "File is internally damaged, .NET error occurred, or GetReferences.exe has a Bug. " + "Error Message: " + e.Message.Replace(Environment.NewLine, " ") + ". Stack Trace: " + e.StackTrace.Replace(Environment.NewLine, " ") + "\""); inputError(quietMode); } dmDoc.CloseDoc(); } else { switch (OpenError) { case SwDmDocumentOpenError.swDmDocumentOpenErrorFail: Console.WriteLine("\"" + docPath + "\"\t\"" + "File failed to open; reasons could be related to permissions, the file is in use, or the file is corrupted." + "\""); inputError(quietMode); break; case SwDmDocumentOpenError.swDmDocumentOpenErrorFileNotFound: Console.WriteLine("\"" + docPath + "\"\t\"" + "File not found or file path is longer than 255 characters." + "\""); inputError(quietMode); break; case SwDmDocumentOpenError.swDmDocumentOpenErrorNonSW: Console.Write("\"" + docPath + "\"\t\"" + "Non-SolidWorks file was opened" + "\""); inputError(quietMode); break; default: Console.WriteLine("\"" + docPath + "\"\t\"" + "An unknown errror occurred. Something is wrong with the code of GetReferences" + "\""); inputError(quietMode); break; } } }
internal static SwDMApplication GetSwDmApp() { var swDocMgrClsFactory = new SwDMClassFactory(); return swDocMgrClsFactory.GetApplication("7DBAB8BFA71BAA4AD7A88E1ABC12D7437FE07A00F33DAAB0"); }
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); }