Example #1
0
 /// <summary>
 /// 设置颜色
 /// </summary>
 /// <param name="colorIndex">UG颜色ID</param>
 public static void SetColor(int colorIndex, NXOpen.Tag faceTag)
 {
     if (faceTag != NXOpen.Tag.Null)
     {
         Snap.NX.Face.Wrap(faceTag).Color = SnapEx.Create.WindowsColor(colorIndex);
     }
 }
Example #2
0
        public static void UpdateTabularNote(NXOpen.Tag tag)
        {
            int numberColumns, numberRows;

            _ufSession.Tabnot.AskNmColumns(tag, out numberColumns);
            _ufSession.Tabnot.AskNmRows(tag, out numberRows);
            for (int i = 0; i < numberColumns; i++)
            {
                NXOpen.Tag columnTag;
                _ufSession.Tabnot.AskNthColumn(tag, i, out columnTag);
                for (int j = 0; j < numberRows; j++)
                {
                    NXOpen.Tag rowTag;
                    _ufSession.Tabnot.AskNthRow(tag, j, out rowTag);
                    NXOpen.Tag cellTag;
                    _ufSession.Tabnot.AskCellAtRowCol(rowTag, columnTag, out cellTag);
                    var cellPrefs = new NXOpen.UF.UFTabnot.CellPrefs();
                    _ufSession.Tabnot.AskCellPrefs(cellTag, out cellPrefs);
                    cellPrefs.zero_display = NXOpen.UF.UFTabnot.ZeroDisplay.ZeroDisplayZero;// UF_TABNOT_zero_display_zero;
                    cellPrefs.text_density = 3;
                    _ufSession.Tabnot.SetCellPrefs(cellTag, ref cellPrefs);
                }
            }
            _ufSession.Draw.UpdateTabnot(tag);
            _ufSession.Tabnot.Update(tag);
        }
Example #3
0
        public static int UC6400(string viewName, NXOpen.Tag objectTag)
        {
            NXOpen.Utilities.JAM.StartUFCall();
            int errorCode = _uc6400(viewName, objectTag);

            NXOpen.Utilities.JAM.EndUFCall();
            return(errorCode);
        }
Example #4
0
        public static int UC6434(string cp1, int ip2, NXOpen.Tag np3, double[] rp4)
        {
            NXOpen.Utilities.JAM.StartUFCall();
            int errorCode = _uc6434(cp1, ip2, np3, rp4);

            NXOpen.Utilities.JAM.EndUFCall();
            return(errorCode);
        }
Example #5
0
        /// <summary>
        /// 干涉检查(1 -> there is interference  2 -> no interference  3 -> touching, that is coincident faces)
        /// </summary>
        public static bool CheckInterference(NXOpen.Tag targetBody, NXOpen.Tag toolBody)
        {
            var result    = true;
            var ufSession = NXOpen.UF.UFSession.GetUFSession();

            int[] r = new int[] { 0 };
            ufSession.Modl.CheckInterference(targetBody, 1, new NXOpen.Tag[] { toolBody }, r);
            result = !(r[0] == 3 || r[0] == 2);
            return(result);
        }
Example #6
0
 /// <summary>
 /// 根据类型自动设置相关参数
 /// </summary>
 public virtual void AutoAnalysis(CAMElectrode ele, NXOpen.Tag WorkGeometryGroup, NXOpen.Tag ProgramGroup, NXOpen.Tag MethodGroupRoot
                                  , CAMCutter CAMCutter, CAMCutter refCAMCutter
                                  )
 {
     if (AnalysisOperIsValid(ele))
     {
         CreateOper(WorkGeometryGroup, ProgramGroup, MethodGroupRoot, CAMCutter);
         if (refCAMCutter != null)
         {
             SetReferenceCutter(refCAMCutter);
         }
         AutoSet(ele);
     }
 }
Example #7
0
        public void CreateOper(NXOpen.Tag WorkGeometryGroup, NXOpen.Tag ProgramGroup, NXOpen.Tag MethodGroupRoot, CAMCutter CAMCutter, bool operIsValid = true)
        {
            this.WorkGeometryGroup = WorkGeometryGroup;
            this.ProgramGroup      = ProgramGroup;
            this.MethodGroupRoot   = MethodGroupRoot;
            this.CAMCutter         = CAMCutter;

            if (operIsValid)
            {
                //TODO 创建工序
                var operTag = CreateOper();

                int          count;
                NXOpen.Tag[] list;
                ufSession.Ncgroup.AskMemberList(ProgramGroup, out count, out list);
                int    index = -1;
                string name;
                for (int i = 0; i < count; i++)
                {
                    ufSession.Obj.AskName(list[i], out name);
                    if (name.Contains(AUTOCAM_SUBTYPE) && operTag != list[i])
                    {
                        var strIndex = name.Split('_').LastOrDefault();
                        var tempInt  = -1;
                        int.TryParse(strIndex, out tempInt);
                        if (tempInt > index)
                        {
                            index = tempInt;
                        }
                    }
                }

                //设置名称
                ufSession.Obj.SetName(operTag, string.Format("{0}_{1}", AUTOCAM_SUBTYPE, index + 1));

                //设置进给率和速度
                _SetFeedRate(CAMCutter.FeedRate, CAMCutter.Speed);

                //设置切深
                SetCutDepth(CAMCutter.CutDepth);

                //设置横越(移刀)
                Helper.SetFeedTraversal(OperTag, CAMCutter.FEED_TRAVERSAL);
            }
        }
Example #8
0
        public static void WriteTabularCell(int row, int column, string cellText, NXOpen.Tag tag, double text_Height = 3.5, string ugFont = "helios")
        {
            row    += 1;
            column += 1;
            var cellParams = new NXOpen.UF.UFDraw.TabnotCellParams();
            var eval_data  = new NXOpen.UF.UFDraw.TabnotCellEvalData();

            _ufSession.Draw.ReadTabnotCell(tag, row, column, out cellParams, out eval_data);
            cellParams.cell_text      = EdmDraw.EDMTableInfo.ChineseHandle(cellText);
            cellParams.horiz_just     = NXOpen.UF.UFDraw.TabnotJust.TabnotJustCenter; // UF_DRAW_tabnot_just_center;
            cellParams.vert_just      = NXOpen.UF.UFDraw.TabnotJust.TabnotJustMiddle; //UF_DRAW_tabnot_just_middle;
            cellParams.ug_text_height = text_Height;
            cellParams.ug_font        = ugFont;
            _ufSession.Draw.WriteTabnotCell(tag, row, column, ref cellParams);

            if (EDMTableInfo.IsHasChinese(cellText))
            {
                NXOpen.Tag columnTag;
                _ufSession.Tabnot.AskNthColumn(tag, column - 1, out columnTag);
                NXOpen.Tag rowTag;
                _ufSession.Tabnot.AskNthRow(tag, row - 1, out rowTag);
                NXOpen.Tag cellTag;
                _ufSession.Tabnot.AskCellAtRowCol(rowTag, columnTag, out cellTag);

                var mark = Snap.Globals.SetUndoMark(Snap.Globals.MarkVisibility.Invisible, "WriteTabularCell");
                try
                {
                    _ufSession.Tabnot.SetCellText(cellTag, EdmDraw.EDMTableInfo.ChineseHandle(cellText));
                    Snap.Globals.DeleteUndoMark(mark, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("WriteTabularCell {0}  {1}", ex.Message, ex.StackTrace);
                    Snap.Globals.UndoToMark(mark, null);
                }
            }
        }
Example #9
0
 public NX_CoordinateSystem(NXOpen.Tag tag, bool highlight) : base(tag, highlight)
 {
 }
Example #10
0
 public static void SetTabularRowHeight(int row, double width, NXOpen.Tag tag)
 {
     _ufSession.Draw.WriteTabnotRowHgt(tag, row + 1, width);
 }
Example #11
0
 public static void SetTabularColumnWidth(int col, double width, NXOpen.Tag tag)
 {
     _ufSession.Draw.WriteTabnotColWdt(tag, col + 1, width);
 }
Example #12
0
 internal static extern int _uc6400(string viewName, NXOpen.Tag objectTag);
Example #13
0
 internal static extern int _uc6434(string cp1, int ip2, NXOpen.Tag np3, double[] rp4);
Example #14
0
 /// <summary>
 /// 存放于当前工作部件中的对象
 /// </summary>
 /// <param name="handle"></param>
 public NX_Plane(NXOpen.Tag tag) : base(tag)
 {
 }
Example #15
0
 /// <summary>
 /// 存放于当前工作部件中的对象
 /// </summary>
 /// <param name="handle"></param>
 public NX_Point(NXOpen.Tag tag) : base(tag)
 {
 }
Example #16
0
 public NX_Body(NXOpen.Tag tag, bool highlight) : base(tag, highlight)
 {
 }
Example #17
0
 public NX_Point(NXOpen.Tag tag, bool highlight) : base(tag, highlight)
 {
 }
Example #18
0
 /// <summary>
 /// 存放于当前工作部件中的对象
 /// </summary>
 /// <param name="handle"></param>
 public NX_CoordinateSystem(NXOpen.Tag tag) : base(tag)
 {
 }
Example #19
0
        public static List <CAMCutter> CreateCutter(CAMElectrode ele, CNCConfig.CAMConfig camConfig, NXOpen.Tag cutterGroupRootTag, out CNCConfig.CAMConfig.ProjectInfo project)
        {
            var eleInfo             = ele.Electrode.GetElectrodeInfo();
            List <CAMCutter> result = new List <CAMCutter>();
            var info          = ele.Electrode.GetElectrodeInfo();
            var cutterConfigs = camConfig.FindCutterInfo(info.MAT_NAME);

            project = camConfig.Projects.Where(u => u.方案名称 == "自动").FirstOrDefault() ?? camConfig.Projects.Where(u => u.方案名称 == "自动").FirstOrDefault();
            if (project == null)
            {
                throw new Exception("配置工具未配置方案!");
            }

            var cutterStrs = new List <string>();

            project.Details.ForEach(u => {
                cutterStrs.Add(u.刀具);
                cutterStrs.Add(u.参考刀具);
            });
            cutterStrs = cutterStrs.Where(u => !string.IsNullOrEmpty(u)).ToList();
            cutterStrs = cutterStrs.Distinct().ToList();
            foreach (var item in cutterStrs)
            {
                var cutterConfig = cutterConfigs.FirstOrDefault(m => m.刀具名称 == item);
                if (cutterConfig != null)
                {
                    Action <double> action = (f) => {
                        var camCutter = new CAMCutter();
                        camCutter.AUTOCAM_TYPE    = AUTOCAM_TYPE.mill_planar;
                        camCutter.AUTOCAM_SUBTYPE = AUTOCAM_SUBTYPE.MILL;
                        camCutter.CutterName      = cutterConfig.刀具名称 + (f != 0 ? f.ToString() : "");
                        camCutter.TL_DIAMETER     = double.Parse(cutterConfig.直径) + (f * 2);
                        camCutter.TL_COR1_RAD     = double.Parse(cutterConfig.R角) + f;
                        camCutter.TL_COR1_RAD     = camCutter.TL_COR1_RAD < 0 ? 0 : camCutter.TL_COR1_RAD;
                        camCutter.TL_HEIGHT       = double.Parse(cutterConfig.刀长);
                        camCutter.TL_FLUTE_LN     = double.Parse(cutterConfig.刃长);
                        camCutter.TL_NUMBER       = int.Parse(cutterConfig.刀号);
                        camCutter.TL_ADJ_REG      = int.Parse(cutterConfig.补正号);
                        camCutter.Speed           = double.Parse(cutterConfig.转速);
                        camCutter.FeedRate        = double.Parse(cutterConfig.进给);
                        camCutter.FEED_TRAVERSAL  = double.Parse(cutterConfig.横越);
                        camCutter.CutDepth        = double.Parse(cutterConfig.切深);
                        result.Add(camCutter);
                    };

                    action(0);

                    if (eleInfo.FINISH_NUMBER > 0)  //精
                    {
                        action(eleInfo.FINISH_SPACE);
                    }

                    if (eleInfo.MIDDLE_NUMBER > 0)  //中
                    {
                        action(eleInfo.MIDDLE_SPACE);
                    }

                    if (eleInfo.ROUGH_NUMBER > 0)  //粗
                    {
                        action(eleInfo.ROUGH_SPACE);
                    }
                }
                else
                {
                    throw new Exception("配置工具方案刀具配置异常!");
                }
            }
            result = Helper.CreateCutter(result, cutterGroupRootTag);
            return(result);
        }
Example #20
0
        /// <summary>
        /// 存放于当前工作部件中的对象
        /// </summary>
        /// <param name="handle"></param>
        public NX_Edge(NXOpen.Tag tag) : base(tag)
        {

        }
Example #21
0
        public NX_Edge(NXOpen.Tag tag, bool highlight) : base(tag, highlight)
        {

        }
Example #22
0
        static List <Snap.Position> GetFacePoints(Snap.NX.Face face, ProbeData data, double max_facet_size = 1)
        {
            var mark      = Snap.Globals.SetUndoMark(Globals.MarkVisibility.Visible, "GetFacePoints");
            var positions = new List <Snap.Position>();

            #region old code
            var parameters = new UFFacet.Parameters();

            var ufSession = NXOpen.UF.UFSession.GetUFSession();
            var facet     = ufSession.Facet;
            facet.AskDefaultParameters(out parameters);
            parameters.max_facet_edges        = 3;
            parameters.specify_max_facet_size = true;
            parameters.max_facet_size         = 1;

            NXOpen.Tag facet_model = NXOpen.Tag.Null;
            facet.FacetSolid(face.NXOpenTag, ref parameters, out facet_model);

            if (facet_model == NXOpen.Tag.Null)
            {
                return(positions);
            }
            NXOpen.Tag solid = NXOpen.Tag.Null;
            facet.AskSolidOfModel(facet_model, out solid);
            if (solid != face.NXOpenTag)
            {
                return(positions);
            }

            int  facet_id = NXOpen.UF.UFConstants.UF_FACET_NULL_FACET_ID;
            bool isWhile  = true;
            while (isWhile)
            {
                facet.CycleFacets(facet_model, ref facet_id);
                if (facet_id != NXOpen.UF.UFConstants.UF_FACET_NULL_FACET_ID)
                {
                    int num_vertices = 0;
                    facet.AskNumVertsInFacet(facet_model, facet_id, out num_vertices);
                    if (num_vertices == 3)
                    {
                        var vertices = new double[num_vertices, 3];
                        facet.AskVerticesOfFacet(facet_model, facet_id, out num_vertices, vertices);
                        for (int i = 0; i < num_vertices; i++)
                        {
                            int pt_status = 0;
                            var position  = new Snap.Position(vertices[i, 0], vertices[i, 1], vertices[i, 2]);
                            ufSession.Modl.AskPointContainment(position.Array, face.NXOpenTag, out pt_status);
                            if (0x1 == pt_status || 0x3 == pt_status)
                            {
                                positions.Add(position);
                            }
                        }
                    }
                }
                else
                {
                    isWhile = false;
                }
            }

            ufSession.Obj.DeleteObject(facet_model);
            positions = positions.Distinct().ToList();
            #endregion

            var edges = face.EdgeCurves.ToList();
            //过滤小于探球半径的点
            foreach (var item in positions.ToList())
            {
                if (IsLessthanProbeR(edges, item, data))
                {
                    positions.Remove(item);
                }
            }
            Snap.Globals.UndoToMark(mark, null);

            return(positions);
        }
Example #23
0
 internal void SetTag(NXOpen.Tag tag)
 {
     this.m_tag = tag;
 }
Example #24
0
        public static List <ICAMOper> CreateCamOper(
            NXOpen.Tag WorkGeometryGroup,
            NXOpen.Tag ProgramGroup,
            NXOpen.Tag MethodGroupRoot,
            NXOpen.Tag cutterGroupRootTag,
            CAMElectrode ele,
            CNCConfig.CAMConfig.ProjectInfo project,
            List <CAMCutter> cutterDetails,
            double fireNum
            )
        {
            var result = new List <ICAMOper>();

            foreach (var item in project.Details)
            {
                var operConfig = ele.CamConfig.Operations.FirstOrDefault(m => m.显示名称 == item.工序);
                Func <string, CAMCutter> GetCutterAction = (s) => {
                    var c = cutterDetails.FirstOrDefault(m => m.CutterName == s);
                    if (ele.CamConfig.SparkPosition == CNCConfig.CAMConfig.E_SparkPosition.CheatKnife ||
                        ele.CamConfig.SparkPosition == CNCConfig.CAMConfig.E_SparkPosition.CheatKnifeZ
                        )
                    {
                        var tempC = cutterDetails.FirstOrDefault(m => m.CutterName == s + fireNum.ToString());
                        if (tempC != null)
                        {
                            c = tempC;
                        }
                    }
                    return(c);
                };
                var cutter    = GetCutterAction(item.刀具);
                var refCutter = cutterDetails.FirstOrDefault(m => m.CutterName == item.参考刀具);

                if (operConfig == null)
                {
                    throw new Exception("配置工具方案工序配置异常!");
                }
                ICAMOper camOper = null;
                switch (operConfig.模版类型)
                {
                case CNCConfig.CAMConfig.S_OperationTemplate.EACT_AUTOCAM:
                {
                    switch (GetEnumByKey(operConfig.模板名称))
                    {
                    case E_TmplateOper.FACE_MILLING_KC:
                    {
                        camOper = new JYTools_FACE_MILLING_KC_Oper();
                        break;
                    }
                    }
                    break;
                }

                default:
                {
                    switch (GetEnumByKey(operConfig.模板名称))
                    {
                    case E_TmplateOper.FACE_MILLING_TOP:
                    {
                        camOper = new WsqAutoCAM_FACE_MILLING_TOP_Oper();
                        break;
                    }

                    case E_TmplateOper.CAVITY_MILL_C:
                    {
                        camOper = new WsqAutoCAM_CAVITY_MILL_C_Oper();
                        break;
                    }

                    case E_TmplateOper.CAVITY_PLANAR_MILL:
                    {
                        camOper = new WsqAutoCAM_CAVITY_PLANAR_MILL_Oper();
                        break;
                    }

                    case E_TmplateOper.CAVITY_MILL_REF:
                    {
                        camOper = new WsqAutoCAM_CAVITY_MILL_REF_Oper();
                        break;
                    }

                    case E_TmplateOper.FACE_MILLING_BASE:
                    {
                        camOper = new WsqAutoCAM_FACE_MILLING_BASE_Oper();
                        break;
                    }

                    case E_TmplateOper.FACE_MILLING:
                    {
                        camOper = new WsqAutoCAM_FACE_MILLING_Oper();
                        break;
                    }

                    case E_TmplateOper.PLANAR_MILL_BASE:
                    {
                        camOper = new WsqAutoCAM_PLANAR_MILL_BASE_Oper();
                        break;
                    }

                    case E_TmplateOper.PLANAR_MILL:
                    {
                        camOper = new WsqAutoCAM_PLANAR_MILL_Oper();
                        break;
                    }

                    case E_TmplateOper.ZLEVEL_PROFILE_STEEP:
                    {
                        camOper = new WsqAutoCAM_ZLEVEL_PROFILE_STEEP_Oper();
                        break;
                    }

                    case E_TmplateOper.ZLEVEL_CORNER:
                    {
                        camOper = new WsqAutoCAM_ZLEVEL_CORNER_Oper();
                        break;
                    }

                    case E_TmplateOper.CONTOUR_AREA_NON_STEEP:
                    {
                        camOper = new WsqAutoCAM_CONTOUR_AREA_NON_STEEP_Oper();
                        break;
                    }

                    case E_TmplateOper.FLOWCUT_REF_TOOL:
                    {
                        camOper = new WsqAutoCAM_FLOWCUT_REF_TOOL_Oper();
                        break;
                    }

                    case E_TmplateOper.FACE_MILLING_CORNER:
                    {
                        camOper = new WsqAutoCAM_FACE_MILLING_CORNER_Oper();
                        break;
                    }

                    case E_TmplateOper.CONTOUR_TEXT:
                    {
                        camOper = new WsqAutoCAM_CONTOUR_TEXT_Oper();
                        break;
                    }
                    }
                    break;
                }
                }


                if (camOper != null)
                {
                    result.Add(camOper);
                    camOper.FRIENUM = fireNum;
                    camOper.AutoAnalysis(ele, WorkGeometryGroup, ProgramGroup, MethodGroupRoot, cutter, refCutter);
                    if (item.切深 > 0)
                    {
                        camOper.SetCutDepth(item.切深);
                    }

                    if (item.进给 > 0)
                    {
                        camOper.SetFeedRate(item.进给);
                    }
                }
            }
            return(result);
        }
Example #25
0
 /// <summary>
 /// 存放于当前工作部件中的对象
 /// </summary>
 /// <param name="handle"></param>
 public NX_Body(NXOpen.Tag tag) : base(tag)
 {
 }