123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using static CollaborativePlatformMain.CADStartUtil.AcadDirs;
- namespace CollaborativePlatformMain.CADStartUtil
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class StartCADUtil
- {
- public static void StartCADMath(bool isFloor = true, OpenDrawPathData openDrawPathData = null)
- {
- try
- {
-
- AcadDirs regedits = new AcadDirs();
-
- if (regedits.Dirs.Count == 0)
- {
- MessageBox.Show(DateTime.Now + "当前电脑未安装 AutoCAD ");
- return;
- }
-
- List<AcadProductKey> cadPathpks = regedits.Dirs.Where(x => x.ProductName.Equals("AutoCAD 2019 - 简体中文 (Simplified Chinese)")).ToList();
- if (cadPathpks.Count == 0)
- {
- Console.WriteLine(DateTime.Now + "当前电脑未安装 AutoCAD 2019 - 简体中文 (Simplified Chinese)");
- Console.ReadLine();
- return;
- }
- var pros = Process.GetProcessesByName("acad");
- if (pros.Length != 0)
- {
-
- if (isFloor)
- {
- TwoOpenCADConfigUtil twoOpenCADConfigUtil = new TwoOpenCADConfigUtil();
- twoOpenCADConfigUtil.Save(new TwoOpenData(true), @"D:\DFBIM\CMTwoOpenFloor.config");
- }
- else
- {
- OpenDrawConfigUtil openDrawConfigUtil = new OpenDrawConfigUtil();
- openDrawConfigUtil.Save(openDrawPathData, @"D:\DFBIM\OpenDrawPathData.config");
- }
- }
- else
- {
- string location = cadPathpks[0].Location;
-
- string scriptFile = location + "\\autocad_script.scr";
- if (isFloor) File.WriteAllText(scriptFile, "CMOPENCADFLOOR\n");
- else
- {
- OpenDrawConfigUtil openDrawConfigUtil = new OpenDrawConfigUtil();
- openDrawConfigUtil.Save(openDrawPathData, @"D:\DFBIM\OpenDrawPathData.config");
- File.WriteAllText(scriptFile, "CMOPENCADDRAW\n");
- }
-
- ProcessStartInfo startInfo = new ProcessStartInfo
- {
- FileName = location + "\\acad.exe",
- Arguments = $"/b \"{scriptFile}\"",
- UseShellExecute = false,
- RedirectStandardError = true,
- RedirectStandardInput = true,
- RedirectStandardOutput = true,
- CreateNoWindow = true
- };
-
- using (Process autocadProcess = new Process())
- {
- autocadProcess.StartInfo = startInfo;
- autocadProcess.Start();
-
- autocadProcess.WaitForInputIdle();
-
-
- }
- }
- }
- catch (Exception)
- {
- return;
- }
- }
-
-
-
- private static void KillProcess(int currentProcessId = -1)
- {
- if (currentProcessId == -1) currentProcessId = Process.GetCurrentProcess().Id;
- Process cadProcess = Process.GetProcessById(currentProcessId);
- if (!cadProcess.HasExited)
- {
- cadProcess.Kill();
-
- }
- else
- {
-
- }
-
- Process[] processes = Process.GetProcessesByName("WSCommCntr4");
- if (processes.Length != 0)
- {
- processes[0].Kill();
-
- }
- }
- }
- }
|