//针对子节点为装配的工序模型,首先将子组件的几何实体几何链接到装配工序上
public static void WavetheChildPart(string assem, string component)
{
try
{
Part displaypart = Program.theSession.Parts.Display;
if (displaypart == null)
{
NXFun.MessageBox("请先打开part");
return;
}
//判断显示部件为转配节点 并加载子节点 获取子节点
List<Tag> List_WaveObjects = new List<Tag>();
Tag parttag = Program.theUfSession.Part.AskDisplayPart();
Tag roottag = Program.theUfSession.Assem.AskRootPartOcc(parttag);
if (roottag == Tag.Null)
{
MessageBox("The Part isnot an Assembly!");
return;
}
NXOpen.Tag[] childrenNum;
int chil = Program.theUfSession.Assem.AskAllPartOccChildren(roottag, out childrenNum);
string[] childrenName = new string[chil];
Part part1 = NXFun.Tag2NXObject<Part>(parttag);
//load all component
string assemId = part1.GetStringAttribute("DB_PART_NO");
string assemVersion = part1.GetStringAttribute("DB_PART_REV");
string assembly = assemId + "/" + assemVersion;
LoadAllComponent(assembly);
//find the bodytype nxobject
for (int i = chil - 1; i >= 0; i--)
{
Tag childrentag = childrenNum[i];
NXOpen.Assemblies.Component part = NXFun.Tag2NXObject<NXOpen.Assemblies.Component>(childrentag);
//判断有无原型:componet 是否一定是一个实例
//Part ptt1 = (Part)part.OwningPart;//指装配总节点
//Part ptt2 = (Part)part.Prototype;
//if (part.IsOccurrence)
//{
// ptt2 = (Part)part.Prototype;
//}
//else
//{
//}
Body[] bb = ((Part)part.Prototype).Bodies.ToArray();
foreach (Body bod in bb)
{
NXObject bod1 = part.FindOccurrence(bod);
if (bod1 != null)
{
List_WaveObjects.Add(bod1.Tag);
}
}
}
//remove the same object
List<Tag> List_NewWaveObjects=RemoveTheSame<Tag>(List_WaveObjects);
//将子节点所有几何体实体wave到父装配节点上
Part childPart = displaypart;
foreach (Tag objtag in List_NewWaveObjects)
{
NXObject obj = NXFun.Tag2NXObject<NXObject>(objtag);
NXFun.CreateWave3(objtag, childPart.Tag, false);
}
//hide all its childcomponent
BlankAllComponent();
}
catch (Exception err)
{
MessageBox(err.ToString());
}
}
//using the method recording the operation in Nx to create body wavelink
public static void CreateWave3(Tag obj, Tag prt, bool update)
{
Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;
NXOpen.Features.Feature nullFeatures_Feature = null;
NXOpen.Features.WaveLinkBuilder waveLinkBuilder1;
waveLinkBuilder1 = workPart.BaseFeatures.CreateWaveLinkBuilder(nullFeatures_Feature);
NXOpen.Features.ExtractFaceBuilder extractFaceBuilder1;
extractFaceBuilder1 = waveLinkBuilder1.ExtractFaceBuilder;
extractFaceBuilder1.FaceOption = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.FaceChain;
waveLinkBuilder1.Type = NXOpen.Features.WaveLinkBuilder.Types.BodyLink;
extractFaceBuilder1.FaceOption = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.FaceChain;
extractFaceBuilder1.AngleTolerance = 45.0;
extractFaceBuilder1.ParentPart = NXOpen.Features.ExtractFaceBuilder.ParentPartType.OtherPart;
extractFaceBuilder1.Associative = true;
extractFaceBuilder1.FixAtCurrentTimestamp = update;//false;
extractFaceBuilder1.HideOriginal = false;
extractFaceBuilder1.InheritDisplayProperties = false;
SelectObjectList selectObjectList1;
selectObjectList1 = extractFaceBuilder1.BodyToExtract;
//NXOpen.Assemblies.Component component1 = (NXOpen.Assemblies.Component) workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT 1 1");
//Body body1 = (Body)component1.FindObject("PROTO#.Bodies|BLOCK(3)");
Body body2 = (Body)Tag2NXObject<NXObject>(obj);
bool added1;
added1 = selectObjectList1.Add(body2);
NXObject nXObject1;
nXObject1 = waveLinkBuilder1.Commit();
waveLinkBuilder1.Destroy();
}
//判断是否为装配节点
public static bool isAssem()
{
Part displaypart = Program.theSession.Parts.Display;
if (displaypart == null)
{
NXFun.MessageBox("请先打开part");
return false;
}
//判断显示部件为转配节点 并加载子节点 获取子节点
List<Tag> List_WaveObjects = new List<Tag>();
Tag parttag = Program.theUfSession.Part.AskDisplayPart();
Tag roottag = Program.theUfSession.Assem.AskRootPartOcc(parttag);
if (roottag == Tag.Null)
{
return false;
}
return true;
}