void IDisposable.Dispose() { try { _app.CloseAllDocuments(true); _app.ExitApp(); _app = null; } // ReSharper disable EmptyGeneralCatchClause catch { } // ReSharper restore EmptyGeneralCatchClause }
/// <summary> /// 关闭SldWorks对象,对象池销毁时调用 /// </summary> /// <param name="sldWorks">要关闭的对象</param> private void CloseSolidWorks(SldWorks sldWorks) { // 关闭 SldWorks,释放所占用的系统资源 sldWorks.ExitApp(); //IDisposable disp = sldWorks as IDisposable; //disp.Dispose(); }
public void CloseSolidWorks() { if (swApp != null) { swApp.ExitApp(); swApp = null; } }
/// <summary> /// 释放SW /// </summary> public static void Dipose() { if (swApp != null) { swApp.ExitApp(); swApp = null; } }
//dispose of solidworks internal static void Dispose() { if (swApp != null) { swApp.ExitApp(); swApp = null; } }
/// <summary> /// 退出SW程序 /// </summary> public static void ExitSW() { if (swApp != null) { swApp.ExitApp(); swApp = null; } }
internal static void Close() { if (swApp != null) { swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, true); swApp.ExitApp(); swApp = null; swDoc = null; } }
static void CreateRevolve() { SldWorks swApp = new SldWorks(); ModelDoc2 swModel; ModelDocExtension swModelDocExt; FeatureManager swFeatMgr; SelectionMgr swSelMgr; bool boolstatus; swModel = (ModelDoc2)swApp.NewDocument("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\PartTemplate.SLDPRT", 0, 0, 0); //swModel = (ModelDoc2)swApp.ActiveDoc; swModelDocExt = swModel.Extension; swSelMgr = (SelectionMgr)swModel.SelectionManager; boolstatus = swModelDocExt.SelectByID2("Right Plane", "PLANE", 0, 0, 0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault); boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, true, 0, null, (int)swSelectOption_e.swSelectOptionDefault); swModel.InsertAxis2(true); boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", -0.08954836342753, 0.0004336873289503, 0.006720765739942, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault); swModel.InsertSketch2(true); swModel.ClearSelection2(true); swModel.SketchRectangle(-0.05, -0.05, 0, 0, 0.1, 0, true); swModel.InsertSketch2(true); swModel.ShowNamedView2("*Trimetric", 8); boolstatus = swModelDocExt.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 0, null, (int)swSelectOption_e.swSelectOptionDefault); boolstatus = swModelDocExt.SelectByID2("Axis1", "AXIS", 0, 0, 0, true, 4, null, (int)swSelectOption_e.swSelectOptionDefault); swFeatMgr = swModel.FeatureManager; swFeatMgr.FeatureRevolve2(true, true, false, false, false, false, 0, 0, 6.28318530718, 0, false, false, 0.01, 0.01, 0, 0, 0, true, true, true); swModel.SaveAs("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\FeatureRevolve.SLDPRT"); swApp.ExitApp(); }
internal static void Dispose() { if (swApp != null && !SwWasStarted) { swApp.CloseAllDocuments(true); swApp.ExitApp(); swApp = null; //if process is not close try { foreach (Process proc in Process.GetProcessesByName("SldWorks")) { proc.Kill(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void button1_Click_1(object sender, EventArgs e) { button1.Enabled = false; button1.Text = "Proceeding..."; // preventing empty fields if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox4.Text) || string.IsNullOrWhiteSpace(textBox5.Text) || string.IsNullOrWhiteSpace(textBox6.Text) || string.IsNullOrWhiteSpace(textBox7.Text) || string.IsNullOrWhiteSpace(textBox8.Text)) { MessageBox.Show("Enter all values", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int time = Convert.ToInt32(textBox1.Text); int step = Convert.ToInt32(textBox2.Text); int initt1 = Convert.ToInt32(textBox3.Text); int initt2 = Convert.ToInt32(textBox4.Text); int initt3 = Convert.ToInt32(textBox7.Text); int conv = Convert.ToInt32(textBox5.Text); double bulk = Convert.ToDouble(textBox8.Text) + 273.15; // converting to Kelvin units int heatpow = Convert.ToInt32(textBox6.Text); DisposeSW(); // Opening SW 2017 // Additional GUID: F16137AD-8EE8-4D2A-8CAC-DFF5D1F67522 Guid Guid1 = new Guid("6B36082E-677B-49E8-BCB2-76698EBD2906"); object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(Guid1)); swApp = (SldWorks)processSW; swApp.Visible = true; CosmosWorks COSMOSWORKS = default(CosmosWorks); CwAddincallback CWObject = default(CwAddincallback); CWModelDoc ActDoc = default(CWModelDoc); CWStudyManager StudyMngr = default(CWStudyManager); CWStudy Study = default(CWStudy); CWThermalStudyOptions ThermalOptions = default(CWThermalStudyOptions); CWConvection CWConv = default(CWConvection); CWMesh CwMesh = default(CWMesh); CWResults CWResult = default(CWResults); CWTemperature CWTemp = default(CWTemperature); ModelDoc2 Part = default(ModelDoc2); CWLoadsAndRestraintsManager LBCMgr = default(CWLoadsAndRestraintsManager); CWHeatPower CWHeatPower = default(CWHeatPower); ModelDoc2 swDoc = null; int bApp = 0; int longstatus = 0; int longwarnings = 0; int errCode = 0; double el = 0; double tl = 0; string cwpath = ""; Part = swApp.OpenDoc6("G:\\assem(simple).SLDASM", (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref longstatus, ref longwarnings); if (Part == null) { MessageBox.Show("Failed to open document"); } swDoc = swApp.IActiveDoc2; // connecting Simulation to SW cwpath = swApp.GetExecutablePath() + @"\Simulation\cosworks.dll"; errCode = swApp.LoadAddIn(cwpath); if (errCode != 0 && errCode != 2) { MessageBox.Show("Failed to load Simulation library"); swApp.ExitApp(); DisposeSW(); Application.Exit(); } // ready-check Simulation add-on CWObject = (CwAddincallback)swApp.GetAddInObject("CosmosWorks.CosmosWorks"); if (CWObject == null) { MessageBox.Show("Failed to start Simulation"); } // ready-check add-on object COSMOSWORKS = CWObject.CosmosWorks; if (COSMOSWORKS == null) { MessageBox.Show("Failed to create CosmosWorks object"); } // connecting add-on to document ActDoc = COSMOSWORKS.ActiveDoc; if (ActDoc == null) { MessageBox.Show("Failed to open document"); } // creating thermal analysis bApp = ActDoc.AddDefaultThermalStudyPlot((int)swsThermalResultComponentTypes_e.swsThermalResultComponentTypes_TEMP, true); StudyMngr = ActDoc.StudyManager; if (StudyMngr == null) { MessageBox.Show("Failed to start analysis manager"); } Study = StudyMngr.CreateNewStudy3("CPU Usage", (int)swsAnalysisStudyType_e.swsAnalysisStudyTypeThermal, (int)swsMeshType_e.swsMeshTypeSolid, out errCode); if (Study == null) { MessageBox.Show("Failed to create thermal analysis"); } ThermalOptions = Study.ThermalStudyOptions; Study.ThermalStudyOptions.SolutionType = 0; if (ThermalOptions == null) { MessageBox.Show("No analysis parameters"); } // analysis duration ThermalOptions.CheckFlowConvectionCoef = 0; ThermalOptions.SolverType = 2; ThermalOptions.TotalTime = time; ThermalOptions.TimeIncrement = step; LBCMgr = Study.LoadsAndRestraintsManager; if (LBCMgr == null) { MessageBox.Show("Failed to load loads and restraints manager"); } // lit coordinates swDoc.ShowNamedView2("*Top", 5); swDoc.ViewZoomtofit2(); ISelectionMgr selectionMgr = (ISelectionMgr)swDoc.SelectionManager; bool isSelected = swDoc.Extension.SelectByRay(-0.28387922510520769, 0.081999999999993634, -0.14613487203691797, 0, -1, 0, 0.0047546274155552031, 2, false, 0, 0); if (isSelected) { Entity swEntity = selectionMgr.GetSelectedObject6(1, -1); Component2 swComp = (Component2)swEntity.GetComponent(); object[] fixedpart = { swComp }; CWTemp = LBCMgr.AddTemperature(fixedpart, out errCode); if (errCode != 0) { MessageBox.Show("Failed to add temperature indicator"); } } CWTemp.TemperatureBeginEdit(); CWTemp.TemperatureType = 0; CWTemp.Unit = 2; CWTemp.TemperatureValue = initt2; errCode = CWTemp.TemperatureEndEdit(); if (errCode != 0) { MessageBox.Show("Failed to edit temperature indicator"); } swDoc.ClearSelection2(true); // silicon board coordinates isSelected = swDoc.Extension.SelectByRay(-0.41952594843134139, 0.02199999999999136, -0.41742831868918501, 0, -1, 0, 0.0047546274155552031, 2, false, 0, 0); if (isSelected) { Entity swEntity = selectionMgr.GetSelectedObject6(1, -1); Component2 swComp = (Component2)swEntity.GetComponent(); object[] fixedpart = { swComp }; CWTemp = LBCMgr.AddTemperature(fixedpart, out errCode); if (errCode != 0) { MessageBox.Show("Failed to add temperature indicator"); } } CWTemp.TemperatureBeginEdit(); CWTemp.TemperatureType = 0; CWTemp.Unit = 2; CWTemp.TemperatureValue = initt1; errCode = CWTemp.TemperatureEndEdit(); if (errCode != 0) { MessageBox.Show("Failed to edit temperature indicator"); } swDoc.ClearSelection2(true); // stalks coordinates swDoc.ShowNamedView2("*Bottom", 6); swDoc.ViewZoomtofit2(); isSelected = swDoc.Extension.SelectByRay(-0.42931488722807265, -0.050999999999987722, 0.28597685484736474, 0, 1, 0, 0.0047546274155552031, 2, false, 0, 0); if (isSelected) { Entity swEntity = selectionMgr.GetSelectedObject6(1, -1); Component2 swComp = (Component2)swEntity.GetComponent(); object[] fixedpart = { swComp }; CWTemp = LBCMgr.AddTemperature(fixedpart, out errCode); if (errCode != 0) { MessageBox.Show("Failed to edit temperature indicator"); } } CWTemp.TemperatureBeginEdit(); CWTemp.TemperatureType = 0; CWTemp.Unit = 2; CWTemp.TemperatureValue = initt3; errCode = CWTemp.TemperatureEndEdit(); if (errCode != 0) { MessageBox.Show("Failed to edit temperature indicator"); } swDoc.ClearSelection2(true); // all faces coordinates swDoc.ShowNamedView2("*Front", 1); swDoc.ViewZoomtofit2(); isSelected = swDoc.Extension.SelectByRay(-0.38382731822234351, 0.04982938298755997, 0.40017589628916994, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.18695037482381383, 0.049829382987560122, 0.42176499999999351, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.35735646868976789, 0.0713369482327776, 0.41521684512093771, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.10505618408240869, 0.010950322736590109, 0.4415000000000191, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.43015130490435044, -0.017174954891772284, 0.29464212540386825, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.42932409085645729, -0.016347740843879296, 0.29483222724246616, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0); swDoc.ShowNamedView2("*Back", 2); swDoc.ViewZoomtofit2(); isSelected = swDoc.Extension.SelectByRay(0.3581836827376611, 0.063064807753847776, -0.4148975912216315, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.14558967242916476, 0.053138239179132019, -0.42176499999999351, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.37969124798287845, 0.047347740843881027, -0.40327910794843547, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.033088561915719295, 0.012604750832376084, -0.4415000000000191, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.42766966276067148, -0.014693312748093316, -0.29499856062381014, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.42766966276067131, -0.022138239179130152, -0.29499856062381014, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0); swDoc.ShowNamedView2("*Left", 3); swDoc.ViewZoomtofit2(); isSelected = swDoc.Extension.SelectByRay(-0.42176499999999351, 0.046520526795988171, -0.081066976693512371, 1, 0, 0, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.4415000000000191, 0.0084686805929112003, -0.082721404789298347, 1, 0, 0, 0.0028125277628361371, 2, false, 0, 0); swDoc.ShowNamedView2("*Right", 4); swDoc.ViewZoomtofit2(); isSelected = swDoc.Extension.SelectByRay(0.42176499999999351, 0.052311025131239031, 0.1158099667050172, -1, 0, 0, 0.0028125277628361371, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.4415000000000191, 0.010123108688697121, 0.12490932123184006, -1, 0, 0, 0.0028125277628361371, 2, false, 0, 0); swDoc.ShowNamedView2("*Top", 5); swDoc.ViewZoomtofit2(); isSelected = swDoc.Extension.SelectByRay(-0.19376272580646192, 0.081999999999993634, -0.13541980560506936, 0, -1, 0, 0.0036397418107291194, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.41535877134202892, 0.02199999999999136, -0.42017607667975893, 0, -1, 0, 0.0036397418107291194, 2, false, 0, 0); swDoc.ShowNamedView2("*Bottom", 6); swDoc.ViewZoomtofit2(); isSelected = swDoc.Extension.SelectByRay(-0.20232682418464809, -0.00099999999997635314, 0.23818898614330264, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.42713440661203494, -0.050999999999987722, 0.28743255181787342, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.42713440661203483, -0.050999999999987722, 0.28529152722332685, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(0.4292754312065814, -0.050999999999987722, -0.28422101492605301, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0); isSelected = swDoc.Extension.SelectByRay(-0.42499338201748837, -0.050999999999987722, -0.28636203952059958, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0); if (isSelected) { object selectedFace1 = (object)selectionMgr.GetSelectedObject6(1, -1); object selectedFace2 = (object)selectionMgr.GetSelectedObject6(2, -1); object selectedFace3 = (object)selectionMgr.GetSelectedObject6(3, -1); object selectedFace4 = (object)selectionMgr.GetSelectedObject6(4, -1); object selectedFace5 = (object)selectionMgr.GetSelectedObject6(5, -1); object selectedFace6 = (object)selectionMgr.GetSelectedObject6(6, -1); object selectedFace7 = (object)selectionMgr.GetSelectedObject6(7, -1); object selectedFace8 = (object)selectionMgr.GetSelectedObject6(8, -1); object selectedFace9 = (object)selectionMgr.GetSelectedObject6(9, -1); object selectedFace10 = (object)selectionMgr.GetSelectedObject6(10, -1); object selectedFace11 = (object)selectionMgr.GetSelectedObject6(11, -1); object selectedFace12 = (object)selectionMgr.GetSelectedObject6(12, -1); object selectedFace13 = (object)selectionMgr.GetSelectedObject6(13, -1); object selectedFace14 = (object)selectionMgr.GetSelectedObject6(14, -1); object selectedFace15 = (object)selectionMgr.GetSelectedObject6(15, -1); object selectedFace16 = (object)selectionMgr.GetSelectedObject6(16, -1); object selectedFace17 = (object)selectionMgr.GetSelectedObject6(17, -1); object selectedFace18 = (object)selectionMgr.GetSelectedObject6(18, -1); object selectedFace19 = (object)selectionMgr.GetSelectedObject6(19, -1); object selectedFace20 = (object)selectionMgr.GetSelectedObject6(20, -1); object selectedFace21 = (object)selectionMgr.GetSelectedObject6(21, -1); object selectedFace22 = (object)selectionMgr.GetSelectedObject6(22, -1); object selectedFace23 = (object)selectionMgr.GetSelectedObject6(23, -1); object[] fixedpart = { selectedFace1, selectedFace2, selectedFace3, selectedFace4, selectedFace5, selectedFace6, selectedFace7, selectedFace8, selectedFace9, selectedFace10, selectedFace11, selectedFace12, selectedFace13, selectedFace14, selectedFace15, selectedFace16, selectedFace17, selectedFace18, selectedFace19, selectedFace20,selectedFace21, selectedFace22, selectedFace23 }; CWConv = LBCMgr.AddConvection(fixedpart, out errCode); if (errCode != 0) { MessageBox.Show("Failed to add convection coefficient indicator"); } } CWConv.ConvectionBeginEdit(); CWConv.Unit = 0; CWConv.ConvectionCoefficient = conv; CWConv.BulkAmbientTemperature = bulk; errCode = CWConv.ConvectionEndEdit(); if (errCode != 0) { MessageBox.Show("Failed to edit convection coefficient indicator"); } swDoc.ClearSelection2(true); // stalks coordinates isSelected = swDoc.Extension.SelectByRay(-0.42931488722807265, -0.050999999999987722, 0.28597685484736474, 0, 1, 0, 0.0047546274155552031, 2, false, 0, 0); if (isSelected) { Entity swEntity = selectionMgr.GetSelectedObject6(1, -1); Component2 swComp = (Component2)swEntity.GetComponent(); object[] fixedpart = { swComp }; CWHeatPower = LBCMgr.AddHeatPower(fixedpart, out errCode); if (errCode != 0) { MessageBox.Show("Failed to add thermal power indicator"); } } CWHeatPower.HeatPowerBeginEdit(); CWHeatPower.Unit = 0; CWHeatPower.HPValue = heatpow; CWHeatPower.ReverseDirection = 0; CWHeatPower.IncludeThermostat = 0; errCode = CWHeatPower.HeatPowerEndEdit(); if (errCode != 0) { MessageBox.Show("Failed to edit thermal power indicator"); } swDoc.ShowNamedView2("*Isometric", 7); swDoc.ViewZoomtofit2(); // creating mesh model CwMesh = Study.Mesh; if (CwMesh == null) { MessageBox.Show("No mesh model"); } CwMesh.Quality = 1; CwMesh.GetDefaultElementSizeAndTolerance(0, out el, out tl); errCode = Study.CreateMesh(0, el, tl); if (errCode != 0) { MessageBox.Show("Failed to create mesh model"); } // analysis start errCode = Study.RunAnalysis(); if (errCode != 0) { MessageBox.Show("Failed to start analysi: " + errCode); } CWResult = Study.Results; if (CWResult == null) { MessageBox.Show("No results"); } else { MessageBox.Show("Done", "Results"); button1.Enabled = true; button1.Text = "Thermal analysis"; } double[] max = new double[time / step]; double[] min = new double[time / step]; double[] avg = new double[4]; for (int i = 1; i <= time / step; i++) { CWPlot plot = CWResult.GetPlot("Thermal" + i.ToString(), out errCode); plot.SetComponentUnitAndValueByElem(0, 2, false); object[] results = null; results = (object[])plot.GetMinMaxResultValues(out errCode); max[i - 1] = Convert.ToDouble(results[3].ToString()); min[i - 1] = Convert.ToDouble(results[1].ToString()); if (i == 1) { avg[0] = Convert.ToDouble(results[1].ToString()); avg[1] = Convert.ToDouble(results[3].ToString()); } if (i == time / step) { avg[2] = Convert.ToDouble(results[1].ToString()); avg[3] = Convert.ToDouble(results[3].ToString()); } } double maxValue = max.Max(); double minValue = min.Min(); textBox9.Text = maxValue.ToString("#.##"); textBox10.Text = minValue.ToString("#.##"); double heatdens = Math.Abs(conv * (((initt2 + initt3) / 2) - (initt3 - (maxValue - minValue)))); textBox12.Text = heatdens.ToString("#.##"); double avg1 = (avg[0] + avg[1]) / 2; double avg2 = (avg[2] + avg[3]) / 2; double avgr = avg1 - avg2; textBox15.Text = avgr.ToString("#.##"); }
private void OpenAssemblyButtonClick(object sender, EventArgs e) { // display an open file dialog where user can select an assembly file OpenFileDialog openAssemblyFileDialog = new OpenFileDialog { InitialDirectory = "E:\\Files\\KPI\\macro", Filter = "SolidWorks2014 assembly files|*.sldasm", Title = "Select a SolidWorks Assembly File" }; // show the dialog // if the user clicked OK in the dialog and // a file was selected, get name of the file if (openAssemblyFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // get name of the assembly file string fileName = openAssemblyFileDialog.FileName; // start solidworks swApp = new SldWorks { Visible = this.swVisible.Checked }; // open assembly file swDoc = OpenAssembly(fileName); // activate opened document swApp.ActivateDoc2("sborka", false, 0); // get active document swDoc = (ModelDoc2)swApp.ActiveDoc; // get assembly object swAsm = (AssemblyDoc)swDoc; // get first feature in the doc feature = swDoc.FirstFeature(); List <string> featureNames = new List <string>(); while (feature != null) { featureNames.Add("Feature: " + feature.GetTypeName2()); if (feature.GetTypeName2() == "MateGroup") { // get first sub feature in the mate group subFeature = feature.GetFirstSubFeature(); // for all sub features get all dimesions while (subFeature != null) { featureNames.Add("-> SubFeature: " + subFeature.GetTypeName2()); displayDimension = subFeature.GetFirstDisplayDimension(); // for all display dimensions show their dimension while (displayDimension != null) { dimension = displayDimension.GetDimension2(0); displayDimension = subFeature.GetNextDisplayDimension(displayDimension); } subFeature = subFeature.GetNextSubFeature(); } } else { subFeature = feature.GetFirstSubFeature(); while (subFeature != null) { featureNames.Add("-> SubFeature: " + subFeature.GetTypeName2()); subFeature = subFeature.GetNextSubFeature(); } } feature = feature.GetNextFeature(); } this.textBox.AppendText("\n====== Start ======\n"); this.textBox.AppendText("File path: " + fileName + "\n"); this.textBox.AppendText(String.Join("\n", featureNames)); this.textBox.AppendText("\n====== End ======\n"); } swApp.ExitApp(); }
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; studyName = nameTextBox.Text; if (string.IsNullOrWhiteSpace(studyName)) { studyName = "Freq_Cantilever"; } analysisLabel.Invoke((MethodInvoker) delegate { analysisLabel.Visible = true; }); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Disposing of SW processes..."; }); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Visible = true; }); // manual cancelling of the analysis if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } DisposeSW(); resGrid.Invoke((MethodInvoker) delegate { resGrid.Rows.Clear(); resGrid.Refresh(); }); if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(5); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Launching SW..."; }); object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(Guid1)); swApp = (SldWorks)processSW; swApp.Visible = true; if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Loading Simulation library..."; }); // connecting Simulation to SW cwpath = swApp.GetExecutablePath() + @"\Simulation\cosworks.dll"; errCode = swApp.LoadAddIn(cwpath); if (errCode != 0 && errCode != 2) { MessageBox.Show("Failed to load Simulation library"); swApp.ExitApp(); DisposeSW(); Application.Exit(); } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Creating cantilever..."; }); // opening cantilever model Part = swApp.OpenDoc6("G:\\Cantilever.SLDPRT", 1, 0, "", ref longstatus, ref longwarnings); if (Part == null) { MessageBox.Show("Failed to load cantilever model"); swApp.ExitApp(); Dispose(); Application.Exit(); } swDoc = swApp.IActiveDoc2; swDoc.ShowNamedView2("*Isometric", 7); swDoc.ViewZoomtofit2(); if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(10); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Check for Simulation readiness..."; }); // ready-check Simulation add-on CWAddinCallBack = (CwAddincallback)swApp.GetAddInObject("CosmosWorks.CosmosWorks"); if (CWAddinCallBack == null) { MessageBox.Show("Failed to open Simulation"); Application.Exit(); } // ready-check add-on object COSMOSWORKS = CWAddinCallBack.CosmosWorks; if (COSMOSWORKS == null) { MessageBox.Show("Failed to create CosmosWorks object"); Application.Exit(); } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(14); // connecting add-on to the document ActDoc = COSMOSWORKS.ActiveDoc; if (ActDoc == null) { MessageBox.Show("Failed to load document"); Application.Exit(); } bwStudy.ReportProgress(16); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Setting up an analysis..."; }); // creating a frequency analysis StudyMngr = ActDoc.StudyManager; if (StudyMngr == null) { MessageBox.Show("Failed to load analysis manager"); Application.Exit(); } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(18); // analysis creation Study = StudyMngr.CreateNewStudy3(studyName, (int)swsAnalysisStudyType_e.swsAnalysisStudyTypeFrequency, (int)swsMeshType_e.swsMeshTypeSolid, out errCode); if (Study == null) { MessageBox.Show("Failed to create a frequency analysis"); Application.Exit(); } // analysis settings CWOptions = Study.FrequencyStudyOptions; // finite element method solver // 1 - Automatic Solver Selection, 0 - Direct sparse solver, 2 - FFEPlus, 7 - Intel Direct Sparse Study.FrequencyStudyOptions.SolverType = SolverDict[solverIndex]; Study.FrequencyStudyOptions.NoOfFrequencies = freqNumber; if (CWOptions == null) { MessageBox.Show("No analysis settings"); } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(20); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Setting cantilever material..."; }); // using silicon as the material (don't know why) string matLib = swApp.GetExecutablePath() + @"\lang\english\sldmaterials\solidworks materials.sldmat"; SolidMgr = (CWSolidManager)Study.SolidManager; SolidComp = SolidMgr.GetComponentAt(0, out errCode); if (errCode == 0) { SolidBody = (CWSolidBody)SolidComp.GetSolidBodyAt(0, out errCode); errCode = (int)SolidBody.SetLibraryMaterial(matLib, "Silicon"); } else { MessageBox.Show("Failed to apply material"); Application.Exit(); } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Adding restraints..."; }); // loading loads and restraints manager LBCMgr = Study.LoadsAndRestraintsManager; if (LBCMgr == null) { MessageBox.Show("Failed to load loads and restraints manager"); Application.Exit(); } bwStudy.ReportProgress(25); // face selection followed by applying restraints ISelectionMgr selectionMgr = (ISelectionMgr)swDoc.SelectionManager; bool isSelected = swDoc.Extension.SelectByRay(0.018229940747914952, 0.051969523507693793, 0.0020000000000095497, -0.57738154519998097, -0.5772877120855483, -0.57738154519997897, 0.00085899699451767535, 2, false, 0, 0); if (isSelected) { object face_bind = selectionMgr.GetSelectedObject6(1, -1); object[] fixedpart = { face_bind }; CWBind = (CWRestraint)LBCMgr.AddRestraint(0, (fixedpart), null, out errCode); if (errCode != 0) { MessageBox.Show("Failed to add restraints"); Application.Exit(); } } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(35); swDoc.ClearSelection2(true); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Creating mesh object..."; }); swDoc.ClearSelection2(true); // mesh object options CWMesh = ((CWMesh)(Study.Mesh)); CWMesh.Quality = 1; CWMesh.UseJacobianCheckForSolids = 1; CWMesh.MesherType = 0; CWMesh.AutomaticTransition = 0; CWMesh.AutomaticLooping = 0; CWMesh.NumberOfLoops = 3; CWMesh.SaveSettingsWithoutMeshing = 0; CWMesh.Unit = 0; if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(50); // create mesh object errCode = Study.CreateMesh(0, 13.3821, 0.669103); if (errCode != 0) { MessageBox.Show("Failed to create mesh object"); Application.Exit(); } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysing..."; }); // start of analysis errCode = Study.RunAnalysis(); if (errCode != 0) { MessageBox.Show("Failed to start analysis"); Application.Exit(); } if (bwStudy.CancellationPending == true) { processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Analysis has been stopped by user"; startBtn.Text = "Start analysis"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); e.Cancel = true; return; } bwStudy.ReportProgress(90); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Receiving results of analysis..."; }); // getting results CWResult = (CWResults)Study.Results; if (CWResult == null) { MessageBox.Show("Failed to receive results of analysis"); return; } double[] res = new double[10]; // getting results from the graph for (int i = 0; i < freqNumber; i++) { plot = CWResult.GetPlot("Amplitude" + (i + 1).ToString(), out errCode); if (plot == null) { MessageBox.Show("Failed to load an information from the graph"); return; } plot.SetComponentUnitAndValueByElem(9, 3, false); results = (object[])plot.GetMinMaxResultValues(out errCode); res[i] = Convert.ToDouble(results[3].ToString()); } for (int k = 0; k < freqNumber; k++) { resGrid.Invoke((MethodInvoker) delegate { int n = resGrid.Rows.Add(); resGrid.Rows[n].Cells[0].Value = k + 1; resGrid.Rows[n].Cells[1].Value = res[k]; }); } bwStudy.ReportProgress(100); processNameLabel.Invoke((MethodInvoker) delegate { processNameLabel.Text = "Done"; }); processNameLabel.Invoke((MethodInvoker) delegate { startBtn.Text = "Review results"; solverComboBox.Enabled = true; freqComboBox.Enabled = true; }); }
private void Window_Closed(object sender, EventArgs e) { swApp.ExitApp(); }
static void Main(string[] args) { Console.WriteLine("Starting.."); var swApp = new SldWorks(); var swAPIWarnings = 0; var swAPIErrors = 0; var importData = (ImportStepData)swApp.GetImportFileData(args[0]); var swActiveDoc = (ModelDoc2)swApp.LoadFile4(args[0], "r", importData, swAPIErrors); if (swActiveDoc == null) { Console.WriteLine("swActiveDoc nullo " + swAPIWarnings + " " + swAPIErrors); return; } var swAssemblyDoc = (AssemblyDoc)swActiveDoc; var SwConfiguration = swActiveDoc.GetActiveConfiguration(); var rootComponent = (Component2)SwConfiguration.GetRootComponent(); var fileName = rootComponent.Name2; //Console.WriteLine("Model " + fileName + " loaded correctly"); var transforation = (Array)AssemblyTraverse.KL_GetTransformsOfAssemblyComponents(rootComponent, swApp); const string fatherName = KLgraph.RootLabel; var pathComponent = rootComponent.Name2; var componentName = pathComponent.Split('/').Last(); var componentPath = rootComponent.GetPathName(); var id = rootComponent.GetHashCode(); var childrenNumber = rootComponent.IGetChildrenCount(); var shape = AssemblyTraverse.KL_GetShapeAssembly(rootComponent, swApp); var statistic = AssemblyTraverse.KL_GetStatisticAssembly(rootComponent, swApp); var nodeAssembly = new KLgraph.KLnodeAssembly(id, transforation, fatherName, -1, rootComponent, pathComponent, componentName, componentPath, -1, childrenNumber, statistic, shape); //Console.WriteLine("Creato il nodo assemblato"); var vertexList = new List <KLgraph.KLnode>(); var edgeList = new List <KLgraph.KLedge>(); vertexList.Add(nodeAssembly); var listOfMyListOfInstances = new List <MyListOfInstances>(); AssemblyTraverse.KL_GetGraphOfAssemblyComponents(rootComponent, nodeAssembly, ref vertexList, edgeList, ref listOfMyListOfInstances, swApp); var partList = new List <KLgraph.KLnode>(vertexList); partList.RemoveAll(v => v.GetType() != typeof(KLgraph.KLnodePart)); nodeAssembly.KLstatistic.PrincipalPartNumber = partList.Count(); nodeAssembly.Instances.AddRange(listOfMyListOfInstances); List <MyPatternOfComponents> listPattern; List <MyPatternOfComponents> listPattern2; PatternComputationFunctions.GetAssemblyPatternsOfRepeatedElements(listOfMyListOfInstances, nodeAssembly, out listPattern, out listPattern2); //Console.WriteLine("Istanze trovate " + listOfMyListOfInstances.Count); //foreach (var inst in listOfMyListOfInstances) //{ // Console.WriteLine("Istanza di " + inst.Name + " trovata " + inst.ListOfMyComponent.Count + " volte"); //} //Console.WriteLine("Pattern trovati " + listPattern.Count); //foreach (var patt in listPattern) //{ // Console.WriteLine("Pattern di " + patt.listOfMyRCOfMyPattern.First().Name); //} //Console.WriteLine("Ending.. nodi " + graph.VertexCount + " e archi " + graph.EdgeCount); //var fileName = Path.GetFileNameWithoutExtension(args[0]); //var storageGraph = new KLgraph.Graph(graph.Vertices.ToList(), graph.Edges.ToList()); var storageGraph = new List <List <MyPatternOfComponents> >(); storageGraph.Add(listPattern2); storageGraph.Add(listPattern); JsonSerializerSettings setting = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat = FormatterAssemblyStyle.Full }; var directoryOutput = Path.GetDirectoryName(args[1]); var fileNameOutput = Path.GetFileNameWithoutExtension(args[1]); //Console.WriteLine(directoryOutput); //Console.WriteLine(fileNameOutput); SaveModel(JsonConvert.SerializeObject(storageGraph, setting), directoryOutput, fileNameOutput + ".json"); Console.WriteLine("JSON saved!"); swApp.ExitApp(); }
public static List <Comp> GetColl(AssemblyDoc swAssy, SldWorks swApp) { Comp component; List <Comp> coll; object[] comps; Component2 comp; ModelDoc2 compDoc, swModel; CustomPropertyManager prpMgr; ModelDocExtension swModelDocExt; swDocumentTypes_e docType = swDocumentTypes_e.swDocPART; ConfigurationManager confManager; string configuration; double[] aTrans; string path; coll = new List <Comp>(); swAssy.ResolveAllLightWeightComponents(false); comps = (object[])swAssy.GetComponents(true); for (int i = 0; i < comps.Length; i++) { component = new Comp(); swModel = (ModelDoc2)swAssy; swModelDocExt = swModel.Extension; confManager = (ConfigurationManager)swModel.ConfigurationManager; configuration = confManager.ActiveConfiguration.Name; prpMgr = swModelDocExt.get_CustomPropertyManager(configuration); prpMgr.Get4("Обозначение", true, out string valOut, out _); component.used = valOut; comp = (Component2)comps[i]; path = comp.GetPathName(); if ((comp.GetSuppression() != (int)swComponentSuppressionState_e.swComponentSuppressed) & (comps[i] != null)) { aTrans = (double[])comp.Transform2.ArrayData; if (path.ToUpper().EndsWith(".SLDASM")) { docType = (swDocumentTypes_e)swDocumentTypes_e.swDocASSEMBLY; } if (path.ToUpper().EndsWith(".SLDPRT")) { docType = (swDocumentTypes_e)swDocumentTypes_e.swDocPART; } int errs = 0, wrns = 0; compDoc = swApp.OpenDoc6(path, (int)docType, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errs, ref wrns); if (compDoc == null) { compDoc = (ModelDoc2)comp.GetModelDoc2(); } if (compDoc == null) { swApp.SendMsgToUser2("Не могу загрузить " + path, 4, 2); swApp.ExitApp(); System.Environment.Exit(0); } configuration = (string)comp.ReferencedConfiguration; swModelDocExt = (ModelDocExtension)compDoc.Extension; prpMgr = (CustomPropertyManager)swModelDocExt.get_CustomPropertyManager(configuration); prpMgr.Get4("Формат", true, out valOut, out _); component.format = valOut; prpMgr.Get4("Обозначение", true, out valOut, out _); component.designation = valOut; prpMgr.Get4("Наименование", true, out valOut, out _); component.name = valOut; prpMgr.Get4("Примечание", true, out valOut, out _); component.note = valOut; prpMgr.Get4("Раздел", true, out valOut, out _); component.chapter = valOut; prpMgr.Get4("Перв.Примен.", true, out valOut, out _); component.included = valOut; if ((component.chapter == "Стандартные изделия") | (component.chapter == "Прочие изделия")) { prpMgr.Get4("Документ на поставку", true, out valOut, out _); component.doc = valOut; component.type = component.name.Substring(0, component.name.IndexOf((char)32)); } component.x = Math.Round((aTrans[9] * 1000), 2); component.y = Math.Round((aTrans[10] * 1000), 2); component.z = Math.Round((aTrans[11] * 1000), 2); component.rotation = Euler(aTrans); component.quantity = 1; coll.Add(component); } } foreach (Comp k in coll) { if (k.chapter != "Сборочные единицы" & k.chapter != "Детали" & k.chapter != "Документация" & k.chapter != "Комплекты") { k.format = ""; } if (k.chapter != "Сборочные единицы" & k.chapter != "Детали" & k.chapter != "Документация" & k.chapter != "Комплекты" & k.chapter != "Стандартные изделия") { k.designation = ""; } if (k.format.Contains("*)")) { k.note = k.format.Substring(2); k.format = "*)"; } } return(coll); }
//Microsoft.Office.Interop.MSProject //string[] args static void CreateSketch() { SldWorks swApp = new SldWorks(); //Feature myFeature; ModelDoc2 swModel = default(ModelDoc2); //RefPlane myRefPlane; SketchManager swSkMgr = default(SketchManager); FeatureManager swFeMgr = default(FeatureManager); //Feature swFeat; //Sketch swSketch; int longstatus = 0; bool boolstatus = false; swApp.ResetUntitledCount(0, 0, 0); swModel = (ModelDoc2)swApp.NewDocument("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\PartTemplate.SLDPRT", 0, 0, 0); swApp.ActivateDoc2("Part1", false, ref longstatus); swModel = (ModelDoc2)swApp.ActiveDoc; swSkMgr = swModel.SketchManager; swFeMgr = swModel.FeatureManager; swSkMgr.InsertSketch(true); //swFeMgr.FeatureExtruRefSurface() boolstatus = swModel.Extension.SelectByID2("Top Plane", "PLANE", -0.0553489443349025, 0.00330468607538553, 0.0269617286188933, false, 0, null, 0); swModel.ClearSelection2(true); if (swModel == null) { swApp.SendMsgToUser2("Ridi.", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk); return; } int modelType = 0; modelType = swModel.GetType(); if (modelType != (int)swDocumentTypes_e.swDocPART) { swApp.SendMsgToUser2("A part document must be active.", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk); return; } // Creating sample point SketchPoint skPoint = default(SketchPoint); skPoint = swSkMgr.CreatePoint(-100, 100, 0); // Creating sample arc SketchSegment skArc = default(SketchSegment); skArc = swSkMgr.Create3PointArc(0, 0, 0, 10, 10, 0, -10, 10, 0); // Creating sample circle SketchSegment skCircle = default(SketchSegment); skCircle = swSkMgr.CreateCircleByRadius(-20, 20, 0, 7.5); swSkMgr.InsertSketch(true); //swModel.SketchCircle(); Console.WriteLine(swApp.Visible.ToString()); Console.WriteLine(swApp.FrameWidth.ToString()); //swApp.CreateNewWindow(); swModel.SaveAs("C:\\Users\\nemati\\Documents\\Visual Studio 2015\\Projects\\SWBlankApp\\SWBlankApp\\SketchArc.SLDPRT"); //swApp. swApp.ExitApp(); //swApp = null; //swApp }
public void OpenDoc(int idPdm, int revision, int taskType, string filePath, string fileName) { swApp = new SldWorks() {Visible = true}; Process[] processes = Process.GetProcessesByName("SLDWORKS"); var errors = 0; var warnings = 0; #region Case switch (taskType) { case 1: Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("Выполняется: {0}\r\n", filePath)))); swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocPART, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); swModel = swApp.ActiveDoc; if (!IsSheetMetalPart((IPartDoc) swModel)) { Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.DarkBlue)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("Не листовой металл!\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("--------------------------------------------------------------------------------------------------------------\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n"))); swApp.CloseDoc(filePath); swApp.ExitApp(); swApp = null; foreach (Process process in processes) { process.CloseMainWindow(); process.Kill(); } return; } swExtension = (ModelDocExtension) swModel.Extension; swModel.EditRebuild3(); swModel.ForceRebuild3(false); CreateFlattPatternUpdate(); object[] confArray = swModel.GetConfigurationNames(); foreach (var confName in confArray) { Configuration swConf = swModel.GetConfigurationByName(confName.ToString()); if (swConf.IsDerived()) continue; Area(confName.ToString()); GabaritsForPaintingCamera(confName.ToString()); } ExportDataToXmlSql(fileName, idPdm, revision); ConvertToErpt(filePath); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("{0} - Выполнен!\r\n", filePath)))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("-----------------------------------------------------------------\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n"))); break; case 2: swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocDRAWING, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); //if (warnings == (int)swFileLoadWarning_e.swFileLoadWarning_ReadOnly) //{MessageBox.Show("This file is read-only.");} swDraw = (DrawingDoc) swModel; swExtension = (ModelDocExtension) swModel.Extension; ConvertToPdf(filePath); break; case 3: //swModel = swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); MessageBox.Show("3"); break; } //TODO: swApp exit swApp.CloseDoc(filePath); swApp.ExitApp(); swApp = null; foreach (Process process in processes) { process.CloseMainWindow(); process.Kill(); } #endregion }
public override void closeInstance() { m_partInstance.Quit(); m_solidworksInstance.ExitApp(); }