예제 #1
0
        public NxOperationGroup(IEnumerable <TaggedObject> taggedObjects, string machineName)
        {
            var objects = taggedObjects as IList <TaggedObject> ?? taggedObjects.ToList();

            if (!objects.OfType <NXOpen.CAM.Operation>().Any() && !objects.OfType <NCGroup>().Any())
            {
                throw new Exception("Не выбрана операция или группа операций!");
            }

            MachineName   = machineName;
            TaggedObjects = objects;
            _taggedObject = TaggedObjects.FirstOrDefault() as CAMObject;
            if (_taggedObject == null)
            {
                throw new Exception("Не выбрана операция или группа операций!");
            }

            if (_taggedObject is NXOpen.CAM.Operation)
            {
                NxOperations = GetOperations(_taggedObject as NXOpen.CAM.Operation);
            }
            else if (_taggedObject is NCGroup)
            {
                NxOperations = GetOperations(_taggedObject as NCGroup);
            }
        }
예제 #2
0
        public NXSessionInfo(Session session, UFSession ufsession)
        {
            theSession   = session;
            theUFSession = ufsession;

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

            part_tag = theUFSession.Part.AskDisplayPart();
            theUFSession.Part.AskPartName(part_tag, out part_name);

            OperationCollection opers = displayPart.CAMSetup.CAMOperationCollection;
            NCGroupCollection   ncgrc = displayPart.CAMSetup.CAMGroupCollection;

            MCSManager.Instance().McsListClear();

            foreach (CAMObject camobj in ncgrc.ToArray())
            {
                if (camobj is OrientGeometry)
                {
                    mcsobj   = camobj;
                    mcs_name = camobj.Name;
                    mcs_geometry.Add(mcs_name);
                    workpice_geometry.Add(mcs_name);

                    MillOrientGeomBuilder     millOrientGeom = displayPart.CAMSetup.CAMGroupCollection.CreateMillOrientGeomBuilder(mcsobj);
                    CartesianCoordinateSystem cartesianCoordinateSystem;
                    cartesianCoordinateSystem = millOrientGeom.Mcs;
                    nmx    = cartesianCoordinateSystem.Orientation;
                    origin = cartesianCoordinateSystem.Origin;
                    MCSManager.Instance().AddValue(nmx, mcs_name, origin);
                }
                if (camobj is FeatureGeometry)
                {
                    workpice_geometry.Add(camobj.Name);
                }

                if (camobj is NXOpen.CAM.Operation)
                {
                    opName.Add(camobj.Name);

                    //      NXSessionManager.Instance.OperationList.Add(camobj) ;
                    //  MessageBox.Show(camobj.Name);
                }
            }

            RaisePropertyChanged("GetMcsGeometry");
            RaisePropertyChanged("GetWorkPiceGeometry");
            RaisePropertyChanged("TheSession");
        }
        private static void GetFeatureGeometryList(CAMObject camObject, ref List <FeatureGeometry> featureGeometryList)
        {
            dynamic nextFeature;

            if (camObject.GetType() == typeof(FeatureGeometry))
            {
                featureGeometryList.Add((FeatureGeometry)camObject);
                nextFeature = (FeatureGeometry)camObject;
                GetFeatureGeometryList((CAMObject)nextFeature.GetParent(), ref featureGeometryList);
            }
            else if (camObject.GetType() == typeof(OrientGeometry))
            {
                nextFeature = (OrientGeometry)camObject;
                GetFeatureGeometryList((CAMObject)nextFeature.GetParent(), ref featureGeometryList);
            }
        }
예제 #4
0
 /// <summary>
 /// 获取程序组最小半径
 /// </summary>
 /// <param name="groups"></param>
 /// <returns></returns>
 public void GetGroupTool(List <NCGroup> groups, out double toolMinNumber, out double diaMin)
 {
     diaMin        = 99999;
     toolMinNumber = 9999;
     foreach (NCGroup np in groups)
     {
         CAMObject     obj   = np.GetMembers()[0];
         NCGroup       tool  = (obj as NXOpen.CAM.Operation).GetParent(CAMSetup.View.MachineTool);
         ToolDataModel model = new ToolDataModel(tool);
         if (diaMin > model.ToolDia)
         {
             diaMin = model.ToolDia;
         }
         if (toolMinNumber > model.ToolNumber)
         {
             toolMinNumber = model.ToolNumber;
         }
     }
 }
예제 #5
0
        public NxOperationGroup(TaggedObject taggedObject, string additionalToolName)
        {
            MachineName   = additionalToolName;
            _taggedObject = taggedObject as CAMObject;
            // todo подумать на выбросом исключения. может просто возврат?
            if (_taggedObject == null)
            {
                throw new Exception("Не выбрана операция или группа операций!");
            }

            if (_taggedObject is NXOpen.CAM.Operation)
            {
                NxOperations = GetOperations(_taggedObject as NXOpen.CAM.Operation);
            }
            else if (_taggedObject is NCGroup)
            {
                NxOperations = GetOperations(_taggedObject as NCGroup);
            }
        }
예제 #6
0
 /// <summary>
 /// 设置切削进给
 /// </summary>
 /// <param name="feeds"></param>
 public void SetFeeds(int feeds)
 {
     try
     {
         NXOpen.CAM.CAMObject[] params1 = new CAMObject[1] {
             this.Oper
         };
         NXOpen.CAM.ObjectsFeedsBuilder objectsFeedsBuilder1;
         objectsFeedsBuilder1 = workPart.CAMSetup.CreateFeedsBuilder(params1);
         objectsFeedsBuilder1.FeedsBuilder.FeedCutBuilder.Value = feeds;
         objectsFeedsBuilder1.FeedsBuilder.RecalculateData(NXOpen.CAM.FeedsBuilder.RecalcuateBasedOn.SurfaceSpeed);
         NXOpen.NXObject nXObject1;
         nXObject1 = objectsFeedsBuilder1.Commit();
         objectsFeedsBuilder1.Destroy();
     }
     catch (NXException ex)
     {
         throw ex;
     }
 }
예제 #7
0
        private void SuperGridOperPanel_RowClick(object sender, GridRowClickEventArgs e)
        {
            //取得使用者選取的OP名稱
            ListSelOper = new List <string>();
            SelectedElementCollection OperSelCollection = OperPanel.GetSelectedElements();

            foreach (GridRow item in OperSelCollection)
            {
                ListSelOper.Add(item.Cells[1].Value.ToString());
                //CaxLog.ShowListingWindow(item.Cells[0].Value.ToString());//可以看出debug中item的值會顯示GridRow的型態
            }

            //這邊設定NX中是否顯示加工路徑為->單條顯示or多條顯示
            NXOpen.CAM.Preferences preferences1 = theSession.CAMSession.CreateCamPreferences();
            if (ListSelOper.Count == 1)
            {
                preferences1.ReplayRefreshBeforeEachPath = true;
                preferences1.Commit();
                preferences1.Destroy();
            }
            else if (ListSelOper.Count > 1)
            {
                preferences1.ReplayRefreshBeforeEachPath = false;
                preferences1.Commit();
                preferences1.Destroy();
            }

            foreach (string SelectOper in ListSelOper)
            {
                for (int i = 0; i < OperationObj.Length; i++)
                {
                    if (SelectOper == OperationObj[i].Name)
                    {
                        NXOpen.CAM.CAMObject[] tempObjToCreateImg = new CAMObject[1];
                        tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationObj[i];
                        workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg);
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// 傳入型別為NXOpen.CAM.Tool的物件,取得該Tool的刀號
        /// </summary>
        /// <param name="tool"></param>
        /// <returns></returns>
        public static string AskToolNumber(CAMObject tool)
        {
            string ToolNumber = "";

            try
            {
                if (tool is NXOpen.CAM.Tool)
                {
                    ToolBuilder toolBuilder = displayPart.CAMSetup.CAMGroupCollection.CreateDrillStepToolBuilder(tool);
                    ToolNumber = toolBuilder.TlNumberBuilder.Value.ToString();
                    return(ToolNumber);
                }
                else
                {
                    return(ToolNumber = "");
                }
            }
            catch (System.Exception ex)
            {
                return(ToolNumber = "");
            }
        }
        public static int GetDimensions(string[] args)
        {
            IntPtr zero;
            string operationName;

            _theUfSession.Mom.AskMom(IntPtr.Zero, out zero);
            _theUfSession.Mom.AskString(zero, "operation_name", out operationName);

            var workPart  = _theSession.Parts.Work;
            var setup     = workPart.CAMSetup;
            var operation = setup.CAMOperationCollection.FindObject(operationName);

            CAMObject geometryView = (CAMObject)operation.GetParent(CAMSetup.View.Geometry);
            List <FeatureGeometry> featureGeometryList = new List <FeatureGeometry>();

            GetFeatureGeometryList(geometryView, ref featureGeometryList);

            double[] result = GetWorkpieseDimension(featureGeometryList, setup);

            _theUfSession.Mom.SetDoubleArray(zero, "part_dimensions", 3, result);


            return(-1);
        }
예제 #10
0
        private void ShowToolPath()
        {
            NXOpen.CAM.Preferences preferences1 = theSession.CAMSession.CreateCamPreferences();
            if (DicSelOper.Count == 1)
            {
                preferences1.ReplayRefreshBeforeEachPath = true;
                preferences1.Commit();
                preferences1.Destroy();
            }
            else if (DicSelOper.Count > 1)
            {
                preferences1.ReplayRefreshBeforeEachPath = false;
                preferences1.Commit();
                preferences1.Destroy();
            }

            foreach (NXOpen.CAM.NCGroup ncGroup in NCGroupAry)
            {
                if (CurrentNCGroup != ncGroup.Name)
                {
                    continue;
                }
                for (int i = 0; i < OperationAry.Length; i++)
                {
                    //取得父層的群組(回傳:NCGroup XXXX)
                    string NCProgramTag = OperationAry[i].GetParent(CAMSetup.View.ProgramOrder).ToString();
                    NCProgramTag = Regex.Replace(NCProgramTag, "[^0-9]", "");
                    NXOpen.CAM.CAMObject[] tempObjToCreateImg = new CAMObject[1];

                    foreach (KeyValuePair <int, ListViewItem> kvp in DicSelOper)
                    {
                        string tempOper = kvp.Value.Text;
                        //如果選擇發那科控制器,則取代P為O才能看路徑
                        if (chb_Fanuc.Checked == true)
                        {
                            tempOper = tempOper.Replace("P", "O");
                        }
                        if (tempOper.Split().Length > 1)
                        {
                            tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                        }
                        if (NCProgramTag == ncGroup.Tag.ToString() && tempOper == CaxOper.AskOperNameFromTag(OperationAry[i].Tag))
                        {
                            tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationAry[i];
                            workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg);
                        }

                        /*
                         * if (chb_Fanuc.Checked == true)
                         * {
                         *  tempOper = tempOper.Replace("P", "O");
                         *  if (tempOper.Split().Length > 1)
                         *  {
                         *      tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                         *  }
                         *  //if (NCProgramTag == ncGroup.Tag.ToString() && tempOper == CaxOper.AskOperNameFromTag(OperationAry[i].Tag))
                         *  //{
                         *  //    tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationAry[i];
                         *  //    workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg);
                         *  //}
                         * }
                         * else if (chb_Heidenhain.Checked == true)
                         * {
                         *  if (tempOper.Split().Length > 1)
                         *  {
                         *      tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                         *  }
                         *  //if (NCProgramTag == ncGroup.Tag.ToString() && kvp.Value.Text == CaxOper.AskOperNameFromTag(OperationAry[i].Tag))
                         *  //{
                         *  //    tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationAry[i];
                         *  //    workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg);
                         *  //}
                         * }
                         * else if (chb_Simens.Checked == true)
                         * {
                         *  if (tempOper.Split().Length > 1)
                         *  {
                         *      tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                         *  }
                         * }
                         */
                    }
                }
            }
        }