public ModelDoc2 OpenSwAssembly(string path) { ModelDoc2 swModel = default(ModelDoc2); DocumentSpecification swDocSpecification = default(DocumentSpecification); string[] componentsArray = new string[1]; object[] components = null; string name = null; int errors = 0; int warnings = 0; //Set the specifications swDocSpecification = (DocumentSpecification)app.GetOpenDocSpec(path); componentsArray[0] = "food bowl-1@bowl and chute"; components = (object[])componentsArray; swDocSpecification.ComponentList = components; swDocSpecification.Selective = true; name = swDocSpecification.FileName; swDocSpecification.DocumentType = (int)swDocumentTypes_e.swDocASSEMBLY; swDocSpecification.DisplayState = "Default_Display State-1"; swDocSpecification.UseLightWeightDefault = false; swDocSpecification.LightWeight = true; swDocSpecification.Silent = true; swDocSpecification.IgnoreHiddenComponents = true; //Open the assembly document as per the specifications swModel = (ModelDoc2)app.OpenDoc7(swDocSpecification); errors = swDocSpecification.Error; warnings = swDocSpecification.Warning; Debugger.Break(); if (errors > 0) { throw new Exception("Error while opening Solidworks assembly"); } if (warnings > 0) { System.Diagnostics.Debug.WriteLine("Warning while opening Soliworks assembly"); } activeModel = swModel; return(swModel); }
public static DocumentSpecification GetDocumentSpecification( ISldWorks swApp, string path) { try { try { if (path == null || string.Compare(path, "") == 0 || swApp == null) { throw new ArgumentException(); } } catch (ArgumentException) { return(null); } try { if (!File.Exists(path)) { throw new ArgumentException(); } } catch (ArgumentException) { return(null); } DocumentSpecification documentSpecification = (DocumentSpecification)swApp.GetOpenDocSpec(path); if (documentSpecification == null) { throw new Exception(); } return(documentSpecification); } catch (Exception) { return(null); } }
/// <summary> /// Returns the input as-is as output. /// </summary> /// <param name="input">The input.</param> /// <param name="sourceSpecification">The source specification.</param> /// <param name="targetSpecification">The target specification.</param> /// <returns>The input returned as-is as output.</returns> protected override string TransformInputToOutput(string input, DocumentSpecification sourceSpecification, DocumentSpecification targetSpecification) => input;
public static DocumentSpecification GetDocumentSpecification( ISldWorks swApp, string path) { logger.Debug("\n Getting Document Specification for File: " + path); try { try { if (path == null || string.Compare(path, "") == 0 || swApp == null) { throw new ArgumentException(); } } catch (ArgumentException exception) { logger.Error(exception, "\n ERROR: Document Specification path or SolidWorks app reference was null or empty"); return(null); } try { logger.Debug("\n Checking file " + path + " exists"); if (!File.Exists(path)) { throw new ArgumentException(); } logger.Debug("\n File " + path + " Found"); } catch (ArgumentException exception) { logger.Error(exception, "\n ERROR: File " + path + " Not Found"); return(null); } DocumentSpecification documentSpecification = (DocumentSpecification)swApp.GetOpenDocSpec(path); logger.Debug("\n Returning Document Specification for " + path + "\n " + documentSpecification); if (documentSpecification == null) { throw new Exception(); } return(documentSpecification); } catch (Exception exception) { logger.Error(exception, "\n ERROR: Could Not Get Document Specification For " + path); return(null); } }
public static void Start(string installDirectory, string programStatePath, string GUIconfigPath, string DDTOpath) { /* * This program listens for a 'call to action bool' * - the second character in a string from the * - run state config file for this MS * On TRUE it reads the DDTO, which the GUI MS * will have sent the current set of expressions to * evaluate, then set the GUI's call to action state * to false - meaning it cannot write to the DDTO, * though it will store the command and do it asap, * then this daemon will read the DDTO and implement * the expressions in it, after it resets its own * and the GUI's call to action, turning itself off * and the GUI's write ability on */ RunState programState; Console.WriteLine(" -- Daemon - Start --"); try { do { programState = RunState.GetProgramState(programStatePath); if (programState.GetActionState()) { CloseGUIsemaphore(GUIconfigPath); var PROG_ID = "SldWorks.Application.24"; var swType = Type.GetTypeFromProgID(PROG_ID); ValidateSWtype(swType); swApp = (ISldWorks)Activator.CreateInstance(swType); CreateSWAppInstance(swApp); var blobName = programState.GetBlobName(); var blobPath = installDirectory + "blob\\" + blobName; DocumentSpecification documentSpecification = SWDocSpecification.GetDocumentSpecification(swApp, blobPath); if (documentSpecification == null) { Console.WriteLine("Could not Get Document Specification for - " + blobPath); return; } Console.WriteLine(" - Obtained Document Specification for - " + blobPath); var model = swApp.OpenDoc7( documentSpecification); if (model == null) { Console.WriteLine(" - ERROR - Could not Open Document - " + blobPath); return; } Console.WriteLine(" - Opened SolidWorks Document - " + blobPath); EquationMgr equationManager = model.GetEquationMgr(); if (equationManager == null) { Console.WriteLine("Could Not Get Equation Manager Instance"); Console.WriteLine(" - Closing All Open SolidWorks Documents"); swApp.CloseAllDocuments(true); return; } Console.WriteLine(" - Created Equation Manager Instance"); var rawBlempString = Blemp.LoadDDTO(DDTOpath); var writeSuccess = false; var timeOut = 5; if (rawBlempString != null) { var equationSegments = Blemp.GetDDTOequationSegments(rawBlempString); if (equationSegments != null) { Console.WriteLine(" - Valid Equations Found - Processing"); try { for (var i = 0; i < equationSegments.Length; ++i) { SWEquation.AddEquation( equationManager, equationSegments[i] ); SWEquation.Build( model ); SWEquation.DeleteEquation( equationManager, 0); } } catch (ArgumentOutOfRangeException exception) { Console.WriteLine(exception); } } else { Console.WriteLine(" - WARNING - No Valid Equations for Processing Found"); } } else { Console.WriteLine("No Equations Found in DDTO"); } do { Console.WriteLine(" - Closing Call to Action Semaphore"); writeSuccess = FileWrite.WriteStringToFileFalseOnFail( programStatePath, "011!" ); FileWrite.WriteStringToFileFalseOnFail(DDTOpath, ""); Thread.Sleep(300); } while (!writeSuccess && timeOut-- > 0); if (timeOut > 0) { Console.WriteLine(" - Call to Action Semaphore - Successfuly Closed"); } else { Console.WriteLine(" - ERROR - Could Not Write Call to Action Close Command"); Console.WriteLine(" - Exiting Daemon -"); Console.WriteLine(" -- Daemon - Exit --"); return; } timeOut = 5; do { Console.WriteLine(" - Opening GUI Call to Action Semaphore"); writeSuccess = FileWrite.WriteStringToFileFalseOnFail( GUIconfigPath, "00" ); Thread.Sleep(300); } while (!writeSuccess && timeOut-- > 0); } if (programState.GetCloseBlob()) { CloseGUIsemaphore(GUIconfigPath); if (swApp != null) { swApp.CloseAllDocuments(true); } FileWrite.WriteStringToFileFalseOnFail(programStatePath, "011!"); Console.WriteLine(" - Opening GUI Call to Action Semaphore"); FileWrite.WriteStringToFileFalseOnFail( GUIconfigPath, "00"); } Thread.Sleep(300); } while (programState.GetRunState()); } catch (Exception exception) { Console.WriteLine(exception); } if (swApp != null) { swApp.CloseAllDocuments(true); } Console.WriteLine(" -- Daemon - Exit --"); }
static void Main(string[] args) { // LiveUpdateTest(); var swType = SWType.GetFromProgID(PROG_ID); if (swType == null) { logger.Error("\n ERROR: GetFromProgID returned null\n" + " - Exiting Program"); promptToExitProgram(); return; } ISldWorks swApp = CreateSWInstance.Create(swType); if (swApp == null) { logger.Error("\n ERROR: Could not get reference to " + "SolidWorks App\n - Exiting Program"); promptToExitProgram(); return; } var path = "C:\\Users\\bolinger\\Desktop\\test install\\toppAppDBdaemon\\blob\\C-HSSX.blob.SLDPRT"; DocumentSpecification documentSpecification = SWDocSpecification.GetDocumentSpecification(swApp, path); if (documentSpecification == null) { logger.Error("\n ERROR: Could not Get Document Specification for file: " + path + "\n - Exiting Program"); promptToExitProgram(); return; } logger.Debug("\n Getting Model from Document Specification"); ModelDoc2 model = (ModelDoc2)swApp.OpenDoc7( documentSpecification); if (model == null) { logger.Error("\n ERROR: Could not get Model from " + "Document Specification\n - Exiting Program"); promptToExitProgram(); return; } Config.model = model; logger.Debug("\n Getting Equation Manager from Model"); EquationMgr equationManager = model.GetEquationMgr(); if (equationManager == null) { logger.Error("\n ERROR: Could not get Equation Manager from Model\n" + " - Exiting Program"); promptToExitProgram(); return; } Config.equationManager = equationManager; logger.Debug("\n SolidWorks App Instance Initialized - Starting Microservice Daemon"); Daemon.Start(); promptToExitProgram(); logger.Debug("\n Closing Open SolidWorks Documents" + "\n - Exiting Microservice"); swApp.CloseAllDocuments(true); }