Example #1
0
    private void CreateExtrude(IBaseCurve[] curves, bool add, double distance, Vector3d vector)
    {
        SelectionIntentRule[] rules = new SelectionIntentRule[1]
        {
            workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves)
        };

        NXOpen.Features.ExtrudeBuilder extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(null);
        NXOpen.Section section1 = workPart.Sections.CreateSection(0.0095, 0.01, 0.5);
        section1.AddToSection(rules, (Curve)curves[0], null, null, new Point3d(0, 0, 0), Section.Mode.Create, false);
        extrudeBuilder1.Section = section1;

        if (add)
        {
            extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;
        }
        else
        {
            extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Subtract;

            extrudeBuilder1.BooleanOperation.SetTargetBodies(new Body[1] {
                workPart.Bodies.ToArray()[0]
            });
        }
        distance = distance / 2.0;
        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "-" + distance.ToString();
        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide   = distance.ToString();

        NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0, 0);
        extrudeBuilder1.Direction = workPart.Directions.CreateDirection(origin1, vector, NXOpen.SmartObject.UpdateOption.WithinModeling);

        extrudeBuilder1.CommitFeature();

        extrudeBuilder1.Destroy();
    }
Example #2
0
        /// <summary>
        /// 创建拉伸特征
        /// </summary>
        /// <param name="vec">向量</param>
        /// <param name="start">起始</param>
        /// <param name="end">终止</param>
        /// <param name="extrude">lastez</param>
        /// <param name="line">线</param>
        /// <returns></returns>
        public static NXOpen.Features.Feature CreateExtrude(Vector3d vec, string start, string end, NXOpen.Features.Feature extrude = null, params TaggedObject[] line)
        {
            Session theSession         = Session.GetSession();
            Part    workPart           = theSession.Parts.Work;
            SelectionRuleFactory rules = new SelectionRuleFactory(line.ToList());

            NXOpen.Features.Feature        nullNXOpen_Features_Feature = null;
            NXOpen.Features.ExtrudeBuilder extrudeBuilder1             = workPart.Features.CreateExtrudeBuilder(nullNXOpen_Features_Feature);
            NXOpen.Section section1 = workPart.Sections.CreateSection();
            extrudeBuilder1.Section = section1;
            extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = start;
            extrudeBuilder1.Limits.EndExtend.Value.RightHandSide   = end;

            NXOpen.Point3d   origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            NXOpen.Direction direction1;
            direction1 = workPart.Directions.CreateDirection(origin1, vec, NXOpen.SmartObject.UpdateOption.WithinModeling);


            NXOpen.NXObject nullNXOpen_NXObject = null;

            section1.AddToSection(rules.CreateSelectionRule().ToArray(), (NXObject)line[0], nullNXOpen_NXObject, nullNXOpen_NXObject, origin1, NXOpen.Section.Mode.Create, false);
            extrudeBuilder1.Direction = direction1;
            NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start Extruded");
            try
            {
                return(extrudeBuilder1.CommitFeature());
            }

            catch (NXException ex)
            {
                LogMgr.WriteLog("ExtrudedUtils:CreateExtruded:" + ex.Message);
                throw ex;
            }
            finally
            {
                extrudeBuilder1.Destroy();
                theSession.UpdateManager.DoUpdate(markId);
                theSession.DeleteUndoMark(markId, "End Extruded");
            }
        }