Exemplo n.º 1
0
        // получаем параметры коррекции
        public bool getCutComParams()
        {
            NXOpen.CAM.VolumeBased25DMillingOperationBuilder operationBuilder;
            NXOpen.CAM.CylinderMillingBuilder cylinderMillingBuilder;

            // создаём метку до которой будем откатываться
            NXOpen.Session.UndoMarkId mark1 = NxSession.Session.SetUndoMark(Session.MarkVisibility.Invisible, "временная метка");

            if (CutComflag) // проверка, понят ли флаг
            {
                return(cutCom.Equals(NXOpen.CAM.NcmPlanarBuilder.CutcomTypes.None) ? false : true);
            }
            if (CutComHoleMillingFlag)
            {
                return(cutComHoleMilling.Equals(NXOpen.CAM.NcmHoleMachining.CutcomTypes.None) ? false : true);
            }

            try
            {
                operationBuilder = NxSession.Part.CAMSetup.CAMOperationCollection.CreateVolumeBased25dMillingOperationBuilder(Operation);
                cutCom           = operationBuilder.NonCuttingBuilder.CutcomType;
                UF_PARAM_TL_CutcomOutputContactPoint = operationBuilder.NonCuttingBuilder.CutcomOutputContactPoint;
                operationBuilder.Destroy();
                CutComflag = true; // поднимаем флаг, при удачном выполнении блока
                return(cutCom.Equals(NXOpen.CAM.NcmPlanarBuilder.CutcomTypes.None) ? false : true);
            }
            catch
            {
                try
                {
                    cylinderMillingBuilder = NxSession.Part.CAMSetup.CAMOperationCollection.CreateCylinderMillingBuilder(Operation);
                    cutComHoleMilling      = cylinderMillingBuilder.NonCuttingBuilder.CutcomType;
                    UF_PARAM_TL_CutcomOutputContactPoint = cylinderMillingBuilder.NonCuttingBuilder.CutcomOutputContactPoint;
                    cylinderMillingBuilder.Destroy();
                    CutComHoleMillingFlag = true; // поднимаем флаг, при удачном выполнении блока
                    return(cutComHoleMilling.Equals(NXOpen.CAM.NcmHoleMachining.CutcomTypes.None) ? false : true);
                }
                catch
                {
                    return(false);
                }
            }

            finally
            {
                NxSession.Session.UndoToMark(mark1, null);      // откатываемся к метке "mark1"
                NxSession.Session.DeleteUndoMark(mark1, null);  // удаляет метчку отката
            }
        }
Exemplo n.º 2
0
        public static PatternGeometry CreatePattern(int xNCopies, double xPitchDistance, int yNCopies, double yPitchDistance, Matrix4 mat = null, PatternGeometry features = null, params DisplayableObject[] obj)
        {
            Part workPart = theSession.Parts.Work;

            if (mat == null)
            {
                mat = new Matrix4();
                mat.Identity();
                mat.TransformToCsys(workPart.WCS.CoordinateSystem, ref mat);
            }
            NXOpen.Features.PatternGeometryBuilder patternGeometryBuilder1;
            patternGeometryBuilder1 = workPart.Features.CreatePatternGeometryBuilder(features);
            Direction xDirection;
            Direction yDirection;
            Vector3d  x      = mat.GetXAxis();
            Vector3d  y      = mat.GetYAxis();
            Point3d   origin = mat.GetCenter();
            bool      added1 = patternGeometryBuilder1.GeometryToPattern.Add(obj); //设置要阵列的对象

            patternGeometryBuilder1.PatternService.RectangularDefinition.UseYDirectionToggle = true;

            patternGeometryBuilder1.ReferencePoint.Point = workPart.Points.CreatePoint(origin);                   //指定参考点

            xDirection = workPart.Directions.CreateDirection(origin, x, SmartObject.UpdateOption.WithinModeling); //方向
            yDirection = workPart.Directions.CreateDirection(origin, y, SmartObject.UpdateOption.WithinModeling); //方向
            patternGeometryBuilder1.PatternService.RectangularDefinition.XDirection                   = xDirection;
            patternGeometryBuilder1.PatternService.RectangularDefinition.YDirection                   = yDirection;
            patternGeometryBuilder1.PatternService.RectangularDefinition.XSpacing.NCopies.Value       = xNCopies;       //要阵列的个数(包括本身)
            patternGeometryBuilder1.PatternService.RectangularDefinition.XSpacing.PitchDistance.Value = xPitchDistance; //设置节距
            patternGeometryBuilder1.PatternService.RectangularDefinition.YSpacing.NCopies.Value       = yNCopies;       //要阵列的个数(包括本身)
            patternGeometryBuilder1.PatternService.RectangularDefinition.YSpacing.PitchDistance.Value = yPitchDistance; //设置节距
            NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start ToolingBox");
            try
            {
                return(patternGeometryBuilder1.CommitFeature() as PatternGeometry);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("PatternUtils:CreatePattern:      " + ex.Message);
                throw ex;
            }
            finally
            {
                patternGeometryBuilder1.Destroy();
                theSession.UpdateManager.DoUpdate(markId);
                theSession.DeleteUndoMark(markId, "End ToolingBox");
            }
        }
        /// <summary>
        /// 创建圆柱特征
        /// </summary>
        /// <param name="zAxis">轴</param>
        /// <param name="centerPt">中心点</param>
        /// <param name="offset"></param>
        /// <param name="toolingBoxFeature"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static ToolingBox CreateToolingCylinder(Vector3d zAxis, Point3d centerPt, double[] offset, ToolingBox toolingBoxFeature = null, params TaggedObject[] objs)
        {
            Part workPart = theSession.Parts.Work;
            SelectionRuleFactory rules = new SelectionRuleFactory(objs.ToList());
            //ToolingBox nullToolingBox = null;
            ToolingBoxBuilder toolingBoxBuilder = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(toolingBoxFeature);

            toolingBoxBuilder.Type = ToolingBoxBuilder.Types.BoundedCylinder;
            Direction dir = workPart.Directions.CreateDirection(centerPt, zAxis, SmartObject.UpdateOption.WithinModeling);

            toolingBoxBuilder.AxisVector            = dir;
            toolingBoxBuilder.RadialOffset.Value    = offset[2];
            toolingBoxBuilder.OffsetPositiveZ.Value = offset[0];
            toolingBoxBuilder.OffsetNegativeZ.Value = offset[1];
            // toolingBoxBuilder.SingleOffset = false;
            ScCollector scCollector = toolingBoxBuilder.BoundedObject;

            scCollector.ReplaceRules(rules.CreateSelectionRule().ToArray(), false);
            toolingBoxBuilder.CalculateBoxSize();

            NXObject[] selections   = new NXObject[1];
            NXObject[] deselections = new NXObject[1];
            selections[0] = (NXObject)objs[0];
            toolingBoxBuilder.SetSelectedOccurrences(selections, deselections);
            toolingBoxBuilder.CalculateBoxSize();

            NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start ToolingBox");
            try
            {
                return(toolingBoxBuilder.CommitFeature() as ToolingBox);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.ToolingFeature.CreateToolingBox:错误:" + ex.Message);
                return(null);
            }
            finally
            {
                toolingBoxBuilder.Destroy();
                theSession.UpdateManager.DoUpdate(markId);
                theSession.DeleteUndoMark(markId, "End ToolingBox");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///更新
        /// </summary>
        public static void UpdateObject(NXOpen.Session.UndoMarkId markId, string name)
        {
            Part workPart = theSession.Parts.Work;

            theSession.Preferences.Modeling.UpdatePending = false;
            try
            {
                theSession.UpdateManager.DoUpdate(markId);
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("DeleteObject.UpdateObject:更新失败!" + ex.Message);
                throw ex;
            }
            finally
            {
                theSession.DeleteUndoMark(markId, name);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 删除部件
 /// </summary>
 /// <param name="comp">部件</param>
 public static void DeleteComponent(params NXOpen.Assemblies.Component[] comp)
 {
     theSession.UpdateManager.ClearErrorList();
     NXOpen.Session.UndoMarkId markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Delete");
     try
     {
         int nErrs1;
         nErrs1 = theSession.UpdateManager.AddToDeleteList(comp);
         bool notifyOnDelete2;
         notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete;
     }
     catch (Exception ex)
     {
         LogMgr.WriteLog("AssmbliesUtils:DeleteComponent:" + ex.Message);
     }
     finally
     {
         int nErrs2;
         nErrs2 = theSession.UpdateManager.DoUpdate(markId2);
     }
 }
Exemplo n.º 6
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");
            }
        }
        /// <summary>
        /// 创建方块盒
        /// </summary>
        /// <param name="matr">矩阵</param>
        /// <param name="centerPt">中心坐标</param>
        /// <param name="offset">偏置 offset[6]</param>
        /// <param name="toolingBoxFeature">方块盒特征</param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static ToolingBox CreateToolingBlockBox(Matrix3x3 matr, Point3d centerPt, double[] offset, ToolingBox toolingBoxFeature = null, params TaggedObject[] objs)
        {
            Part workPart = theSession.Parts.Work;
            SelectionRuleFactory rules = new SelectionRuleFactory(objs.ToList());
            //ToolingBox nullToolingBox = null;
            ToolingBoxBuilder toolingBoxBuilder = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(toolingBoxFeature);

            toolingBoxBuilder.Type = ToolingBoxBuilder.Types.BoundedBlock;
            toolingBoxBuilder.OffsetPositiveX.Value = offset[0];
            toolingBoxBuilder.OffsetNegativeX.Value = offset[1];
            toolingBoxBuilder.OffsetPositiveY.Value = offset[2];
            toolingBoxBuilder.OffsetNegativeY.Value = offset[3];
            toolingBoxBuilder.OffsetPositiveZ.Value = offset[4];
            toolingBoxBuilder.OffsetNegativeZ.Value = offset[5];
            toolingBoxBuilder.SingleOffset          = false;
            toolingBoxBuilder.SetBoxMatrixAndPosition(matr, centerPt);
            ScCollector scCollector = toolingBoxBuilder.BoundedObject;

            scCollector.ReplaceRules(rules.CreateSelectionRule().ToArray(), false);
            toolingBoxBuilder.CalculateBoxSize();
            NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start ToolingBox");
            try
            {
                return(toolingBoxBuilder.CommitFeature() as ToolingBox);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("Basic.ToolingFeature.CreateToolingBox:错误:" + ex.Message);
                return(null);
            }
            finally
            {
                toolingBoxBuilder.Destroy();
                theSession.UpdateManager.DoUpdate(markId);
                theSession.DeleteUndoMark(markId, "End ToolingBox");
            }
        }
Exemplo n.º 8
0
        static RevSurface ToRhinoRevSurface(NXOpen.Face face, FaceEx.FaceData faceData)
        {
            var bodyFeatures = face.GetBody().GetFeatures();

            var revolveFeature = bodyFeatures.FirstOrDefault(obj => obj is NXOpen.Features.Revolve);

            Curve  faceSectionCurve = default;
            double startRadian      = 0.0;
            double endRadian        = Math.PI * 2;

            if (revolveFeature != null)
            {
                NXOpen.Features.RevolveBuilder revolveBuilder = WorkPart.Features.CreateRevolveBuilder(revolveFeature);
                revolveBuilder.Section.GetOutputCurves(out var sectionCurves);

                startRadian = revolveBuilder.Limits.StartExtend.Value.Value * Math.PI / 180.0;

                endRadian = revolveBuilder.Limits.EndExtend.Value.Value * Math.PI / 180.0;

                revolveBuilder.Destroy();

                for (int i = 0; i < sectionCurves.Length; i++)
                {
                    var baseCurve = sectionCurves[i] as NXOpen.IBaseCurve;

                    var curveMidPt = baseCurve.GetPoint(0.5);
                    if (curveMidPt.DistanceTo(face.Tag).Distance < DistanceTolerance)
                    {
                        faceSectionCurve = baseCurve.ToRhinoCurve();
                        break;
                    }
                }
            }
            else
            {
                var faceBoundingBox = face.GetAlignedBoundingBox(faceData.Direction);

                var point1 = faceData.Point.Move(faceData.Direction, faceBoundingBox.Height * 1.5);

                var faceMidPoint = face.GetPoint();

                // 求与旋转方向垂直,并且位于面上的方向
                var verticalDirection = faceData.Direction.CrossProduct(faceMidPoint.Subtract(faceData.Point)).CrossProduct(faceData.Direction);

                var point2 = point1.Move(verticalDirection, faceBoundingBox.Length * 1.5);

                var point3 = point2.Move(faceData.Direction.Reverse(), faceBoundingBox.Height * 3);

                var point4 = point3.Move(verticalDirection.Reverse(), faceBoundingBox.Length * 1.5);

                NXOpen.Session.UndoMarkId undoMarkId = TheSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Calc Rev Profile");

                NXOpen.Body fourPointSurface = WorkPart.Features.CreateFourPointSurface(point1, point2, point3, point4);

                try
                {
                    NXOpen.Features.IntersectionCurve intersectionCurveFeature = WorkPart.Features.CreateIntersectionCurve(fourPointSurface.GetFaces(), face);

                    faceSectionCurve = (intersectionCurveFeature.GetEntities()[0] as NXOpen.Curve).ToRhino();

                    intersectionCurveFeature.Delete();

                    fourPointSurface.Delete();
                }
                catch (Exception)
                {
                    TheSession.UndoToMark(undoMarkId, "Calc Rev Profile");

                    Console.WriteLine($"无法创建面 {face.Tag} 的交线");

                    return(null);
                }
                finally
                {
                    TheSession.DeleteUndoMark(undoMarkId, "Calc Rev Profile");
                }
            }

            return(RevSurface.Create(faceSectionCurve, new Line(faceData.Point.ToRhino(), faceData.Point.Move(faceData.Direction, 10.0).ToRhino()), startRadian, endRadian));
        }