手工执行的话一般如此操作,例如分离零件等操作
今天利用c# 介绍下AM如何用代码执行提取零件gen文件的过程
引用如下的库文件
封装的类库
其中appname/shortname/appExecutable这些去下面的文件去查找
C:\AVEVA\Marine\OH12.1.SP4\MarJobs.xml
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();
}
}
标签:MarJobLauncher,C#,Aveva,mj,MDB,File,var,new,程序执行 From: https://www.cnblogs.com/NanShengBlogs/p/18169353