示例#1
0
        internal static Snap.NX.ProjectCurve CreateProjectCurve(Snap.NX.Curve[] curves, Snap.NX.Point[] points, Snap.NX.Face face)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.ProjectCurveBuilder featureBuilder = workPart.Features.CreateProjectCurveBuilder(null);
            featureBuilder.CurveFitData.Tolerance = Globals.DistanceTolerance;
            featureBuilder.AngleToProjectionVector.RightHandSide = "0";
            featureBuilder.SectionToProject.DistanceTolerance    = Globals.DistanceTolerance;
            featureBuilder.SectionToProject.ChainingTolerance    = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
            featureBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints);
            featureBuilder.ProjectionDirectionMethod = NXOpen.Features.ProjectCurveBuilder.DirectionType.AlongFaceNormal;
            Snap.NX.Section sectionToProject = featureBuilder.SectionToProject;
            sectionToProject.AddICurve(curves);
            sectionToProject.AddPoints(points);
            ScCollector collector = workPart.ScCollectors.CreateCollector();

            NXOpen.Face[] faces = new NXOpen.Face[] { face };
            FaceDumbRule  rule  = workPart.ScRuleFactory.CreateRuleFaceDumb(faces);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            collector.ReplaceRules(rules, false);
            featureBuilder.FaceToProjectTo.Add(collector);
            NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.SectionToProject.CleanMappingData();
            featureBuilder.Destroy();
            return((NXOpen.Features.ProjectCurve)feature);
        }
示例#2
0
        internal static Snap.NX.SplitBody CreateSplitBody(Snap.NX.Body targetBody, Snap.NX.Face[] toolFaces)
        {
            NXOpen.Part work = Globals.Session.Parts.Work;
            NXOpen.Features.SplitBodyBuilder featureBuilder = work.Features.CreateSplitBodyBuilder(null);
            featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.PrepareMappingData();
            featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = Globals.DistanceTolerance;
            featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
            ScCollector collector = work.ScCollectors.CreateCollector();

            NXOpen.Body[] bodies = new NXOpen.Body[] { targetBody };
            BodyDumbRule  rule   = work.ScRuleFactory.CreateRuleBodyDumb(bodies);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            collector.ReplaceRules(rules, false);
            featureBuilder.TargetBodyCollector = collector;
            SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[toolFaces.Length];
            for (int i = 0; i < toolFaces.Length; i++)
            {
                ruleArray2[i] = work.ScRuleFactory.CreateRuleFaceBody((NXOpen.Body)toolFaces[i].Body);
            }
            featureBuilder.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(ruleArray2, false);
            NXOpen.Features.SplitBody split = (NXOpen.Features.SplitBody)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return(new Snap.NX.SplitBody(split));
        }
示例#3
0
        internal static Snap.NX.Chamfer CreateChamfer(Snap.NX.Edge edge, Snap.Number distance1, Snap.Number distance2, bool offsetFaces)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.ChamferBuilder featureBuilder = workPart.Features.CreateChamferBuilder(null);
            featureBuilder.Option = NXOpen.Features.ChamferBuilder.ChamferOption.TwoOffsets;
            if (offsetFaces)
            {
                featureBuilder.Method = NXOpen.Features.ChamferBuilder.OffsetMethod.FacesAndTrim;
            }
            else
            {
                featureBuilder.Method = NXOpen.Features.ChamferBuilder.OffsetMethod.EdgesAlongFaces;
            }
            featureBuilder.FirstOffset  = distance1.ToString();
            featureBuilder.SecondOffset = distance2.ToString();
            //featureBuilder.Tolerance = Globals.DistanceTolerance;
            ScCollector     collector = workPart.ScCollectors.CreateCollector();
            EdgeTangentRule rule      = workPart.ScRuleFactory.CreateRuleEdgeTangent((NXOpen.Edge)edge, null, false, Globals.AngleTolerance, false, false);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            collector.ReplaceRules(rules, false);
            featureBuilder.SmartCollector = collector;
            NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return((NXOpen.Features.Chamfer)feature);
        }
示例#4
0
        /// <summary>
        /// 获取极限点
        /// </summary>
        /// <param name="measureManager"></param>
        /// <param name="curves">要计算的曲线</param>
        /// <param name="measureDirection">测量方向</param>
        /// <param name="secondDirection">第二方向,以防在第一个方向上出现多个极值点</param>
        /// <param name="thirdDirection">第三方向</param>
        /// <returns>极限点</returns>
        public static Point3d MeasureExtreme(this MeasureManager measureManager, IBaseCurve[] curves, Vector3d measureDirection, Vector3d secondDirection, Vector3d thirdDirection)
        {
            NXOpen.Unit unit1      = WorkPart.UnitCollection.FindObject("MilliMeter");
            Point3d     origin1    = new Point3d(0.0, 0.0, 0.0);
            Direction   direction1 = WorkPart.Directions.CreateDirection(origin1, measureDirection, NXOpen.SmartObject.UpdateOption.WithinModeling);
            Direction   direction2 = WorkPart.Directions.CreateDirection(origin1, secondDirection, NXOpen.SmartObject.UpdateOption.WithinModeling);
            Direction   direction3 = WorkPart.Directions.CreateDirection(origin1, thirdDirection, NXOpen.SmartObject.UpdateOption.WithinModeling);
            ScCollector scCollector1;

            scCollector1 = WorkPart.ScCollectors.CreateCollector();

            CurveDumbRule curveDumbRule1 = WorkPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves);

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1] {
                curveDumbRule1
            };
            scCollector1.ReplaceRules(rules1, false);
            MeasureRectangularExtreme extreme = WorkPart.MeasureManager.NewRectangularExtreme(unit1, direction1, direction2, direction3, scCollector1, false);

            Point3d extremePoint = extreme.Point;

            int nErrs1 = TheSession.UpdateManager.AddToDeleteList(direction1);

            scCollector1.Destroy();

            return(extremePoint);
        }
示例#5
0
        /// <summary>
        /// 设置加工面
        /// </summary>
        /// <param name="faces"></param>
        public void SetGeometry(params Face[] faces)
        {
            NXOpen.CAM.SurfaceContourBuilder builder1;
            builder1 = workPart.CAMSetup.CAMOperationCollection.CreateSurfaceContourBuilder(this.Oper);
            builder1.FeedsBuilder.SetMachiningData();
            NXOpen.CAM.GeometrySetList geometrySetList;
            geometrySetList = builder1.CutAreaGeometry.GeometryList;
            NXOpen.CAM.GeometrySet geometrySet2;
            geometrySet2 = builder1.CutAreaGeometry.CreateGeometrySet();
            geometrySetList.Append(geometrySet2);
            NXOpen.ScCollector scCollector1 = geometrySet2.ScCollector;
            ISelectionRule     rule         = new SelectionFaceRule(faces.ToList());

            SelectionIntentRule[] rules = new SelectionIntentRule[1] {
                rule.CreateSelectionRule()
            };
            scCollector1.ReplaceRules(rules, false);
            try
            {
                builder1.Commit();
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("SurfaceContourModel.SetGeometry 错误" + ex.Message);
            }
            finally
            {
                builder1.Destroy();
            }
        }
示例#6
0
        internal static SelectionIntentRule[] CreateSelectionIntentRule(params Snap.NX.ICurve[] icurves)
        {
            List <SelectionIntentRule> list = new List <SelectionIntentRule>();

            for (int i = 0; i < icurves.Length; i++)
            {
                if (icurves[i] is Snap.NX.Curve)
                {
                    NXOpen.Curve[]        curves    = new NXOpen.Curve[] { icurves[i] as Snap.NX.Curve };
                    CurveDumbRule         rule      = Globals.NXOpenWorkPart.ScRuleFactory.CreateRuleCurveDumb(curves);
                    SelectionIntentRule[] ruleArray = new SelectionIntentRule[] { rule };
                    for (int j = 0; j < ruleArray.Length; j++)
                    {
                        list.Add(ruleArray[j]);
                    }
                }
                else
                {
                    NXOpen.Edge[]         edges      = new NXOpen.Edge[] { icurves[i] as Snap.NX.Edge };
                    EdgeDumbRule          rule2      = Globals.NXOpenWorkPart.ScRuleFactory.CreateRuleEdgeDumb(edges);
                    SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[] { rule2 };
                    for (int k = 0; k < ruleArray2.Length; k++)
                    {
                        list.Add(ruleArray2[k]);
                    }
                }
            }
            return(list.ToArray());
        }
示例#7
0
        internal static Snap.NX.FaceBlend CreateFaceBlend(Snap.NX.Face face1, Snap.NX.Face face2, Snap.Number radius)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.FaceBlendBuilder featureBuilder = workPart.Features.CreateFaceBlendBuilder(null);
            featureBuilder.Tolerance = Globals.DistanceTolerance;
            ScCollector collector = workPart.ScCollectors.CreateCollector();

            NXOpen.Face[]   boundaryFaces = new NXOpen.Face[0];
            FaceTangentRule rule          = workPart.ScRuleFactory.CreateRuleFaceTangent((NXOpen.Face)face1, boundaryFaces, 0.5);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            collector.ReplaceRules(rules, false);
            featureBuilder.FirstFaceCollector     = collector;
            featureBuilder.ReverseFirstFaceNormal = true;
            ScCollector collector2 = workPart.ScCollectors.CreateCollector();

            NXOpen.Face[]   faceArray2 = new NXOpen.Face[0];
            FaceTangentRule rule2      = workPart.ScRuleFactory.CreateRuleFaceTangent((NXOpen.Face)face2, faceArray2, 0.5);

            SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[] { rule2 };
            collector2.ReplaceRules(ruleArray2, false);
            featureBuilder.SecondFaceCollector     = collector2;
            featureBuilder.ReverseSecondFaceNormal = true;
            featureBuilder.CircularCrossSection.SetRadius(radius.ToString());
            NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return((NXOpen.Features.FaceBlend)feature);
        }
示例#8
0
        /// <summary>
        /// 投影曲线
        /// </summary>
        /// <param name="features"></param>
        /// <param name="curves">要投影的曲线</param>
        /// <param name="originPoint">投影平面原点</param>
        /// <param name="normal">投影方向</param>
        /// <returns></returns>
        public static ProjectCurve CreateProjectCurve(this FeatureCollection features, IBaseCurve[] curves, Point3d originPoint, Vector3d normal)
        {
            NXOpen.Features.ProjectCurveBuilder projectCurveBuilder = features.CreateProjectCurveBuilder(null);
            Plane plane1 = WorkPart.Planes.CreatePlane(originPoint, normal, NXOpen.SmartObject.UpdateOption.WithinModeling);

            plane1.SetMethod(NXOpen.PlaneTypes.MethodType.Distance);
            plane1.SetFlip(false);
            plane1.SetReverseSide(false);
            plane1.SetAlternate(NXOpen.PlaneTypes.AlternateType.One);
            plane1.Evaluate();
            projectCurveBuilder.PlaneToProjectTo                      = plane1;
            projectCurveBuilder.CurveFitData.Tolerance                = 0.025;
            projectCurveBuilder.CurveFitData.AngleTolerance           = 0.5;
            projectCurveBuilder.ProjectionOption                      = NXOpen.Features.ProjectCurveBuilder.ProjectionOptionType.ProjectBothSides;
            projectCurveBuilder.AngleToProjectionVector.RightHandSide = "0";
            projectCurveBuilder.SectionToProject.DistanceTolerance    = 0.025;
            projectCurveBuilder.SectionToProject.ChainingTolerance    = 0.02375;
            projectCurveBuilder.SectionToProject.AngleTolerance       = 0.5;
            projectCurveBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints);
#if NX12
            CurveDumbRule curveFeatureRule1 = (WorkPart as BasePart).ScRuleFactory.CreateRuleBaseCurveDumb(curves);
#else
            CurveDumbRule curveFeatureRule1 = WorkPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves);
#endif
            projectCurveBuilder.SectionToProject.AllowSelfIntersection(true);
            SelectionIntentRule[] rules1 = new SelectionIntentRule[1] {
                curveFeatureRule1
            };
            Point3d helpPoint1 = new Point3d(1614.13079321387, -713.841520793069, 769.877304064383);
            projectCurveBuilder.SectionToProject.AddToSection(rules1, (NXObject)curves[0], null, null, helpPoint1, NXOpen.Section.Mode.Create, false);
            ProjectCurve projectCurve = (ProjectCurve)projectCurveBuilder.CommitFeature();
            projectCurveBuilder.SectionToProject.CleanMappingData();
            projectCurveBuilder.Destroy();
            return(projectCurve);
        }
示例#9
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();
    }
示例#10
0
        /// <summary>
        /// 抽取体
        /// </summary>
        /// <param name="features"></param>
        /// <param name="bodies"></param>
        /// <param name="associative"></param>
        /// <returns></returns>
        public static ExtractFace CreateExtractGeometry(this FeatureCollection features, Body[] bodies, bool associative = false)
        {
            ExtractFaceBuilder extractFaceBuilder = _workPart.Features.CreateExtractFaceBuilder(null);

            extractFaceBuilder.ParentPart = ExtractFaceBuilder.ParentPartType.WorkPart;

            extractFaceBuilder.Associative = associative;

            extractFaceBuilder.FixAtCurrentTimestamp = true;

            extractFaceBuilder.HideOriginal = false;

            extractFaceBuilder.InheritDisplayProperties = false;

            extractFaceBuilder.Type = ExtractFaceBuilder.ExtractType.Body;

            extractFaceBuilder.CopyThreads = false;

            extractFaceBuilder.FeatureOption = ExtractFaceBuilder.FeatureOptionType.SeparateFeatureForEachBody;

            BodyDumbRule bodyDumbRule1 = _workPart.ScRuleFactory.CreateRuleBodyDumb(bodies, true);

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
            rules1[0] = bodyDumbRule1;
            extractFaceBuilder.ExtractBodyCollector.ReplaceRules(rules1, false);

            ExtractFace nXObject1 = (ExtractFace)extractFaceBuilder.Commit();

            extractFaceBuilder.Destroy();

            return(nXObject1);
        }
示例#11
0
        /// <summary>
        /// 抽取曲线
        /// </summary>
        /// <param name="features"></param>
        /// <param name="curves"></param>
        /// <param name="associative"></param>
        /// <returns></returns>
        public static CompositeCurve CreateExtractGeometry(this FeatureCollection features, IBaseCurve[] curves, bool associative = false)
        {
            NXOpen.Features.CompositeCurveBuilder compositeCurveBuilder1 = _workPart.Features.CreateCompositeCurveBuilder(null);
            compositeCurveBuilder1.Tolerance                 = 0.01;
            compositeCurveBuilder1.Associative               = associative;
            compositeCurveBuilder1.FixAtCurrentTimestamp     = true;
            compositeCurveBuilder1.JoinOption                = NXOpen.Features.CompositeCurveBuilder.JoinMethod.Genernal;
            compositeCurveBuilder1.ParentPart                = NXOpen.Features.CompositeCurveBuilder.PartType.WorkPart;
            compositeCurveBuilder1.Section.DistanceTolerance = 0.01;
            compositeCurveBuilder1.Section.ChainingTolerance = 0.0095;
            compositeCurveBuilder1.HideOriginal              = false;
            compositeCurveBuilder1.InheritDisplayProperties  = false;
            compositeCurveBuilder1.Section.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints);

            CurveDumbRule curveDumbRule1 = _workPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves);

            compositeCurveBuilder1.Section.AllowSelfIntersection(false);
            SelectionIntentRule[] rules1 = new SelectionIntentRule[1] {
                curveDumbRule1
            };
            Point3d helpPoint1 = new Point3d(1885.57193958882, -793.938033503939, 819.818721208804);

            compositeCurveBuilder1.Section.AddToSection(rules1, curves[0] as NXObject, null, null, helpPoint1, NXOpen.Section.Mode.Create, false);
            CompositeCurve compositeCurve = (CompositeCurve)compositeCurveBuilder1.CommitFeature();

            compositeCurveBuilder1.Destroy();
            return(compositeCurve);
        }
示例#12
0
        public override List <SelectionIntentRule> GetSelectionRule()
        {
            List <SelectionIntentRule> sir = new List <SelectionIntentRule>();

            if (faces.Count != 0)
            {
                ISelectionRule rule = new SelectionFaceRule(faces);
                try
                {
                    SelectionIntentRule sr = rule.CreateSelectionRule();
                    sir.Add(sr);
                }
                catch
                {
                    ClassItem.WriteLogFile("选择面收集器错误!");
                    return(null);
                }
            }
            if (this.nextSelection != null)
            {
                List <SelectionIntentRule> tmpe = this.nextSelection.GetSelectionRule();
                if (tmpe.Count != 0)
                {
                    sir.AddRange(tmpe);
                }
            }
            return(sir);
        }
示例#13
0
        internal static Snap.NX.EdgeBlend CreateEdgeBlend(Snap.Number radius, Snap.NX.Edge[] edges)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.EdgeBlendBuilder featureBuilder = workPart.Features.CreateEdgeBlendBuilder(null);
            BlendLimitsData limitsListData = featureBuilder.LimitsListData;
            ScCollector     collector      = workPart.ScCollectors.CreateCollector();

            NXOpen.Edge[] seedEdges = new NXOpen.Edge[edges.Length];
            for (int i = 0; i < seedEdges.Length; i++)
            {
                seedEdges[i] = (NXOpen.Edge)edges[i];
            }
            EdgeMultipleSeedTangentRule rule = workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(seedEdges, Globals.AngleTolerance, true);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            collector.ReplaceRules(rules, false);
            featureBuilder.Tolerance              = Globals.DistanceTolerance;
            featureBuilder.AllInstancesOption     = false;
            featureBuilder.RemoveSelfIntersection = true;
            featureBuilder.ConvexConcaveY         = false;
            featureBuilder.RollOverSmoothEdge     = true;
            featureBuilder.RollOntoEdge           = true;
            featureBuilder.MoveSharpEdge          = true;
            featureBuilder.TrimmingOption         = false;
            featureBuilder.OverlapOption          = NXOpen.Features.EdgeBlendBuilder.Overlap.AnyConvexityRollOver;
            featureBuilder.BlendOrder             = NXOpen.Features.EdgeBlendBuilder.OrderOfBlending.ConvexFirst;
            featureBuilder.SetbackOption          = NXOpen.Features.EdgeBlendBuilder.Setback.SeparateFromCorner;
            featureBuilder.AddChainset(collector, radius.ToString());
            NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return((NXOpen.Features.EdgeBlend)feature);
        }
示例#14
0
        /// <summary>
        /// 创建单边偏置的拉伸
        /// </summary>
        /// <param name="features"></param>
        /// <param name="curves"></param>
        /// <param name="extrudeDirection"></param>
        /// <param name="startDistance"></param>
        /// <param name="endDistance"></param>
        /// <param name="bodyStyle"></param>
        /// <param name="offsetValue"></param>
        /// <returns></returns>
        public static Extrude CreateExtrude(this FeatureCollection features, IBaseCurve[] curves, Vector3d extrudeDirection, double startDistance, double endDistance, NXOpen.GeometricUtilities.FeatureOptions.BodyStyle bodyStyle, double offsetValue)
        {
            NXOpen.Features.ExtrudeBuilder extrudeBuilder = features.CreateExtrudeBuilder(null);

            Section section1 = WorkPart.Sections.CreateSection(0.0095, 0.01, 0.5);

            extrudeBuilder.Section = section1;

            extrudeBuilder.AllowSelfIntersectingSection(true);

            extrudeBuilder.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

            extrudeBuilder.Offset.Option = NXOpen.GeometricUtilities.Type.SingleOffset;

            extrudeBuilder.Offset.EndOffset.Value = offsetValue;

            extrudeBuilder.Draft.DraftOption = NXOpen.GeometricUtilities.SimpleDraft.SimpleDraftType.NoDraft;

            extrudeBuilder.FeatureOptions.BodyType = bodyStyle;

            section1.DistanceTolerance = 0.01;

            section1.ChainingTolerance = 0.0095;

            section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

            extrudeBuilder.Direction = WorkPart.Directions.CreateDirection(new Point3d(0.0, 0.0, 0.0), extrudeDirection, NXOpen.SmartObject.UpdateOption.WithinModeling);

#if NX12
            CurveDumbRule curveDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleBaseCurveDumb(curves);
#else
            CurveDumbRule curveDumbRule = WorkPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves);
#endif
            section1.AllowSelfIntersection(true);

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1] {
                curveDumbRule
            };

            section1.AddToSection(rules1, (NXObject)curves[0], null, null, new Point3d(0, 0, 0), NXOpen.Section.Mode.Create, false);

            extrudeBuilder.Limits.StartExtend.TrimType = NXOpen.GeometricUtilities.Extend.ExtendType.Value;

            extrudeBuilder.Limits.EndExtend.TrimType = NXOpen.GeometricUtilities.Extend.ExtendType.Value;

            extrudeBuilder.Limits.EndExtend.Value.RightHandSide = endDistance.ToString();

            extrudeBuilder.Limits.StartExtend.Value.RightHandSide = startDistance.ToString();

            extrudeBuilder.ParentFeatureInternal = false;

            Extrude extrude = (Extrude)extrudeBuilder.CommitFeature();
            extrudeBuilder.Destroy();
            return(extrude);
        }
示例#15
0
        /// <summary>
        /// 链接到工作部件中(非关联)
        /// </summary>
        /// <param name="seleObj">要链接的体</param>
        /// <returns></returns>
        public static NXOpen.Features.Feature WaveBodys(params NXObject[] seleObj)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Features.Feature            nullNXOpen_Features_Feature = null;
            NXOpen.Features.WaveLinkBuilder    waveLinkBuilder1            = workPart.BaseFeatures.CreateWaveLinkBuilder(nullNXOpen_Features_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             = false; //关联
            extractFaceBuilder1.MakePositionIndependent = false;
            extractFaceBuilder1.FixAtCurrentTimestamp   = false;

            extractFaceBuilder1.HideOriginal = false;

            extractFaceBuilder1.InheritDisplayProperties = false;

            NXOpen.ScCollector scCollector1;
            scCollector1 = extractFaceBuilder1.ExtractBodyCollector;

            extractFaceBuilder1.CopyThreads = false; //是否复制

            extractFaceBuilder1.FeatureOption = NXOpen.Features.ExtractFaceBuilder.FeatureOptionType.OneFeatureForAllBodies;
            Body[] seleBody = new Body[seleObj.Length];
            for (int i = 0; i < seleObj.Length; i++)
            {
                seleBody[i] = (Body)seleObj[i];
            }

            BodyDumbRule bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(seleBody, true);

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
            rules1[0] = bodyDumbRule1;
            scCollector1.ReplaceRules(rules1, false);
            try
            {
                return(waveLinkBuilder1.CommitFeature());
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("AssmbliesUtils:WaveBodys:" + ex.Message);
                return(null);
            }
            finally
            {
                extractFaceBuilder1.Destroy();
            }
        }
示例#16
0
    public Body Revolve(Part workPart, Axis axisRotation, Sketch sketch, Line lineSketch, Point3d point3dSketch, double degStart, double degEnd)
    {
        //RevolveBulidier
        NXOpen.Features.Feature        nullFeature1    = null;
        NXOpen.Features.RevolveBuilder revolveBuilder1 = workPart.Features.CreateRevolveBuilder(nullFeature1);

        //Section
        Section section1 = workPart.Sections.CreateSection(0.02, 0.02, 0.02);

        revolveBuilder1.Section    = section1;
        revolveBuilder1.Axis       = axisRotation;
        revolveBuilder1.Tolerance  = 0.02;
        section1.DistanceTolerance = 0.02;
        section1.ChainingTolerance = 0.02;

        //Line assignment
        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)sketch.Feature;
        features1[0] = sketchFeature1;

        CurveFeatureRule curveFeatureRule1;

        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        NXObject nullNXObject = null;

        //Selection
        section1.AddToSection(rules1, lineSketch, nullNXObject, nullNXObject, point3dSketch, NXOpen.Section.Mode.Create, false);

        revolveBuilder1.Axis = axisRotation;

        //Sheet Body selection
        revolveBuilder1.FeatureOptions.BodyType = NXOpen.GeometricUtilities.FeatureOptions.BodyStyle.Sheet;
        revolveBuilder1.Section = section1;

        //Ustawienia
        revolveBuilder1.Limits.StartExtend.Value.RightHandSide = degStart.ToString();
        revolveBuilder1.Limits.EndExtend.Value.RightHandSide   = degEnd.ToString();
        revolveBuilder1.ParentFeatureInternal = false;

        NXObject feature_revolve1 = revolveBuilder1.CommitFeature();

        NXOpen.Features.BodyFeature bodyFeature1 = (NXOpen.Features.BodyFeature)feature_revolve1;
        Body[] body = bodyFeature1.GetBodies();
        return(body[0]);
    }
示例#17
0
        /// <summary>
        /// 创建拉伸体
        /// </summary>
        public static Extrude Extrude(Snap.NX.Face face, double height)
        {
            var     curves      = face.EdgeCurves;
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            var normal = face.Normal(face.BoxUV.MinU, face.BoxUV.MinV);
            var point  = face.Position(face.BoxUV.MinU, face.BoxUV.MinV);

            var curveList = new List <NXOpen.Curve>();

            curves.ToList().ForEach(u =>
            {
                curveList.Add(u);
            });

            //创建拉伸
            NXOpen.Features.Feature nullFeatures_Feature = null;
            ExtrudeBuilder          extrudeBuilder1;

            extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullFeatures_Feature);

            //方向
            extrudeBuilder1.Direction = workPart.Directions.CreateDirection(point, normal, SmartObject.UpdateOption.WithinModeling);

            //曲面
            Section section1;

            section1 = workPart.Sections.CreateSection();
            extrudeBuilder1.Section = section1;
            var curveDumbRule1 = workPart.ScRuleFactory.CreateRuleCurveDumb(curveList.ToArray());

            SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
            rules1[0] = curveDumbRule1;
            section1.AddToSection(rules1, curves.FirstOrDefault(), null, null, new Point3d(), NXOpen.Section.Mode.Create);

            //开始值、结束值
            extrudeBuilder1.Limits.StartExtend.Value.Value = 0;
            extrudeBuilder1.Limits.EndExtend.Value.Value   = height;

            Extrude feature1;

            feature1 = (Extrude)extrudeBuilder1.CommitFeature();
            extrudeBuilder1.Destroy();
            return(feature1);
        }
示例#18
0
 internal static Snap.NX.OffsetFace CreateOffsetFace(Snap.NX.Face[] faces, Snap.Number distance, bool direction)
 {
     NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
     NXOpen.Features.OffsetFaceBuilder featureBuilder = workPart.Features.CreateOffsetFaceBuilder(null);
     featureBuilder.Distance.RightHandSide = distance.ToString();
     SelectionIntentRule[] rules = new SelectionIntentRule[faces.Length];
     for (int i = 0; i < faces.Length; i++)
     {
         NXOpen.Face[] boundaryFaces = new NXOpen.Face[0];
         rules[i] = workPart.ScRuleFactory.CreateRuleFaceTangent((NXOpen.Face)faces[i], boundaryFaces);
     }
     featureBuilder.FaceCollector.ReplaceRules(rules, false);
     featureBuilder.Direction = direction;
     NXOpen.Features.OffsetFace offsetFace = (NXOpen.Features.OffsetFace)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return(new Snap.NX.OffsetFace(offsetFace));
 }
示例#19
0
        internal static Snap.NX.ExtractFace CreateExtractFace(Snap.NX.Face[] faces)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.ExtractFaceBuilder featureBuilder = workPart.Features.CreateExtractFaceBuilder(null);
            featureBuilder.FaceOption = NXOpen.Features.ExtractFaceBuilder.FaceOptionType.FaceChain;
            NXOpen.Face[] faceArray = new NXOpen.Face[faces.Length];
            for (int i = 0; i < faces.Length; i++)
            {
                faceArray[i] = (NXOpen.Face)faces[i];
            }
            FaceDumbRule rule = workPart.ScRuleFactory.CreateRuleFaceDumb(faceArray);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            featureBuilder.FaceChain.ReplaceRules(rules, false);
            NXOpen.Features.ExtractFace extract = (NXOpen.Features.ExtractFace)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return(new Snap.NX.ExtractFace(extract));
        }
示例#20
0
        internal static Snap.NX.ProjectCurve CreateProjectCurve2(Snap.NX.Curve[] curves, Snap.NX.Point[] points, Snap.NX.Face face)
        {
            NXOpen.Part work = Globals.Session.Parts.Work;
            NXOpen.Features.ProjectCurveBuilder featureBuilder = work.Features.CreateProjectCurveBuilder(null);
            featureBuilder.CurveFitData.Tolerance = Globals.DistanceTolerance;
            featureBuilder.AngleToProjectionVector.RightHandSide = "0";
            featureBuilder.SectionToProject.DistanceTolerance    = Globals.DistanceTolerance;
            featureBuilder.SectionToProject.ChainingTolerance    = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
            featureBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints);
            if (curves != null)
            {
                Snap.NX.Section sectionToProject = featureBuilder.SectionToProject;
                for (int i = 0; i < curves.Length; i++)
                {
                    sectionToProject.AddICurve(new Snap.NX.ICurve[] { curves[i] });
                }
            }
            if (points != null)
            {
                NXOpen.Point[] pointArray = new NXOpen.Point[points.Length];
                for (int j = 0; j < pointArray.Length; j++)
                {
                    pointArray[j] = (NXOpen.Point)points[j];
                }
                CurveDumbRule rule = work.ScRuleFactory.CreateRuleCurveDumbFromPoints(pointArray);
                featureBuilder.SectionToProject.AllowSelfIntersection(true);
                SelectionIntentRule[] ruleArray = new SelectionIntentRule[] { rule };
                Point3d helpPoint = new Point3d(0.0, 0.0, 0.0);
                featureBuilder.SectionToProject.AddToSection(ruleArray, null, null, null, helpPoint, NXOpen.Section.Mode.Create, false);
            }
            ScCollector collector = work.ScCollectors.CreateCollector();

            NXOpen.Face[] faces = new NXOpen.Face[] { face };
            FaceDumbRule  rule2 = work.ScRuleFactory.CreateRuleFaceDumb(faces);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule2 };
            collector.ReplaceRules(rules, false);
            featureBuilder.FaceToProjectTo.Add(collector);
            NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.SectionToProject.CleanMappingData();
            featureBuilder.Destroy();
            return((NXOpen.Features.ProjectCurve)feature);
        }
示例#21
0
        internal static Snap.NX.Chamfer CreateChamfer(Snap.NX.Edge edge, Snap.Number distance, Snap.Number angle)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.ChamferBuilder featureBuilder = workPart.Features.CreateChamferBuilder(null);
            featureBuilder.Option      = NXOpen.Features.ChamferBuilder.ChamferOption.OffsetAndAngle;
            featureBuilder.FirstOffset = distance.ToString();
            featureBuilder.Angle       = angle.ToString();
            //featureBuilder.Tolerance = Globals.DistanceTolerance;
            ScCollector     collector = workPart.ScCollectors.CreateCollector();
            EdgeTangentRule rule      = workPart.ScRuleFactory.CreateRuleEdgeTangent((NXOpen.Edge)edge, null, true, Globals.AngleTolerance, false, false);

            SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
            collector.ReplaceRules(rules, false);
            featureBuilder.SmartCollector = collector;
            featureBuilder.AllInstances   = false;
            NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return((NXOpen.Features.Chamfer)feature);
        }
示例#22
0
 internal static Snap.NX.TrimBody CreateTrimBody(Snap.NX.Body targetBody, Snap.NX.Face toolFace, bool direction)
 {
     NXOpen.Part workPart = (NXOpen.Part) Globals.WorkPart;
     TrimBody2Builder featureBuilder = workPart.Features.CreateTrimBody2Builder(null);
     featureBuilder.Tolerance = Globals.DistanceTolerance;
     featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.DistanceTolerance = Globals.DistanceTolerance;
     featureBuilder.BooleanTool.ExtrudeRevolveTool.ToolSection.ChainingTolerance = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
     ScCollector collector = workPart.ScCollectors.CreateCollector();
     NXOpen.Body[] bodies = new NXOpen.Body[] { targetBody };
     BodyDumbRule rule = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies);
     SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
     collector.ReplaceRules(rules, false);
     featureBuilder.TargetBodyCollector = collector;
     SelectionIntentRule[] ruleArray2 = new SelectionIntentRule[] { workPart.ScRuleFactory.CreateRuleFaceBody((NXOpen.Body) toolFace.Body) };
     featureBuilder.BooleanTool.FacePlaneTool.ToolFaces.FaceCollector.ReplaceRules(ruleArray2, false);
     featureBuilder.BooleanTool.ReverseDirection = direction;
     TrimBody2 trim = (TrimBody2) Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return new Snap.NX.TrimBody(trim);
 }
示例#23
0
        internal static Snap.NX.ProjectCurve CreateProjectCurve2(Snap.NX.DatumPlane datumPlane, Snap.NX.Curve[] curves, Snap.NX.Point[] points)
        {
            NXOpen.Part work = Globals.Session.Parts.Work;
            NXOpen.Features.ProjectCurveBuilder featureBuilder = work.Features.CreateProjectCurveBuilder(null);
            //featureBuilder.CurveFitData.Tolerance = Globals.DistanceTolerance;
            featureBuilder.Tolerance = Globals.DistanceTolerance;
            featureBuilder.AngleToProjectionVector.RightHandSide = "0";
            featureBuilder.SectionToProject.DistanceTolerance    = Globals.DistanceTolerance;
            featureBuilder.SectionToProject.ChainingTolerance    = (Globals.UnitType == Globals.Unit.Millimeter) ? 0.02413 : 0.00095;
            featureBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.SectionEx.AllowTypes.CurvesAndPoints);
            if (curves != null)
            {
                Snap.NX.Section sectionToProject = featureBuilder.SectionToProject;
                for (int i = 0; i < curves.Length; i++)
                {
                    sectionToProject.AddICurve(new Snap.NX.ICurve[] { curves[i] });
                }
            }
            if (points != null)
            {
                NXOpen.Point[] pointArray = new NXOpen.Point[points.Length];
                for (int j = 0; j < pointArray.Length; j++)
                {
                    pointArray[j] = (NXOpen.Point)points[j];
                }
                CurveDumbRule rule = work.ScRuleFactory.CreateRuleCurveDumbFromPoints(pointArray);
                featureBuilder.SectionToProject.AllowSelfIntersection(true);
                SelectionIntentRule[] rules = new SelectionIntentRule[] { rule };
                Point3d helpPoint           = new Point3d(0.0, 0.0, 0.0);
                featureBuilder.SectionToProject.AddToSection(rules, null, null, null, helpPoint, NXOpen.Section.Mode.Create, false);
            }
            Position origin = datumPlane.Origin;
            Vector   normal = datumPlane.Normal;

            NXOpen.Plane plane = Globals.NXOpenWorkPart.Planes.CreatePlane((Point3d)origin, (Vector3d)normal, SmartObject.UpdateOption.WithinModeling);
            featureBuilder.PlaneToProjectTo = plane;
            NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.SectionToProject.CleanMappingData();
            featureBuilder.Destroy();
            return((NXOpen.Features.ProjectCurve)feature);
        }
        public void SetGeometry(params Face[] faces)
        {
            NXOpen.CAM.ZLevelMillingBuilder builder1;
            try
            {
                builder1 = workPart.CAMSetup.CAMOperationCollection.CreateZlevelMillingBuilder(this.Oper);
            }
            catch (NXException ex)
            {
                throw ex;
            }
            builder1.FeedsBuilder.SetMachiningData();
            NXOpen.CAM.GeometrySetList geometrySetList;
            geometrySetList = builder1.CutAreaGeometry.GeometryList;
            NXOpen.CAM.GeometrySet geometrySet2;
            geometrySet2 = builder1.CutAreaGeometry.CreateGeometrySet();
            geometrySetList.Append(geometrySet2);
            NXOpen.ScCollector scCollector1 = geometrySet2.ScCollector;
            ISelectionRule     rule         = new SelectionFaceRule(faces.ToList());

            SelectionIntentRule[] rules = new SelectionIntentRule[1] {
                rule.CreateSelectionRule()
            };
            scCollector1.ReplaceRules(rules, false);
            try
            {
                builder1.Commit();
            }
            catch (NXException ex)
            {
                throw ex;
            }
            finally
            {
                builder1.Destroy();
            }
        }
示例#25
0
        /// <summary>
        /// 创建有界平面
        /// </summary>
        /// <param name="featureCollection"></param>
        /// <param name="boundingCurves"></param>
        /// <returns></returns>
        public static BoundedPlane CreateBoundedPlane(this FeatureCollection featureCollection, IBaseCurve[] boundingCurves)
        {
            if (boundingCurves.Length != 0)
            {
                BoundedPlaneBuilder boundedPlaneBuilder = _workPart.Features.CreateBoundedPlaneBuilder(null);

                boundedPlaneBuilder.BoundingCurves.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

                CurveDumbRule curveDumbRule1 = _workPart.ScRuleFactory.CreateRuleBaseCurveDumb(boundingCurves);

                boundedPlaneBuilder.BoundingCurves.AllowSelfIntersection(true);

                NXOpen.SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
                rules1[0] = curveDumbRule1;
                boundedPlaneBuilder.BoundingCurves.AddToSection(rules1, boundingCurves[0] as NXObject, null, null, new Point3d(), Section.Mode.Create, false);

                BoundedPlane nXObject1 = (BoundedPlane)boundedPlaneBuilder.Commit();

                boundedPlaneBuilder.Destroy();

                return(nXObject1);
            }
            return(null);
        }
示例#26
0
 internal static Snap.NX.Thicken CreateThicken(Snap.NX.Body[] targetBodies, Snap.Number offset1, Snap.Number offset2)
 {
     NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
     NXOpen.Features.ThickenBuilder featureBuilder = workPart.Features.CreateThickenBuilder(null);
     featureBuilder.Tolerance = Globals.DistanceTolerance;
     featureBuilder.FirstOffset.RightHandSide  = offset1.ToString();
     featureBuilder.SecondOffset.RightHandSide = offset2.ToString();
     featureBuilder.BooleanOperation.Type      = BooleanOperation.BooleanType.Create;
     NXOpen.Body[] bodyArray = new NXOpen.Body[targetBodies.Length];
     for (int i = 0; i < targetBodies.Length; i++)
     {
         bodyArray[i] = (NXOpen.Body)targetBodies[i];
     }
     featureBuilder.BooleanOperation.SetTargetBodies(bodyArray);
     SelectionIntentRule[] rules = new SelectionIntentRule[targetBodies.Length];
     for (int j = 0; j < targetBodies.Length; j++)
     {
         rules[j] = workPart.ScRuleFactory.CreateRuleFaceBody((NXOpen.Body)targetBodies[j]);
     }
     featureBuilder.FaceCollector.ReplaceRules(rules, false);
     NXOpen.Features.Thicken thicken = (NXOpen.Features.Thicken)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return(new Snap.NX.Thicken(thicken));
 }
示例#27
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Starting NX Journal");

        //Declare Part Variables
        //Convert Strings to doubles from the args
        double length    = System.Convert.ToDouble(args[0]);
        double width     = System.Convert.ToDouble(args[1]);
        double height    = System.Convert.ToDouble(args[2]);
        string part_name = args[3];

        //Measurements need to be converted from m to mm
        length = 1000 * length;
        width  = 1000 * width;
        height = 1000 * height;


        //Convert necessary values to string.
        string length_string = System.Convert.ToString(length);
        string width_string  = System.Convert.ToString(width);
        string height_string = System.Convert.ToString(height);


        Session theSession = Session.GetSession();

        // ----------------------------------------------
        //   Menu: File->New...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId1;
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        FileNew fileNew1;

        fileNew1 = theSession.Parts.FileNew();

        theSession.SetUndoMarkName(markId1, "New Dialog");

        NXOpen.Session.UndoMarkId markId2;
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        theSession.DeleteUndoMark(markId2, null);

        NXOpen.Session.UndoMarkId markId3;
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New");

        fileNew1.TemplateFileName = "model-plain-1-mm-template.prt";

        fileNew1.ApplicationName = "ModelTemplate";

        fileNew1.Units = NXOpen.Part.Units.Millimeters;

        fileNew1.RelationType = "";

        fileNew1.UsesMasterModel = "No";

        fileNew1.TemplateType = FileNewTemplateType.Item;

        fileNew1.NewFileName = part_name;

        fileNew1.MasterFileName = "";

        fileNew1.UseBlankTemplate = false;

        fileNew1.MakeDisplayedPart = true;

        NXObject nXObject1;

        nXObject1 = fileNew1.Commit();

        Part workPart    = theSession.Parts.Work;
        Part displayPart = theSession.Parts.Display;

        theSession.DeleteUndoMark(markId3, null);

        fileNew1.Destroy();

        NXOpen.Session.UndoMarkId markId4;
        markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Enter Modeling");

        // ----------------------------------------------
        //   Menu: Insert->Sketch...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId5;
        markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        Sketch nullSketch = null;
        SketchInPlaceBuilder sketchInPlaceBuilder1;

        sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullSketch);

        Unit       unit1 = (Unit)workPart.UnitCollection.FindObject("MilliMeter");
        Expression expression1;

        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        Expression expression2;

        expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        SketchAlongPathBuilder sketchAlongPathBuilder1;

        sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullSketch);

        sketchAlongPathBuilder1.PlaneLocation.Expression.RightHandSide = "0";

        theSession.SetUndoMarkName(markId5, "Create Sketch Dialog");

        DatumPlane datumPlane1 = (DatumPlane)workPart.Datums.FindObject("DATUM_CSYS(0) XY plane");
        Point3d    point1      = new Point3d(26.3626531592029, 1.06581410364015e-014, 30.438226401797);

        sketchInPlaceBuilder1.PlaneOrFace.SetValue(datumPlane1, workPart.ModelingViews.WorkView, point1);

        NXOpen.Features.DatumCsys datumCsys1 = (NXOpen.Features.DatumCsys)workPart.Features.FindObject("DATUM_CSYS(0)");
        Point point2 = (Point)datumCsys1.FindObject("POINT 1");

        sketchInPlaceBuilder1.SketchOrigin = point2;

        sketchInPlaceBuilder1.PlaneOrFace.Value = null;

        sketchInPlaceBuilder1.PlaneOrFace.Value = datumPlane1;

        sketchInPlaceBuilder1.ReversePlaneNormal = true;

        DatumAxis datumAxis1 = (DatumAxis)workPart.Datums.FindObject("DATUM_CSYS(0) X axis");

        sketchInPlaceBuilder1.Axis.Value = datumAxis1;

        NXOpen.Session.UndoMarkId markId6;
        markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.DeleteUndoMark(markId6, null);

        NXOpen.Session.UndoMarkId markId7;
        markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Sketch");

        theSession.Preferences.Sketch.CreateInferredConstraints = true;

        theSession.Preferences.Sketch.ContinuousAutoDimensioning = true;

        theSession.Preferences.Sketch.DimensionLabel = NXOpen.Preferences.SketchPreferences.DimensionLabelType.Expression;

        theSession.Preferences.Sketch.TextSizeFixed = true;

        theSession.Preferences.Sketch.FixedTextSize = 3.0;

        theSession.Preferences.Sketch.ConstraintSymbolSize = 3.0;

        theSession.Preferences.Sketch.DisplayObjectColor = false;

        theSession.Preferences.Sketch.DisplayObjectName = true;

        NXObject nXObject2;

        nXObject2 = sketchInPlaceBuilder1.Commit();

        Sketch sketch1 = (Sketch)nXObject2;

        NXOpen.Features.Feature feature1;
        feature1 = sketch1.Feature;

        NXOpen.Session.UndoMarkId markId8;
        markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "update");

        int nErrs1;

        nErrs1 = theSession.UpdateManager.DoUpdate(markId8);

        sketch1.Activate(NXOpen.Sketch.ViewReorient.True);

        theSession.DeleteUndoMark(markId7, null);

        theSession.SetUndoMarkName(markId5, "Create Sketch");

        sketchInPlaceBuilder1.Destroy();

        sketchAlongPathBuilder1.Destroy();

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression2);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        try
        {
            // Expression is still in use.
            workPart.Expressions.Delete(expression1);
        }
        catch (NXException ex)
        {
            ex.AssertErrorCode(1050029);
        }

        // ----------------------------------------------
        //   Menu: Insert->Sketch Curve->Rectangle...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId9;
        markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Profile short list");

        NXOpen.Session.UndoMarkId markId10;
        markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create Rectangle");

        Expression expression3;

        expression3 = workPart.Expressions.CreateSystemExpression(width_string);

        theSession.SetUndoMarkVisibility(markId10, "Create Rectangle", NXOpen.Session.MarkVisibility.Visible);

        // ----------------------------------------------
        // Creating rectangle using By 2 Points method
        // ----------------------------------------------
        Point3d startPoint1 = new Point3d(0.0, 0.0, 0.0);
        Point3d endPoint1   = new Point3d(width, 0.0, 0.0);
        Line    line1;

        line1 = workPart.Curves.CreateLine(startPoint1, endPoint1);

        Point3d startPoint2 = new Point3d(width, 0.0, 0.0);
        Point3d endPoint2   = new Point3d(width, 0.0, height);
        Line    line2;

        line2 = workPart.Curves.CreateLine(startPoint2, endPoint2);

        Point3d startPoint3 = new Point3d(width, 0.0, height);
        Point3d endPoint3   = new Point3d(0.0, 0.0, height);
        Line    line3;

        line3 = workPart.Curves.CreateLine(startPoint3, endPoint3);

        Point3d startPoint4 = new Point3d(0.0, 0.0, height);
        Point3d endPoint4   = new Point3d(0.0, 0.0, 0.0);
        Line    line4;

        line4 = workPart.Curves.CreateLine(startPoint4, endPoint4);

        theSession.ActiveSketch.AddGeometry(line1, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.ActiveSketch.AddGeometry(line2, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.ActiveSketch.AddGeometry(line3, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        theSession.ActiveSketch.AddGeometry(line4, NXOpen.Sketch.InferConstraintsOption.InferNoConstraints);

        NXOpen.Sketch.ConstraintGeometry geom1_1;
        geom1_1.Geometry  = line1;
        geom1_1.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_1;
        geom2_1.Geometry  = line2;
        geom2_1.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint1;

        sketchGeometricConstraint1 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_1, geom2_1);

        NXOpen.Sketch.ConstraintGeometry geom1_2;
        geom1_2.Geometry  = line2;
        geom1_2.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_2;
        geom2_2.Geometry  = line3;
        geom2_2.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_2.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint2;

        sketchGeometricConstraint2 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_2, geom2_2);

        NXOpen.Sketch.ConstraintGeometry geom1_3;
        geom1_3.Geometry  = line3;
        geom1_3.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_3;
        geom2_3.Geometry  = line4;
        geom2_3.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_3.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint3;

        sketchGeometricConstraint3 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_3, geom2_3);

        NXOpen.Sketch.ConstraintGeometry geom1_4;
        geom1_4.Geometry  = line4;
        geom1_4.PointType = NXOpen.Sketch.ConstraintPointType.EndVertex;
        geom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_4;
        geom2_4.Geometry  = line1;
        geom2_4.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom2_4.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint4;

        sketchGeometricConstraint4 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_4, geom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1;
        geom1.Geometry  = line1;
        geom1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint5;

        sketchGeometricConstraint5 = theSession.ActiveSketch.CreateHorizontalConstraint(geom1);

        NXOpen.Sketch.ConstraintGeometry conGeom1_1;
        conGeom1_1.Geometry  = line1;
        conGeom1_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_1.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_1;
        conGeom2_1.Geometry  = line2;
        conGeom2_1.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_1.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint6;

        sketchGeometricConstraint6 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_1, conGeom2_1);

        NXOpen.Sketch.ConstraintGeometry conGeom1_2;
        conGeom1_2.Geometry  = line2;
        conGeom1_2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_2.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_2;
        conGeom2_2.Geometry  = line3;
        conGeom2_2.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_2.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint7;

        sketchGeometricConstraint7 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_2, conGeom2_2);

        NXOpen.Sketch.ConstraintGeometry conGeom1_3;
        conGeom1_3.Geometry  = line3;
        conGeom1_3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_3.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_3;
        conGeom2_3.Geometry  = line4;
        conGeom2_3.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_3.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint8;

        sketchGeometricConstraint8 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_3, conGeom2_3);

        NXOpen.Sketch.ConstraintGeometry conGeom1_4;
        conGeom1_4.Geometry  = line4;
        conGeom1_4.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom1_4.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry conGeom2_4;
        conGeom2_4.Geometry  = line1;
        conGeom2_4.PointType = NXOpen.Sketch.ConstraintPointType.None;
        conGeom2_4.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint9;

        sketchGeometricConstraint9 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_4, conGeom2_4);

        NXOpen.Sketch.ConstraintGeometry geom1_5;
        geom1_5.Geometry  = line1;
        geom1_5.PointType = NXOpen.Sketch.ConstraintPointType.StartVertex;
        geom1_5.SplineDefiningPointIndex = 0;
        NXOpen.Sketch.ConstraintGeometry geom2_5;
        geom2_5.Geometry  = point2;
        geom2_5.PointType = NXOpen.Sketch.ConstraintPointType.None;
        geom2_5.SplineDefiningPointIndex = 0;
        SketchGeometricConstraint sketchGeometricConstraint10;

        sketchGeometricConstraint10 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_5, geom2_5);

        NXOpen.Sketch.DimensionGeometry dimObject1_1;
        dimObject1_1.Geometry    = line3;
        dimObject1_1.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_1.AssocValue  = 0;
        dimObject1_1.HelpPoint.X = 0.0;
        dimObject1_1.HelpPoint.Y = 0.0;
        dimObject1_1.HelpPoint.Z = 0.0;
        NXObject nullNXObject = null;

        dimObject1_1.View = nullNXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_1;
        dimObject2_1.Geometry    = line3;
        dimObject2_1.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_1.AssocValue  = 0;
        dimObject2_1.HelpPoint.X = 0.0;
        dimObject2_1.HelpPoint.Y = 0.0;
        dimObject2_1.HelpPoint.Z = 0.0;
        dimObject2_1.View        = nullNXObject;
        Point3d dimOrigin1 = new Point3d(25.0, 0.0, 149.651881900218);
        SketchDimensionalConstraint sketchDimensionalConstraint1;

        sketchDimensionalConstraint1 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_1, dimObject2_1, dimOrigin1, expression3, NXOpen.Sketch.DimensionOption.CreateAsDriving);

        SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint1 = (SketchHelpedDimensionalConstraint)sketchDimensionalConstraint1;

        NXOpen.Annotations.Dimension dimension1;
        dimension1 = sketchHelpedDimensionalConstraint1.AssociatedDimension;

        NXOpen.Sketch.DimensionGeometry dimObject1_2;
        dimObject1_2.Geometry    = line2;
        dimObject1_2.AssocType   = NXOpen.Sketch.AssocType.StartPoint;
        dimObject1_2.AssocValue  = 0;
        dimObject1_2.HelpPoint.X = 0.0;
        dimObject1_2.HelpPoint.Y = 0.0;
        dimObject1_2.HelpPoint.Z = 0.0;
        dimObject1_2.View        = nullNXObject;
        NXOpen.Sketch.DimensionGeometry dimObject2_2;
        dimObject2_2.Geometry    = line2;
        dimObject2_2.AssocType   = NXOpen.Sketch.AssocType.EndPoint;
        dimObject2_2.AssocValue  = 0;
        dimObject2_2.HelpPoint.X = 0.0;
        dimObject2_2.HelpPoint.Y = 0.0;
        dimObject2_2.HelpPoint.Z = 0.0;
        dimObject2_2.View        = nullNXObject;
        Point3d    dimOrigin2     = new Point3d(74.651881900218, 0.0, 62.5);
        Expression nullExpression = null;
        SketchDimensionalConstraint sketchDimensionalConstraint2;

        sketchDimensionalConstraint2 = theSession.ActiveSketch.CreateDimension(NXOpen.Sketch.ConstraintType.ParallelDim, dimObject1_2, dimObject2_2, dimOrigin2, nullExpression, NXOpen.Sketch.DimensionOption.CreateAsAutomatic);

        SketchHelpedDimensionalConstraint sketchHelpedDimensionalConstraint2 = (SketchHelpedDimensionalConstraint)sketchDimensionalConstraint2;

        NXOpen.Annotations.Dimension dimension2;
        dimension2 = sketchHelpedDimensionalConstraint2.AssociatedDimension;

        Expression expression4;

        expression4 = sketchHelpedDimensionalConstraint2.AssociatedExpression;

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = false;

        theSession.ActiveSketch.Update();

        theSession.Preferences.Sketch.AutoDimensionsToArcCenter = true;

        SmartObject[] geoms1 = new SmartObject[4];
        geoms1[0] = line1;
        geoms1[1] = line2;
        geoms1[2] = line3;
        geoms1[3] = line4;
        theSession.ActiveSketch.UpdateConstraintDisplay(geoms1);

        SmartObject[] geoms2 = new SmartObject[4];
        geoms2[0] = line1;
        geoms2[1] = line2;
        geoms2[2] = line3;
        geoms2[3] = line4;
        theSession.ActiveSketch.UpdateDimensionDisplay(geoms2);

        // ----------------------------------------------
        //   Menu: File->Finish Sketch
        // ----------------------------------------------
        theSession.ActiveSketch.Deactivate(NXOpen.Sketch.ViewReorient.False, NXOpen.Sketch.UpdateLevel.Model);

        // ----------------------------------------------
        //   Menu: Insert->Design Feature->Extrude...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId11;
        markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        NXOpen.Features.Feature nullFeatures_Feature = null;

        if (!workPart.Preferences.Modeling.GetHistoryMode())
        {
            throw new Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
        }

        NXOpen.Features.ExtrudeBuilder extrudeBuilder1;
        extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullFeatures_Feature);

        Section section1;

        section1 = workPart.Sections.CreateSection(0.0095, 0.01, 0.5);

        extrudeBuilder1.Section = section1;

        extrudeBuilder1.AllowSelfIntersectingSection(true);

        Unit unit2;

        unit2 = extrudeBuilder1.Draft.FrontDraftAngle.Units;

        Expression expression5;

        expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("2.00", unit2);

        extrudeBuilder1.DistanceTolerance = 0.01;

        extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

        Body[] targetBodies1 = new Body[1];
        Body   nullBody      = null;

        targetBodies1[0] = nullBody;
        extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies1);

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = "25";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0";

        extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = length_string;

        extrudeBuilder1.Draft.FrontDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Draft.BackDraftAngle.RightHandSide = "2";

        extrudeBuilder1.Offset.StartOffset.RightHandSide = "0";

        extrudeBuilder1.Offset.EndOffset.RightHandSide = "5";

        NXOpen.GeometricUtilities.SmartVolumeProfileBuilder smartVolumeProfileBuilder1;
        smartVolumeProfileBuilder1 = extrudeBuilder1.SmartVolumeProfile;

        smartVolumeProfileBuilder1.OpenProfileSmartVolumeOption = false;

        smartVolumeProfileBuilder1.CloseProfileRule = NXOpen.GeometricUtilities.SmartVolumeProfileBuilder.CloseProfileRuleType.Fci;

        theSession.SetUndoMarkName(markId11, "Extrude Dialog");

        section1.DistanceTolerance = 0.01;

        section1.ChainingTolerance = 0.0095;

        section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves);

        NXOpen.Session.UndoMarkId markId12;
        markId12 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "section mark");

        NXOpen.Session.UndoMarkId markId13;
        markId13 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, null);

        NXOpen.Features.Feature[]     features1      = new NXOpen.Features.Feature[1];
        NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)feature1;
        features1[0] = sketchFeature1;
        CurveFeatureRule curveFeatureRule1;

        curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1);

        section1.AllowSelfIntersection(true);

        SelectionIntentRule[] rules1 = new SelectionIntentRule[1];
        rules1[0] = curveFeatureRule1;
        Point3d helpPoint1 = new Point3d(23.553389477581, 0.0, height);

        section1.AddToSection(rules1, line3, nullNXObject, nullNXObject, helpPoint1, NXOpen.Section.Mode.Create, false);

        theSession.DeleteUndoMark(markId13, null);

        Direction direction1;

        direction1 = workPart.Directions.CreateDirection(sketch1, Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling);

        extrudeBuilder1.Direction = direction1;

        theSession.DeleteUndoMark(markId12, null);

        NXOpen.Session.UndoMarkId markId14;
        markId14 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        theSession.DeleteUndoMark(markId14, null);

        NXOpen.Session.UndoMarkId markId15;
        markId15 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Extrude");

        extrudeBuilder1.ParentFeatureInternal = false;

        NXOpen.Features.Feature feature2;
        feature2 = extrudeBuilder1.CommitFeature();

        theSession.DeleteUndoMark(markId15, null);

        theSession.SetUndoMarkName(markId11, "Extrude");

        Expression expression6 = extrudeBuilder1.Limits.StartExtend.Value;
        Expression expression7 = extrudeBuilder1.Limits.EndExtend.Value;

        extrudeBuilder1.Destroy();

        workPart.Expressions.Delete(expression5);

        // ----------------------------------------------
        //   Menu: Analysis->Measure Bodies...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId16;
        markId16 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

        MeasureBodyBuilder measureBodyBuilder1;

        measureBodyBuilder1 = workPart.MeasureManager.CreateMeasureBodyBuilder(nullNXObject);

        theSession.SetUndoMarkName(markId16, "Measure Bodies Dialog");

        Body[] bodies1 = new Body[1];
        Body   body1   = (Body)workPart.Bodies.FindObject("EXTRUDE(2)");

        bodies1[0] = body1;
        BodyDumbRule bodyDumbRule1;

        bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, true);

        SelectionIntentRule[] rules2 = new SelectionIntentRule[1];
        rules2[0] = bodyDumbRule1;
        measureBodyBuilder1.BodyCollector.ReplaceRules(rules2, false);

        NXOpen.Session.UndoMarkId markId17;
        markId17 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Bodies");

        theSession.DeleteUndoMark(markId17, null);

        NXOpen.Session.UndoMarkId markId18;
        markId18 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Measure Bodies");

        theSession.DeleteUndoMark(markId18, null);

        theSession.SetUndoMarkName(markId16, "Measure Bodies");

        measureBodyBuilder1.Destroy();


        MeasureBodies measureBodies1 = workPart.MeasureManager.NewMassProperties(workPart.UnitCollection.ToArray(), 1.0, bodies1);
        //Console.WriteLine(measureBodies1.Volume);

        // ----------------------------------------------
        //   Menu: File->Save
        // ----------------------------------------------
        PartSaveStatus partSaveStatus1;

        partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);

        partSaveStatus1.Dispose();
        // ----------------------------------------------
        //   Menu: Tools->Journal->Stop Recording
        // ----------------------------------------------


        Console.WriteLine("Finishing NX Journal. Part Saved.");

        //Write output file with dimensions of beam in current directory
        File.WriteAllText("Optimum_beam_dimensions.txt",
                          "Volume of Optimal Beam = " + ((measureBodies1.Volume) / 1000000000) + "m^3\r\nLength = 2m" +
                          "\r\nWidth = " + (width / 1000) + "m\r\nHeight = " + (height / 1000) + "m");
        Console.WriteLine("Beam dimensions written to file.");
    }
    //------------------------------------------------------------------------------
    // Callback Name: apply_cb
    // Following callback is associated with the "changeDialog" Styler item.
    // Input: eventObject - object of UIStyler.StylerEvent class
    //------------------------------------------------------------------------------
    //Following is Apply Callback - This function is responsible for creating Edge Blend.
    public NXOpen.UIStyler.DialogState apply_cb(NXOpen.UIStyler.StylerEvent eventObject)
    {
        try
        {
            Part workPart    = theSession.Parts.Work;
            Part displayPart = theSession.Parts.Display;

            // ----------------------------------------------
            //   Menu: Insert->Detail Feature->Edge Blend...
            // ----------------------------------------------
            Session.UndoMarkId      markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start");
            NXOpen.Features.Feature nullFeatures_Feature = null;

            NXOpen.Features.EdgeBlendBuilder edgeBlendBuilder1 = workPart.Features.CreateEdgeBlendBuilder(nullFeatures_Feature);

            theSession.SetUndoMarkName(markId1, "Edge Blend");
            Boolean featureAlerts1 = theSession.Preferences.Modeling.FeatureAlerts;

            ScCollector scCollector1 = workPart.ScCollectors.CreateCollector();

            NXOpen.Features.Block block1 = (NXOpen.Features.Block)workPart.Features.FindObject("BLOCK(1)");

            Boolean featureAlerts2 = theSession.Preferences.Modeling.FeatureAlerts;
            Boolean featureAlerts3 = theSession.Preferences.Modeling.FeatureAlerts;

            Edge[] seedEdges1        = new Edge[htEdges.Count];
            IDictionaryEnumerator en = htEdges.GetEnumerator();
            int EdgeIndex            = 0;
            while (en.MoveNext())
            {
                Edge edgeVar = (Edge)en.Value;;
                seedEdges1[EdgeIndex] = edgeVar;
                EdgeIndex            += 1;
            }

            EdgeMultipleSeedTangentRule edgeMultipleSeedTangentRule2 = workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(seedEdges1, 0.5, true);

            SelectionIntentRule[] rules2 = new SelectionIntentRule[1];
            rules2[0] = edgeMultipleSeedTangentRule2;

            scCollector1.ReplaceRules(rules2, false);
            Boolean featureAlerts4 = theSession.Preferences.Modeling.FeatureAlerts;

            Boolean            featureAlerts5 = theSession.Preferences.Modeling.FeatureAlerts;
            Session.UndoMarkId markId2        = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Edge Blend");
            //Following can set the Tolerance for Edge Blend.
            edgeBlendBuilder1.Tolerance          = changeReal6.ItemValue;
            edgeBlendBuilder1.AllInstancesOption = false;
            //Following can set the Remove Self Intersection option for the Edge Blend.
            edgeBlendBuilder1.RemoveSelfIntersection = changeToggle6.ItemValue;
            edgeBlendBuilder1.ConvexConcaveY         = false;
            edgeBlendBuilder1.RollOverSmoothEdge     = true;
            edgeBlendBuilder1.RollOntoEdge           = true;
            edgeBlendBuilder1.MoveSharpEdge          = true;
            edgeBlendBuilder1.OverlapOption          = NXOpen.Features.EdgeBlendBuilder.Overlap.AnyConvexityRollOver;
            edgeBlendBuilder1.BlendOrder             = NXOpen.Features.EdgeBlendBuilder.OrderOfBlending.ConvexFirst;
            edgeBlendBuilder1.SetbackOption          = NXOpen.Features.EdgeBlendBuilder.Setback.SeparateFromCorner;

            //Following sets the value for Blend Radius.
            int csIndex1 = edgeBlendBuilder1.AddChainset(scCollector1, changeStr0.ItemValue);
            NXOpen.Features.Feature feature1 = edgeBlendBuilder1.CommitFeature();

            theSession.DeleteUndoMark(markId2, null);
            edgeBlendBuilder1.Destroy();
            htEdges.Clear();
            changeLabel1.SetLabel("Select Edges (0)");
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("UI Styler", NXMessageBox.DialogType.Error, ex.Message);
        }
        // Callback acknowledged, do not terminate dialog
        // A return value of NXOpen.UIStyler.DialogState.ExitDialog will not be accepted
        // for this callback type. You must respond to your apply button.
        return(NXOpen.UIStyler.DialogState.ContinueDialog);
    }