Beispiel #1
0
 internal static Snap.NX.DatumAxis CreateDatumAxis(Snap.Position origin, Vector direction)
 {
     NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
     NXOpen.Features.DatumAxisBuilder featureBuilder = workPart.Features.CreateDatumAxisBuilder(null);
     featureBuilder.Type = NXOpen.Features.DatumAxisBuilder.Types.PointAndDir;
     NXOpen.Direction direction2 = workPart.Directions.CreateDirection((Point3d)origin, (Vector3d)direction, SmartObject.UpdateOption.WithinModeling);
     featureBuilder.IsAssociative  = true;
     featureBuilder.IsAxisReversed = false;
     featureBuilder.Vector         = direction2;
     featureBuilder.Point          = workPart.Points.CreatePoint((Point3d)origin);
     NXOpen.Features.Feature feature = (NXOpen.Features.Feature)Snap.NX.Feature.CommitFeature(featureBuilder);
     featureBuilder.Destroy();
     return(new Snap.NX.DatumAxis((DatumAxisFeature)feature));
 }
Beispiel #2
0
        /// <summary>
        /// 投影点
        /// </summary>
        /// <param name="features"></param>
        /// <param name="point_to_project">要投影的点</param>
        /// <param name="plane_to_project_to">投影到的平面</param>
        public static ProjectCurve CreateProjectCurve(this FeatureCollection features, Point point_to_project, Plane plane_to_project_to)
        {
            NXOpen.Features.ProjectCurveBuilder projectCurveBuilder = features.CreateProjectCurveBuilder(null);

            projectCurveBuilder.CurveFitData.Tolerance = 0.025399999999999999;

            projectCurveBuilder.CurveFitData.AngleTolerance = 0.5;

            projectCurveBuilder.ProjectionDirectionMethod = NXOpen.Features.ProjectCurveBuilder.DirectionType.AlongFaceNormal;

            projectCurveBuilder.AngleToProjectionVector.RightHandSide = "0";

            NXOpen.Direction direction1 = WorkPart.Directions.CreateDirection(plane_to_project_to.Origin, plane_to_project_to.Normal, NXOpen.SmartObject.UpdateOption.WithinModeling);

            projectCurveBuilder.ProjectionVector = direction1;

            projectCurveBuilder.SectionToProject.DistanceTolerance = 0.025399999999999999;

            projectCurveBuilder.SectionToProject.ChainingTolerance = 0.024129999999999999;

            projectCurveBuilder.SectionToProject.AngleTolerance = 0.5;

            projectCurveBuilder.PlaneToProjectTo = plane_to_project_to;

            projectCurveBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints);

#if NX12
            NXOpen.CurveDumbRule curveDumbRule1 = (WorkPart as BasePart).ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project });
#else
            NXOpen.CurveDumbRule curveDumbRule1 = WorkPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project });
#endif
            projectCurveBuilder.SectionToProject.AllowSelfIntersection(true);

            NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1] {
                curveDumbRule1
            };
            projectCurveBuilder.SectionToProject.AddToSection(rules1, null, null, null, new Point3d(), NXOpen.Section.Mode.Create, false);

            ProjectCurve projectCurve = (ProjectCurve)projectCurveBuilder.Commit();

            projectCurveBuilder.SectionToProject.CleanMappingData();

            projectCurveBuilder.Destroy();

            return(projectCurve);
        }
        /// <summary>
        /// 创建尺寸约束
        /// </summary>
        /// <param name="line1"></param>
        /// <param name="line2"></param>
        /// <param name="dimOrigin"></param>
        /// <param name="method"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Expression CreateDimForLine(Line line1, Line line2, double[] dimOrigin, NXOpen.Annotations.DimensionMeasurementBuilder.MeasurementMethod method, InferSnapType.SnapType type)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Annotations.Dimension        nullNXOpen_Annotations_Dimension = null;
            NXOpen.SketchLinearDimensionBuilder sketchLinearDimensionBuilder1;
            sketchLinearDimensionBuilder1 = workPart.Sketches.CreateLinearDimensionBuilder(nullNXOpen_Annotations_Dimension);
            sketchLinearDimensionBuilder1.Origin.SetInferRelativeToGeometry(true);                                                      //如果未应用其他关联性,则在提交时推断关联几何关系
            sketchLinearDimensionBuilder1.Measurement.Method       = method;                                                            //测量方向
            sketchLinearDimensionBuilder1.Driving.DrivingMethod    = NXOpen.Annotations.DrivingValueBuilder.DrivingValueMethod.Driving; //驱动方法
            sketchLinearDimensionBuilder1.Origin.Plane.PlaneMethod = NXOpen.Annotations.PlaneBuilder.PlaneMethodType.XyPlane;           //平面类型
            NXOpen.Direction nullNXOpen_Direction = null;
            sketchLinearDimensionBuilder1.Measurement.Direction = nullNXOpen_Direction;                                                 //测量方向
            NXOpen.View nullNXOpen_View = null;
            sketchLinearDimensionBuilder1.Measurement.DirectionView = nullNXOpen_View;                                                  //测量视图
            sketchLinearDimensionBuilder1.Style.DimensionStyle.NarrowDisplayType = NXOpen.Annotations.NarrowDisplayOption.None;         //设置窄尺寸样式
            NXOpen.Point3d point2_3 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            sketchLinearDimensionBuilder1.SecondAssociativity.SetValue(NXOpen.InferSnapType.SnapType.Mid, line2, workPart.ModelingViews.WorkView, line2.EndPoint, null, nullNXOpen_View, point2_3);

            NXOpen.Point3d point2_4 = new NXOpen.Point3d(0.0, 0.0, 0.0);
            sketchLinearDimensionBuilder1.FirstAssociativity.SetValue(type, line1, workPart.ModelingViews.WorkView, line1.EndPoint, null, nullNXOpen_View, point2_4);
            NXOpen.Point3d point3 = new NXOpen.Point3d(dimOrigin[0], dimOrigin[1], dimOrigin[2]);
            sketchLinearDimensionBuilder1.Origin.Origin.SetValue(null, nullNXOpen_View, point3);

            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = sketchLinearDimensionBuilder1.Commit();
                Expression exp = sketchLinearDimensionBuilder1.Driving.ExpressionValue;
                return(exp);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("SketchUtils:CreateDimForLine:" + ex.Message);
                throw ex;
            }
            finally
            {
                sketchLinearDimensionBuilder1.Destroy();
            }
        }
Beispiel #4
0
        internal static Snap.NX.Extrude CreateExtrude(Snap.NX.Section section, Vector axis, Snap.Number[] extents, Snap.Number draftAngle, bool offset, Snap.Number[] offsetValues, bool createSheet)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.ExtrudeBuilder featureBuilder = workPart.Features.CreateExtrudeBuilder(null);
            featureBuilder.DistanceTolerance     = Globals.DistanceTolerance;
            featureBuilder.BooleanOperation.Type = BooleanOperation.BooleanType.Create;
            if (createSheet)
            {
                featureBuilder.FeatureOptions.BodyType = FeatureOptions.BodyStyle.Sheet;
            }
            featureBuilder.Limits.StartExtend.Value.RightHandSide = extents[0].ToString();
            featureBuilder.Limits.EndExtend.Value.RightHandSide   = extents[1].ToString();
            featureBuilder.Offset.Option = NXOpen.GeometricUtilities.Type.NoOffset;
            if (offset)
            {
                featureBuilder.Offset.Option = NXOpen.GeometricUtilities.Type.NonsymmetricOffset;
                featureBuilder.Offset.StartOffset.RightHandSide = offsetValues[0].ToString();
                featureBuilder.Offset.EndOffset.RightHandSide   = offsetValues[1].ToString();
            }
            double num = Snap.Number.Parse(Snap.Number.NullToZero(draftAngle).ToString());

            if (System.Math.Abs(num) < 0.001)
            {
                featureBuilder.Draft.DraftOption = SimpleDraft.SimpleDraftType.NoDraft;
            }
            else
            {
                featureBuilder.Draft.DraftOption = SimpleDraft.SimpleDraftType.SimpleFromProfile;
            }
            featureBuilder.Draft.FrontDraftAngle.RightHandSide = Snap.Number.ToString(num);
            featureBuilder.Section = (NXOpen.Section)section;
            Point3d  origin = new Point3d(30.0, 0.0, 0.0);
            Vector3d vector = new Vector3d(axis.X, axis.Y, axis.Z);

            NXOpen.Direction direction = workPart.Directions.CreateDirection(origin, vector, SmartObject.UpdateOption.WithinModeling);
            featureBuilder.Direction = direction;
            NXOpen.Features.Extrude extrude = (NXOpen.Features.Extrude)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return(new Snap.NX.Extrude(extrude));
        }
Beispiel #5
0
        /// <summary>
        /// 投影点
        /// </summary>
        /// <param name="features"></param>
        /// <param name="point_to_project">要投影的点</param>
        /// <param name="faces_to_project_to">投影到的面</param>
        /// <param name="project_direction3d">投影方向,正反向均可</param>
        /// <returns></returns>
        public static ProjectCurve CreateProjectCurve(this FeatureCollection features, Point point_to_project, Face[] faces_to_project_to, Vector3d project_direction3d)
        {
            NXOpen.Features.ProjectCurveBuilder projectCurveBuilder = features.CreateProjectCurveBuilder(null);

            projectCurveBuilder.CurveFitData.Tolerance = 0.01;

            projectCurveBuilder.CurveFitData.AngleTolerance = 0.5;

            projectCurveBuilder.ProjectionDirectionMethod = NXOpen.Features.ProjectCurveBuilder.DirectionType.AlongVector;

            projectCurveBuilder.AngleToProjectionVector.RightHandSide = "0";

            projectCurveBuilder.SectionToProject.DistanceTolerance = 0.01;

            projectCurveBuilder.SectionToProject.ChainingTolerance = 0.0095;

            projectCurveBuilder.SectionToProject.AngleTolerance = 0.5;

            projectCurveBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints);

#if NX12
            NXOpen.CurveDumbRule curveDumbRule1 = (WorkPart as BasePart).ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project });
#else
            NXOpen.CurveDumbRule curveDumbRule1 = WorkPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project });
#endif

            projectCurveBuilder.SectionToProject.AllowSelfIntersection(true);

            NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1] {
                curveDumbRule1
            };
            projectCurveBuilder.SectionToProject.AddToSection(rules1, null, null, null, new Point3d(), NXOpen.Section.Mode.Create, false);

            NXOpen.ScCollector scCollector = WorkPart.ScCollectors.CreateCollector();

#if NX12
            NXOpen.FaceDumbRule faceDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleFaceDumb(faces_to_project_to);
#else
            NXOpen.FaceDumbRule faceDumbRule = WorkPart.ScRuleFactory.CreateRuleFaceDumb(faces_to_project_to);
#endif

            NXOpen.SelectionIntentRule[] rules2 = new NXOpen.SelectionIntentRule[1] {
                faceDumbRule
            };
            scCollector.ReplaceRules(rules2, false);

            bool added1 = projectCurveBuilder.FaceToProjectTo.Add(scCollector);

            NXOpen.Direction direction = WorkPart.Directions.CreateDirection(new Point3d(), project_direction3d, NXOpen.SmartObject.UpdateOption.WithinModeling);

            projectCurveBuilder.ProjectionVector = direction;

            projectCurveBuilder.ProjectionOption = ProjectCurveBuilder.ProjectionOptionType.ProjectBothSides;

            ProjectCurve nXObject = (ProjectCurve)projectCurveBuilder.Commit();

            projectCurveBuilder.SectionToProject.CleanMappingData();

            projectCurveBuilder.Destroy();

            return(nXObject);
        }