PCB Genesis或Incam 右键导入TGZ 实现方法

您所在的位置:网站首页 genesis读取资料挂红 PCB Genesis或Incam 右键导入TGZ 实现方法

PCB Genesis或Incam 右键导入TGZ 实现方法

2024-06-19 06:04| 来源: 网络整理| 查看: 265

      使用Genesis导入TGZ方式很多 的,比如有:写个脚本框选TGZ的的方式实现TGZ导入,将TGZ拖入脚本界面实现TGZ导入, 给Engineering Toolkit窗口句柄注册拖拽事件实现TGZ导入, 右键实现TGZ导入等,本篇介绍最后一种右键导入TGZ的方法.

  一.实现效果图

      1.tgz文件右键导入

       

     2.tgz文件夹右键导入

     

 

  二.借助Gateway实现InputTGZ脚本----C#实现代码

        1.C#实现代码部份

using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Serialization; namespace InputTGZ { static class Program { static Process process = new Process(); private static bool isIncam = false; static string db_name = "genesis"; //db名为默认值,满足个性化可以改为配置读取 /// /// 应用程序的主入口点。 /// [STAThread] static void Main(string[] args) { if (args.Length == 1) { try { string file_path = args[0]; string OpenStepName = System.Configuration.ConfigurationManager.AppSettings["OpenStepName"] ?? ""; string StateInfo = getPid(); if (!string.IsNullOrEmpty(StateInfo)) { MessageBox.Show($"{StateInfo}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } List job_list = getJOBlist(); var isDirExists = Directory.Exists(file_path); //导入目录下所有TGZ if (isDirExists) { var tgzFileList = Directory.GetFiles(file_path, "*.tgz"); foreach (var item in tgzFileList) { string job_name1 = Path.GetFileNameWithoutExtension(item).ToLower().Trim(); if (job_list.Any(tt => tt == job_name1)) { COM($"close_job,job={job_name1}"); COM($"close_form,job={job_name1}"); COM($"close_flow,job={job_name1}"); COM($"delete_entity,job=,type=job,name={job_name1}"); } COM($"import_job,db= {db_name},path={item},name ={job_name1}"); } return; } //单个TGZ导入 string job_name = Path.GetFileNameWithoutExtension(file_path).ToLower().Trim(); if (job_list.Any(tt => tt == job_name)) { var isYes = MessageBox.Show($"TGZ名【{job_name}】已存在,请确认是否覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (isYes == DialogResult.No) return; COM($"close_job,job={job_name}"); COM($"close_form,job={job_name}"); COM($"close_flow,job={job_name}"); COM($"delete_entity,job=,type=job,name={job_name}"); } COM($"import_job,db= {db_name},path={file_path},name ={job_name}"); if (!string.IsNullOrEmpty(OpenStepName)) { COM($"open_job,job={job_name}"); COM($"open_entity,job={job_name},type=step,name={OpenStepName}"); } } catch (Exception ex) { MessageBox.Show($"导入TGZ出错了{ex.Message}", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } finally { if (process.StartInfo.FileName.Length > 0) { if (!process.HasExited) process.Kill(); } } } } /// /// 执行COM指令 /// /// /// public static string COM(string command) { process.StandardInput.WriteLine("COM " + command); var STATUS = process.StandardOutput.ReadLine(); process.StandardInput.WriteLine("COMANS"); return process.StandardOutput.ReadLine(); } /// /// 设置genesis或incam PID /// /// public static string getPid() { int gpid = getPIDonly(); if (gpid < 1) return "未打开Genesis或incam"; var gatewayFilePath = ""; if (!isIncam) { gatewayFilePath = System.Environment.GetEnvironmentVariable("GENESIS_EDIR").Replace("/", "\\") + @"\misc\gateway.exe"; } else { gatewayFilePath = @"D:\InCAM\release\bin\gateway.exe"; if (!File.Exists(gatewayFilePath)) gatewayFilePath = @"C:\InCAM\release\bin\gateway.exe"; } process = new Process(); process.StartInfo.FileName = gatewayFilePath; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.Arguments = "%" + gpid.ToString(); process.Start(); return ""; } /// /// 获取的有JOB列表 /// /// public static List getJOBlist() { List job_list = new List(); if (!isIncam) { string path = (System.Environment.GetEnvironmentVariable("GENESIS_DIR").Replace("/", "\\")) + "/share/joblist"; using (StreamReader sr = new StreamReader(path, Encoding.Default)) { while (!sr.EndOfStream) { string strline = sr.ReadLine(); int start = strline.IndexOf("NAME="); if (start != -1) { job_list.Add(strline.Substring(start + 5)); } } } db_name = "genesis"; //默认 } else { string filePath = @"D:\InCAM\server\config\joblist.xml"; if (!File.Exists(filePath)) filePath = @"C:\InCAM\server\config\joblist.xml"; string xml = File.ReadAllText(filePath); xml = "" + xml + ""; using (StringReader sr = new StringReader(xml)) { XmlSerializer xmldes = new XmlSerializer(typeof(RootXml)); job_list = (xmldes.Deserialize(sr) as RootXml).JobList.Select(tt => tt.Name).ToList(); ; } db_name = "db1";//默认 } return job_list; } /// /// 获取唯一PID 仅用单开 /// /// public static int getPIDonly() { Process[] arrayProcess = Process.GetProcesses(); foreach (Process p in arrayProcess) { if (p.ProcessName.ToLower() == "get" || p.ProcessName.ToLower() == "gfx") { return p.Id; } if (p.ProcessName.ToLower() == "incam") { isIncam = true; return p.Id; } } return 0; } } [XmlRoot("RootXml")] public class RootXml { [XmlArray("JobList")] [XmlArrayItem("job")] public List JobList { get; set; } = new List(); } [XmlRootAttribute("job")] public class job { [XmlAttribute("name")] public string Name { get; set; } [XmlAttribute("dbName")] public string dbName { get; set; } } }

   2.app.config 设置打开StepName名

 

 三.注册右键代码

      1.tgz后缀文件名加入右键【导入tgz】

/// /// tgz后缀文件名加入右键[导入tgz] /// static void tgz_SuffixFile() { string FileSuffix = ".tgz"; string FileSuffixName = "tgz"; string menuName = "导入tgz"; //加入TGZ后缀 RegistryKey shell = Registry.ClassesRoot; RegistryKey custom = shell.CreateSubKey(FileSuffix); custom.SetValue("", FileSuffixName); custom.Close(); shell.Close(); //TGZ绑定程序 var FileSuffix2Root = Registry.ClassesRoot.CreateSubKey(FileSuffixName); string OpenFilePath = Application.StartupPath + @"\InputTGZ.exe"; string OpenFilePathIco = Application.StartupPath + @"\InputTGZ.ico"; RegistryKey shell2 = FileSuffix2Root.CreateSubKey("shell"); RegistryKey custom2 = shell2.CreateSubKey(menuName); custom2.SetValue("", menuName ); custom2.SetValue("Icon", OpenFilePathIco); RegistryKey cmd = custom2.CreateSubKey("command"); cmd.SetValue("", OpenFilePath + " %1"); FileSuffix2Root.Close(); cmd.Close(); custom.Close(); shell2.Close(); }

      2.文件夹加入右键【导入tgz文件夹】

/// /// 文件夹加入右键[导入tgz文件夹] /// static void tgz_Dir() { string menuName = "导入tgz文件夹"; string OpenFilePath = Application.StartupPath + @"\InputTGZ.exe"; string OpenFilePathIco = Application.StartupPath + @"\InputTGZ.ico"; RegistryKey shell = Registry.ClassesRoot.OpenSubKey(@"Directory\shell", true); RegistryKey custom = shell.CreateSubKey(menuName); custom.SetValue("", menuName ); custom.SetValue("Icon", OpenFilePathIco); RegistryKey cmd = custom.CreateSubKey("command"); cmd.SetValue("", OpenFilePath + " %1"); cmd.Close(); custom.Close(); shell.Close(); }

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3