示例#1
0
 //event
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     SolidworksSingleton.Dispose();
     Properties.Settings.Default.PathToLustProperties = pathToSettings;
     Properties.Settings.Default.LustPropertiPreset   = toolStripComboBox_addTo.SelectedIndex;
     Properties.Settings.Default.Save();
 }
        private async void MessageForm_Load(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = false;
            dialog.Filter      = "Solidworks 3d (*.sldprt;*.sldasm)|*.sldprt;*.sldasm|Parts (*.sldprt)|*.sldprt|Assemblies (*.sldasm)|*.sldasm";

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                this.Close();
                return;
            }

            path = dialog.FileName;
            if (!File.Exists(path))
            {
                this.Close();
                return;
            }


            this.Text = "Loading...";
            this.button_import.Enabled   = false;
            this.comboBox_config.Enabled = false;

            Form1 f = (Form1)this.Owner;

            this.label1.Text      = "Start Solidworks";
            button_import.Enabled = false;
            if (swApp == null)
            {
                swApp = await SolidworksSingleton.GetSwAppAsync();
            }

            this.label1.Text      = "Choose configugation name\n and press import.";
            button_import.Enabled = true;

            string            ext = Path.GetExtension(path);
            swDocumentTypes_e type;

            if (ext.ToLower().Contains("sldprt"))
            {
                type = swDocumentTypes_e.swDocPART;
            }
            else if (ext.ToLower().Contains("sldasm"))
            {
                type = swDocumentTypes_e.swDocASSEMBLY;
            }
            else
            {
                this.Close();
                return;
            }

            try
            {
                int Error   = 0;
                int Warning = 0;
                doc = swApp.OpenDoc6(path, (int)type, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Error, ref Warning);

                if (Error != 0)
                {
                    MessageBox.Show("Fail to open file");
                    this.Close();
                    return;
                }
                configurations.AddRange(doc.GetConfigurationNames());
                comboBox_config.DataSource = configurations;
                comboBox_config.Enabled    = true;
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#3
0
        private async void importItem_main_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = false;

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string path = dialog.FileName;

            if (!File.Exists(path))
            {
                return;
            }


            if (swApp == null)
            {
                toolStripStatusLabel_status.Text = "Lunch SolidWorks. Please wait";
            }

            this.Enabled = false;
            Form f = new LoadForm();

            f.StartPosition = FormStartPosition.CenterParent;
            f.Show(this);

            int             timeout = 10000;
            Task <SldWorks> task    = SolidworksSingleton.GetSwAppAsync();

            //swApp = await SolidworksSingleton.GetSwAppAsync();
            if (await Task.WhenAny(task, Task.Delay(timeout)) == task)
            {
                swApp = await task;
            }
            else
            {
                f.Close();
                this.Enabled = true;
                MessageBox.Show("Time out");
                return;
            }



            Helper.HelperResult res = Helper.ImportProperties(swApp, bindingSource_swSettings, path);
            if (res != Helper.HelperResult.SUCCESS)
            {
                toolStripStatusLabel_status.Text = "Fail to import";
            }
            else
            {
                toolStripStatusLabel_status.Text = "Ready!";
            }

            f.Close();
            this.Enabled = true;
            //throw new NotImplementedException();
        }
示例#4
0
        //buttons
        private async void button_start_Click(object sender, EventArgs e)
        {
            setEnableUiTools(false);

            //check tables
            if (bindingSource_swSettings.Count == 0)
            {
                MessageBox.Show("Setting table is empty!\n Please add settings before you press start");
                setEnableUiTools(true);
                return;
            }
            if (bindingSource_swFolder.Count == 0)
            {
                MessageBox.Show("File table is empty!\n Please add file before you press start");
                setEnableUiTools(true);
                return;
            }

            BindingList <FileObj> fileList = (BindingList <FileObj>)bindingSource_swFolder.DataSource;

            if (fileList.Count == 0)
            {
                MessageBox.Show("Fail to read from table!");
                return;
            }


            if (swApp == null)
            {
                toolStripStatusLabel_status.Text = "Lunch SolidWorks...";
            }
            swApp = await SolidworksSingleton.GetSwAppAsync();

            //swApp.Visible = false;
            if (swApp == null)
            {
                MessageBox.Show("Fail to start Solid Works");
            }
            else
            {
                toolStripStatusLabel_status.Text = "SolidWorks started!";
            }

            BindingList <PropertyObject> prop_list = (BindingList <PropertyObject>)bindingSource_swSettings.DataSource;

            if (prop_list.Count == 0)
            {
                MessageBox.Show("Fail to read from settings");
                return;
            }

            toolStripProgressBar1.Maximum = fileList.Count;
            toolStripProgressBar1.Value   = 0;
            //run process method
            try
            {
                cancelSource = new CancellationTokenSource();
                foreach (FileObj file in fileList)
                {
                    processModelAsyncTask = ProcessModelAsync(cancelSource.Token, file);
                    Helper.HelperResult res = await processModelAsyncTask;
                    Console.WriteLine("Res {0}", res);
                    toolStripProgressBar1.Value     += 1;
                    toolStripStatusLabel_status.Text = file.Name;

                    //if(res == Helper.HelperResult.CANCELED)
                    //{
                    //	toolStripStatusLabel_status.Text = "Canceled";
                    //	break;
                    //}
                }

                toolStripStatusLabel_status.Text = "Done";
            }
            catch (Exception ex)
            {
                toolStripStatusLabel_status.Text = ex.Message;
            }


            processModelAsyncTask = null;
            setEnableUiTools(true);
        }