选择多个面创建BOX

    //設定選取過濾條件為只允許sheet body跟face
    private int init_proc(IntPtr select, IntPtr user_data)
    {
        UFUi.Mask[] masks = {
            new UFUi.Mask {object_type = UFConstants.UF_solid_type, object_subtype = 0, solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_SHEET},
            new UFUi.Mask {object_type = UFConstants.UF_solid_type, object_subtype = 0, solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE}
        };

        try
        {
            theUfSession.Ui.SetSelMask(select, UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, 2, masks);
            return UFConstants.UF_UI_SEL_SUCCESS;
        }
        catch
        {
            return UFConstants.UF_UI_SEL_FAILURE;
        }

    }

    //選擇多個sheet body或是face
    private int SelectSheetsOrFaces(string prompt, out Tag[] objects)
    {
        int resp;
        int count = 0;
        double[] cursor = new double[3];
        objects = null;

        //選取多個物件
        theUfSession.Ui.SelectWithClassDialog ("Select faces or sheets", prompt, UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY,
            init_proc, IntPtr.Zero, out resp, out count, out objects);

        if (resp == UFConstants.UF_UI_BACK || resp == UFConstants.UF_UI_CANCEL)
            return 0;

        for (int i = 0; i < count; i++)
            theUfSession.Disp.SetHighlight (objects[i], 0);

        return count;
    }

    //使用原點及邊長的方式建立方塊
    public Block CreateBlock(double[] origin, string[] lengths)
    {
        Part workPart = theSession.Parts.Work;
        BlockFeatureBuilder blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(null);
        blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;
        blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;

        //根據錄製的Journal內容完成blockFeatureBuilder1的設定
        //your code here
        NXOpen.Point3d originPt = new NXOpen.Point3d(origin[0],origin[1],origin[2]);
        blockFeatureBuilder1.SetOriginAndLengths(originPt,lengths[0],lengths[1],lengths[2]);

        Block feature1 = (Block)blockFeatureBuilder1.CommitFeature();
        blockFeatureBuilder1.Destroy();

        return feature1;
    }

    private Body [] CreateWrapBlock(Tag[] objects)
    {
        Body [] result = null;
        double[] min = {Double.MaxValue, 99999999, 99999999};
        double[] max = {-99999999, -99999999, -99999999};
        

        //依序計算每個物件的最小方盒, 並計算總體的最小方盒 (UF_MODL)
        for (int i = 0; i < objects.Length; i++)
        {
            double[] bbox = new double[6];
            theUfSession.Modl.AskBoundingBox(objects[i], bbox ); 
            min[0] = (min[0] < bbox[0]) ? min[0] : bbox[0];
            min[1] = (min[1] < bbox[1]) ? min[1] : bbox[1];
            min[2] = (min[2] < bbox[2]) ? min[2] : bbox[2];
            max[0] = (max[0] > bbox[3]) ? max[0] : bbox[3];
            max[1] = (max[1] > bbox[4]) ? max[1] : bbox[4];
            max[2] = (max[2] > bbox[5]) ? max[2] : bbox[5];
        }

        //取得最小方盒三個方向長度的字串表示
        string xLen = (max[0] - min[0]).ToString();
        string yLen = (max[1] - min[1]).ToString();
        string zLen = (max[2] - min[2]).ToString();
	    string[] edgeLen = {xLen, yLen, zLen};

        //建立block特徵
        Block block = CreateBlock(min, edgeLen);
        if (block != null)
        {
            //取得block特徵底下的body
            result = block.GetBodies();
        }

        return result;
    }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值