Exemplo n.º 1
0
        private static void CheckTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            //kill solidworks
            swApp = null;
            try
            {
                Process.Kill();
            }
            catch
            {
            }
            Debug.Print("Solidworks Timed out");
            Console.WriteLine("Solidworks Timed out");

            while (swApp == null)
            {
                Tuple <SldWorks, Process> tuple = GetSolidworks.Solidworks(1);
                swApp   = tuple.Item1;
                Process = tuple.Item2;
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            ModelDoc2         swModelDoc    = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            PackAndGo         swPackAndGo   = default(PackAndGo);
            //SldWorks swApp = new SldWorks();
            //GetSolidworks getSW = new GetSolidworks();
            Tuple <SldWorks, Process> processes = GetSolidworks.Solidworks(1);

            swApp   = processes.Item1;
            Process = processes.Item2;
            //swApp.Visible = false;


            //add another line to get item 2 which is the process which you can then use to kill when it derps

            /* To be used to more easily choose which assemblies to pack and go
             * List<string> trNames = new List<string>(new string[] { "500", "525"});
             * List<string> cmtNames = new List<string>(new string[] { "500", "525" });
             *
             * for (int i = 0; i <= trNames.Count - 1; i++)
             * {
             *  trNames[i] = "TR-34-20-" + trNames[i];
             * }
             * for (int i = 0; i <= cmtNames.Count - 1; i++)
             * {
             *  cmtNames[i] = "CMT-34-20-" + cmtNames[i];
             * }
             */

            List <string> modelNames = new List <string>(new string[] { "TR-34-20-400", "TR-34-20-425", "TR-34-20-500", "TR-34-20-525", "TR-34-20-530", "TR-34-20-600", "TR-34-20-625", "TR-34-20-630", "TR-34-20-700", "TR-34-20-725", "TR-34-20-730", "TR-34-20-900", "TR-34-20-925", "TR-34-20-930",
                                                                        "CMT-34-20-400", "CMT-34-20-425", "CMT-34-20-500", "CMT-34-20-525", "CMT-34-20-530", "CMT-34-20-600", "CMT-34-20-625", "CMT-34-20-630", "CMT-34-20-700", "CMT-34-20-725", "CMT-34-20-730", "CMT-34-20-900", "CMT-34-20-925", "CMT-34-20-930" });

            //List<string> modelNames = new List<string>(new string[] { "TR-34-20-400", "TR-34-20-425", "TR-34-20-500" });
            int modelCount = modelNames.Count;

            while (modelNames.Count > 0)
            {
                SetCheckTimer();
                int j = 0;
                try
                {
                    string openFile   = null;
                    bool   status     = false;
                    int    warnings   = 0;
                    int    errors     = 0;
                    int    i          = 0;
                    int    namesCount = 0;
                    string savePath   = null;
                    int[]  statuses   = null;

                    openFile = @"C:\Configurator\" + modelNames[j] + ".sldasm";
                    Debug.Print("Performing pack and go on " + modelNames[j]);
                    Console.WriteLine("Performing pack and go on " + modelNames[j]);

                    swModelDoc         = swApp.OpenDoc6(openFile, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
                    swModelDoc.Visible = false;
                    swApp.Visible      = false; //opendoc6 seems to remove the visiblility setting
                    swModelDocExt      = (ModelDocExtension)swModelDoc.Extension;

                    swPackAndGo = (PackAndGo)swModelDocExt.GetPackAndGo();

                    savePath = @"C:\Configurator\PackandGoTest\test.zip";
                    status   = swPackAndGo.SetSaveToName(false, savePath);
                    swPackAndGo.FlattenToSingleFolder = true;

                    namesCount = swPackAndGo.GetDocumentNamesCount();
                    Debug.Print("  Number of model documents: " + namesCount);
                    Console.WriteLine("  Number of model documents: " + namesCount);
                    // Include any drawings, SOLIDWORKS Simulation results, and SOLIDWORKS Toolbox components
                    swPackAndGo.IncludeDrawings = true;
                    //Debug.Print(" Include drawings: " + swPackAndGo.IncludeDrawings);
                    swPackAndGo.IncludeSimulationResults = false;
                    //Debug.Print(" Include SOLIDWORKS Simulation results: " + swPackAndGo.IncludeSimulationResults);
                    swPackAndGo.IncludeToolboxComponents = false;
                    //Debug.Print(" Include SOLIDWORKS Toolbox components: " + swPackAndGo.IncludeToolboxComponents);
                    swPackAndGo.IncludeSuppressed = true;
                    // Verify document paths and filenames after adding prefix and suffix
                    object getFileNames;
                    object getDocumentStatus;


                    status = swPackAndGo.GetDocumentSaveToNames(out getFileNames, out getDocumentStatus);
                    string[] pgGetFileNames = (string[])getFileNames;
                    if (pgGetFileNames.Length == 0)
                    {
                        status         = swPackAndGo.GetDocumentSaveToNames(out getFileNames, out getDocumentStatus);
                        pgGetFileNames = (string[])getFileNames;
                    }

                    for (int z = 0; z < pgGetFileNames.Length; z++)
                    {
                        if (pgGetFileNames[z].StartsWith(@"c:\configurator"))
                        {
                        }
                        else
                        {
                            Debug.Print(pgGetFileNames[z]);
                            Console.WriteLine("Please Remove This File and Try Again: " + pgGetFileNames[z]);
                        }
                        pgGetFileNames[z] = GetProperFilePathCapitalization(pgGetFileNames[z]);
                    }
                    swPackAndGo.SetDocumentSaveToNames(pgGetFileNames);
                    //for (int z = 0;z< )
                    //pgGetFileNames = (string[])getFileNames;

                    /*This section is unnecessary and clutters the debug window, add back in at own preference
                     * Debug.Print("");
                     * Debug.Print("  My Pack and Go path and filenames after adding prefix and suffix: ");
                     * for (i = 0; i <= namesCount - 1; i++)
                     * {
                     *  Debug.Print("    My path and filename is: " + pgGetFileNames[i]);
                     * }
                     */

                    // Pack and Go
                    statuses = (int[])swModelDocExt.SavePackAndGo(swPackAndGo);
                    //swApp.CloseDoc(modelNames[j]);
                    checkTimer.Stop();
                    swApp.CloseAllDocuments(true);
                    modelNames.RemoveAt(0); //removes as the very last step to ensure successful execution
                }
                catch (Exception e)
                {
                    /*
                     * Process swProcess = new Process();
                     * int processID = swApp.GetProcessID();
                     * swProcess = Process.GetProcessById(processID);
                     * swProcess.Kill();
                     * while (swProcess.HasExited == false) { }
                     */
                    checkTimer.Stop();
                    swApp = null;
                    try
                    {
                        Process.Kill();
                    }
                    catch
                    {
                    }

                    Debug.Print("Solidworks Crash: Restarting Now");
                    Console.WriteLine("Solidworks Crash: Restarting Now");
                    Debug.Print(e.StackTrace);
                    while (swApp == null)
                    {
                        Tuple <SldWorks, Process> tuple = GetSolidworks.Solidworks(1);
                        swApp   = tuple.Item1;
                        Process = tuple.Item2;
                    }
                }
            }

            swApp.Visible = true;

            swApp.SendMsgToUser2("Pack and Go Is Complete!", 2, 2);
        }