装配焊接工序模型创建wave关系的函数

//针对子节点为装配的工序模型,首先将子组件的几何实体几何链接到装配工序上
        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;
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bryan Ding

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值