NX版本:12.0
VS版本:2017
功能:通过二次开发实现快速将一个程序的部件及余量赋给另一个程序。通过Ufun方式进行设置程序部件,以型腔铣程序为例,可自行添加固定轮廓铣等程序。
逻辑:通过两个程序的名称,先获取一个程序部件中的面,余量等设置,依次进行设置到另一个程序中。可通过for循环等实现批量设置等。
主要运用C#语言,本次主要使用UFun类型进行设置,若使用c#类型,需要将每个程序类型单独编写函数,这样可以批量操作,有利于开发人员的开发效率。
public static void Copy_Oper_to_Another_Oper(string Operation_Name1,string Operation_Name2)
{
Operation Original_Operation = theSession.Parts.Work.CAMSetup.CAMOperationCollection.FindObject(Operation_Name1);
Operation New_Operation = theSession.Parts.Work.CAMSetup.CAMOperationCollection.FindObject(Operation_Name2);
theUfSession.Camgeom.AskItems(Original_Operation.Tag,CamGeomType.CamPart,out int Get_Num,out IntPtr[] Array_InPter);
List<Tag> Tag_Get = new List<Tag> { };
List<UFCamgeom.AppData> AppData_Get = new List<UFCamgeom.AppData> { };
if (Get_Num < 0)
{
return;
}
for (int i=0;i<Get_Num;i++)
{
theUfSession.Camgeom.AskItemEntity(Array_InPter[i],out Tag Entity_Get);
theUfSession.Camgeom.AskItemAppData(Array_InPter[i], out UFCamgeom.AppData AppData_Get_in);
theUfSession.Camgeom.AskCollectorItems(Array_InPter[i],out int Counts, out Tag[] Items_Get);
List<Face> Face_All = new List<Face> { };
foreach (Tag tag in Items_Get)
{
//获取部件中的面
Face_All.Add((Face)theSession.GetObjectManager().GetTaggedObject(tag));
}
FaceDumbRule FDR = theSession.Parts.Work.ScRuleFactory.CreateRuleFaceDumb(Face_All.ToArray());
ScCollector SCollector = theSession.Parts.Work.ScCollectors.CreateCollector();
SCollector.ReplaceRules(new SelectionIntentRule[1] { FDR},false);
theUfSession.Obj.AskTypeAndSubtype(Entity_Get,out int Type_Get,out int SubType_Get);
UFCamgeom.AppData AppData_Items_Set = new UFCamgeom.AppData();
if (New_Operation is CavityMilling)
{
//在型腔铣中进行设置 部件 数据,可进行继续添加if添加类型
AppData_Items_Set.has_stock = AppData_Get_in.has_stock;
AppData_Items_Set.stock = AppData_Get_in.stock;
AppData_Items_Set.has_tolerances = AppData_Get_in.has_tolerances;
AppData_Items_Set.tolerances = AppData_Get_in.tolerances;
}
Tag_Get.Add(SCollector.Tag);
AppData_Get.Add(AppData_Items_Set);
}
//最终设置
theUfSession.Camgeom.AppendItems(New_Operation.Tag,CamGeomType.CamPart,Tag_Get.Count,Tag_Get.ToArray(),AppData_Get.ToArray());
}