AVEVA MARINE C# 程式執行MarJobLauncher工作

南胜NanSheng發表於2024-05-01

手工執行的話一般如此操作,例如分離零件等操作

AVEVA MARINE C# 程式執行MarJobLauncher工作AVEVA MARINE C# 程式執行MarJobLauncher工作

AVEVA MARINE C# 程式執行MarJobLauncher工作

今天利用c# 介紹下AM如何用程式碼執行提取零件gen檔案的過程

引用如下的庫檔案

AVEVA MARINE C# 程式執行MarJobLauncher工作

封裝的類庫

其中appname/shortname/appExecutable這些去下面的檔案去查詢

C:\AVEVA\Marine\OH12.1.SP4\MarJobs.xml

AVEVA MARINE C# 程式執行MarJobLauncher工作

public static class MarJobEx
 {
     public static string appName = "Hull Plate Interface";

     public static string appShort_name = "tbrplateint";

     /// <summary>
     /// 按照零件名稱提取gen檔案
     /// </summary>
     /// <param name="Plates"></param>
     /// <param name="passWord"></param>
     /// <returns></returns>
     public static List<FileInfo> HullPlatePartsInterFace(this IEnumerable<string> Plates, string passWord)
     {
         //
         MDB.CurrentMDB.GetWork();
         //var job = ExportOutHullMarJobs().First(j => j.executable == HullPlateInterface);
         var pro = Aveva.Pdms.Database.Project.CurrentProject;
         var mdb = Aveva.Pdms.Database.MDB.CurrentMDB;
         MarJob mj = new MarJob()
         {
             Project = pro.Name,
             MDB = mdb.Name,
             User = pro.UserName,
             Password = passWord
         };
         mj.Create(appName);
         Aveva.Marine.Utility.MarUtil util = new Aveva.Marine.Utility.MarUtil();
         var datDir = util.TBEnvironmentGet("SB_SHIPDATA");
         util.Dispose();
         StringBuilder sb = new StringBuilder();
         Plates.ToList().ForEach(c => sb.AppendLine($"PLATE,'{c}';"));
         string cmdstr = sb.ToString();
         var fn = Path.Combine(datDir, $"{appShort_name}_{mj.JobId}.dat");
         File.WriteAllText(fn, cmdstr);
         mj.AddInput(fn);
         mj.Run(false);
         var dats = mj.Outputs.Cast<string>().FirstOrDefault(c => c.EndsWith(".dat"));
         var fls = File.ReadAllLines(dats).Where(c => File.Exists(c));
         return fls.Select(c => new FileInfo(c)).ToList();
     }

     /// <summary>
     /// 按照裝配提取
     /// </summary>
     /// <param name="curAss"></param>
     /// <param name="passWord"></param>
     /// <returns></returns>
     public static List<FileInfo> HullPlatePartsInterFace(this List<DbElement> curAssOrBlockEle, string passWord)
     {
         var strs = curAssOrBlockEle.Select(c=>c.GetAsString(DbAttributeInstance.NAMN));
         MDB.CurrentMDB.GetWork();
         //var job = ExportOutHullMarJobs().First(j => j.executable == HullPlateInterface);
         var pro = Aveva.Pdms.Database.Project.CurrentProject;
         var mdb = Aveva.Pdms.Database.MDB.CurrentMDB;
         MarJob mj = new MarJob()
         {
             Project = pro.Name,
             MDB = mdb.Name,
             User = pro.UserName,
             Password = passWord
         };
         mj.Create(appName);
         Aveva.Marine.Utility.MarUtil util = new Aveva.Marine.Utility.MarUtil();
         var datDir = util.TBEnvironmentGet("SB_SHIPDATA");
         util.Dispose();
         var cmdstrs = curAssOrBlockEle.Select(c=>$"{(c.GetActualType().Name == "ASMBLY" ? "ASSEMBLY" : "BLOCK")},'{c.GetAsString(DbAttributeInstance.NAMN)}';").ToArray();
         var fn = Path.Combine(datDir, $"{appShort_name}_{mj.JobId}.dat");
         File.WriteAllLines(fn, cmdstrs);
         mj.AddInput(fn);
         mj.Run(false);
         var dats=mj.Outputs.Cast<string>().FirstOrDefault(c => c.EndsWith(".dat"));
         var fls = File.ReadAllLines(dats).Where(c => File.Exists(c));
         return fls.Select(c => new FileInfo(c)).ToList();
     }
 }

相關文章