예제 #1
0
파일: CaxPublic.cs 프로젝트: chiumimy/cax
 /// <summary>
 /// 取得dat每一行的資料
 /// </summary>
 /// <param name="TxtPath">Dat的路徑</param>
 /// <param name="IndexToRead">想要從哪一行開始抓取</param>
 /// <param name="TxtData">抓取的資料</param>
 /// <returns></returns>
 public static bool ReadFileData(string DatPath, int IndexToRead, out string[] DatData)
 {
     DatData = new string[] { };
     try
     {
         List <string> tempDataStr      = new List <string>();
         string[]      TemplatePostData = System.IO.File.ReadAllLines(DatPath);
         if (TemplatePostData.Length == 0)
         {
             CaxLog.ShowListingWindow(Path.GetFileName(DatPath) + "資料為空,請檢查");
             DatData = new string[] { };
             return(false);
         }
         DatData = new string[TemplatePostData.Length];
         for (int i = 0; i < TemplatePostData.Length; i++)
         {
             if (i >= IndexToRead)
             {
                 tempDataStr.Add(TemplatePostData[i]);
             }
         }
         DatData = tempDataStr.ToArray();
     }
     catch (System.Exception ex)
     {
         DatData = new string[] { };
         return(false);
     }
     return(true);
 }
예제 #2
0
        //獲得所有刀具名稱
        public static bool FindAllMachineToolName(out List <string> toolNameList)
        {
            toolNameList = new List <string>();
            try
            {
                Part workPart = theSession.Parts.Work;

                //取得Machine Tool Root的NCGroup
                NCGroup machineToolRoot = workPart.CAMSetup.GetRoot(CAMSetup.View.MachineTool);

                CAMObject[] toolRootMenberAry = machineToolRoot.GetMembers();


                foreach (CAMObject member in toolRootMenberAry)
                {
                    if (member.Name != "NONE")
                    {
                        toolNameList.Add(member.Name);
                    }
                }
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow("FindAllMachineToolName()..." + ex.Message);
                return(false);
            }
            return(true);
        }
예제 #3
0
        //獲得刀具名稱,若有重複的會自動加底線流水號
        public static bool GetToolName(string insertName, string holderName, out string toolName)
        {
            toolName = "";
            try
            {
                List <string> allToolNameList;
                FindAllMachineToolName(out allToolNameList);

                string tempName = (holderName == "") ? insertName : insertName + "_" + holderName;

                if (allToolNameList.Contains(tempName))
                {
                    List <string> sameNameToolList = allToolNameList.FindAll(
                        qq =>
                        qq.ToUpper().Contains(tempName.ToUpper()) &&
                        qq.Length - tempName.Length <= 2);

                    toolName = tempName + "_" + sameNameToolList.Count.ToString();
                }
                else
                {
                    toolName = tempName;
                }
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow("GetToolName()..." + ex.Message);
                return(false);
            }
            return(true);
        }
예제 #4
0
        public static bool CreateNewEmptyComp(string comp_path, out NXOpen.Assemblies.Component component, string TemplateFileName = "model-plain-1-mm-template.prt", string ReferenceSetName = "Entire Part")
        {
            try
            {
                Session theSession  = Session.GetSession();
                Part    workPart    = theSession.Parts.Work;
                Part    displayPart = theSession.Parts.Display;
                // ----------------------------------------------
                //   Menu: Assemblies->Components->Create New Component...
                // ----------------------------------------------
                FileNew fileNew1;
                fileNew1 = theSession.Parts.FileNew();
                fileNew1.TemplateFileName = TemplateFileName;
                fileNew1.Application      = FileNewApplication.Modeling;
                fileNew1.Units            = NXOpen.Part.Units.Millimeters;
                //fileNew1.TemplateType = FileNewTemplateType.Item;
                fileNew1.NewFileName       = comp_path;
                fileNew1.MasterFileName    = "";
                fileNew1.UseBlankTemplate  = false;
                fileNew1.MakeDisplayedPart = false;
                string newNameNoExt = "";
                newNameNoExt = Path.GetFileNameWithoutExtension(comp_path);
                string newNameNoExtUpper = "";
                newNameNoExtUpper = newNameNoExt.ToUpper();

                NXOpen.Assemblies.CreateNewComponentBuilder createNewComponentBuilder1;

                createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder();

                createNewComponentBuilder1.NewComponentName = newNameNoExtUpper;

                createNewComponentBuilder1.ReferenceSet = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly;

                createNewComponentBuilder1.ReferenceSetName = ReferenceSetName;

                // ----------------------------------------------
                //   Dialog Begin Create New Component
                // ----------------------------------------------
                createNewComponentBuilder1.ReferenceSet = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.Model;
                createNewComponentBuilder1.NewFile      = fileNew1;
                NXObject nXObject1;
                nXObject1 = createNewComponentBuilder1.Commit();

                component = (NXOpen.Assemblies.Component)nXObject1;

                //UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Information, component.Name);


                createNewComponentBuilder1.Destroy();
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow(ex.ToString());
                component = null;
                return(false);
            }

            return(true);
        }
예제 #5
0
파일: CaxOper.cs 프로젝트: chiumimy/cax
        /// <summary>
        /// 取得Operatrion程式名
        /// </summary>
        /// <param name="operTag"></param>
        /// <param name="operName"></param>
        /// <returns></returns>
        public static string AskOperNameFromTag(Tag operTag)
        {
            string operName = "";

            try
            {
                theUfSession.Oper.AskNameFromTag(operTag, out operName);
                return(operName);
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow("使用AskOperNameFromTag出錯:" + ex.ToString());
                return(operName);
            }
        }
예제 #6
0
파일: CaxOper.cs 프로젝트: chiumimy/cax
 /// <summary>
 /// 取得Operation加工方法
 /// </summary>
 /// <param name="operTag"></param>
 /// <param name="operMethodName"></param>
 /// <returns></returns>
 public static bool AskOperMethodNameFromTag(Tag operTag, out string operMethodName)
 {
     operMethodName = "";
     try
     {
         Tag bb;
         theUfSession.Oper.AskMethodGroup(operTag, out bb);
         NXOpen.CAM.Method cc = (NXOpen.CAM.Method)NXObjectManager.Get(bb);
         operMethodName = cc.Name;
     }
     catch (System.Exception ex)
     {
         CaxLog.ShowListingWindow("使用AskOperMethodNameFromTag出錯:" + ex.ToString());
         return(false);
     }
     return(true);
 }
예제 #7
0
        /// <summary>
        /// 以另存檔案的方式修改Part名稱,可指定是否刪除原檔案,預設為刪除
        /// </summary>
        /// <param name="Part"></param>
        /// <param name="NewPartName"></param>
        /// <param name="DeleteOldPart"></param>
        /// <returns></returns>
        public static bool RenamePart(NXOpen.Part part, string NewPartName, bool DeleteOldPart = true)
        {
            try
            {
                Part currentworkpart = theSession.Parts.Work;

                theSession.Parts.SetWork(part);

                string oldPartPath = part.FullPath;
                string newPartPath = string.Format("{0}\\{1}.prt", Path.GetDirectoryName(oldPartPath), NewPartName);
                if (File.Exists(newPartPath))
                {
                    File.Delete(newPartPath);
                }
                //另存成新的檔案架構名稱
                PartSaveStatus partSaveStatus1;
                partSaveStatus1 = part.SaveAs(Path.GetDirectoryName(newPartPath) + "\\" + Path.GetFileNameWithoutExtension(newPartPath));
                partSaveStatus1.Dispose();
                //刪除舊有檔案
                if (DeleteOldPart)
                {
                    if (File.Exists(oldPartPath))
                    {
                        File.Delete(oldPartPath);
                    }
                }

                theSession.Parts.SetWork(currentworkpart);
            }
            catch (Exception ex)
            {
                CaxLog.ShowListingWindow(ex.Message);
                return(false);
            }
            return(true);
        }
예제 #8
0
        public static bool CreateTcutterToolNxopen()
        {
            try
            {
                Part workPart = theSession.Parts.Work;

                //取得Machine Tool Root的NCGroup
                NCGroup machineToolRoot = workPart.CAMSetup.GetRoot(CAMSetup.View.MachineTool);

                //建立刀具
                string  toolType        = "mill_planar";
                string  toolSubtype     = "T_CUTTER";
                string  toolName        = "TestTool";
                NCGroup createToolGroup = workPart.CAMSetup.CAMGroupCollection.CreateTool(
                    machineToolRoot, toolType, toolSubtype, NCGroupCollection.UseDefaultName.True, toolName);
                Tool createTool = (Tool)createToolGroup;

                //設定刀具參數
                NXOpen.CAM.TToolBuilder toolBuilder;
                toolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateTToolBuilder(createTool);

                //設定刀具直徑(Tool>Dimensions>Diameter)
                toolBuilder.TlDiameterBuilder.Value = 26.0;
                //設定刀桿直徑(Tool>Dimensions>Shank Diameter)
                toolBuilder.TlShankDiaBuilder.Value = 10.0;
                //設定刀尖R角(Tool>Dimensions>Lower Radius)
                toolBuilder.TlLowCorRadBuilder.Value = 2.0;
                //設定刀刃上R角(Tool>Dimensions>Up Radius)
                toolBuilder.TlUpCorRadBuilder.Value = 3.0;
                //設定刀長(Tool>Dimensions>Length)
                toolBuilder.TlHeightBuilder.Value = 30.0;
                //設定刃長(Tool>Dimensions>Flute Length)
                toolBuilder.TlFluteLnBuilder.Value = 25.0;
                //設定刃數(Tool>Dimensions>Flutes)
                toolBuilder.TlNumFlutesBuilder.Value = 5;


                //設定刀把階段
                //設定段數(Holder>Holder Steps>Step)
                int sectionIndex = 0;
                //設定直徑(Holder>Holder Steps>Diameter)
                double sectionDiameter = 60.0;
                //設定長度(Holder>Holder Steps>Length)
                double sectionLength = 20.0;
                //設定錐度(Holder>Holder Steps>Taper Angle)
                double sectionTaper = 2.0;
                //設定下端R角(Holder>Holder Steps>Corner Radius)
                double sectionRadius = 1.0;
                //新增階段
                toolBuilder.HolderSectionBuilder.Add(sectionIndex, sectionDiameter, sectionLength, sectionTaper, sectionRadius);


                toolBuilder.Commit();
                toolBuilder.Destroy();
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow(ex.Message);
                return(false);
            }
            return(true);
        }
예제 #9
0
        public static bool CreateMillToolNxopen(int toolNo, MillingToolData millToolData, out Tool millTool)
        {
            millTool = null;
            try
            {
                Part workPart = theSession.Parts.Work;

                //取得Machine Tool Root的NCGroup
                NCGroup machineToolRoot = workPart.CAMSetup.GetRoot(CAMSetup.View.MachineTool);

                //建立刀具
                string toolType    = "mill_planar";
                string toolSubtype = "MILL";
                string toolName    = "";
                string preToolName = string.Format("T{0}_{1}", toolNo, millToolData.CUTTER_NAME);
                GetToolName(preToolName, "", out toolName);

                NCGroup createToolGroup = workPart.CAMSetup.CAMGroupCollection.CreateTool(
                    machineToolRoot, toolType, toolSubtype, NCGroupCollection.UseDefaultName.False, toolName);
                Tool createTool = (Tool)createToolGroup;

                //設定刀具參數
                NXOpen.CAM.MillToolBuilder toolBuilder;
                toolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateMillToolBuilder(createTool);

                //設定刀具直徑(Tool>Dimensions>Diameter)
                toolBuilder.TlDiameterBuilder.Value = double.Parse(millToolData.DIAMETER);
                //設定刀尖R角(Tool>Dimensions>Lower Radius)
                toolBuilder.TlCor1RadBuilder.Value = double.Parse(millToolData.RADIUS);
                //設定錐度(Tool>Dimensions>Taper Angle)
                toolBuilder.TlTaperAngBuilder.Value = double.Parse(millToolData.FLUTE_B_ANGLE);
                //設定刀尖斜度(Tool>Dimensions>Tip Angle)
                toolBuilder.TlTipAngBuilder.Value = double.Parse(millToolData.FLUTE_A_ANGLE);

                //設定刀長(Tool>Dimensions>Length)
                if (double.Parse(millToolData.NECK_LENGTH) != 0.0 &&
                    double.Parse(millToolData.NECK_DIAMETER) != double.Parse(millToolData.DIAMETER)) //有輸入NL而且ND跟D不同
                {
                    toolBuilder.TlHeightBuilder.Value = double.Parse(millToolData.NECK_LENGTH);
                }
                else
                {
                    toolBuilder.TlHeightBuilder.Value = 0.0; //刀長設為0,其餘長度丟到holder
                }

                //設定刃長(Tool>Dimensions>Flute Length)
                toolBuilder.TlFluteLnBuilder.Value = double.Parse(millToolData.FLUTE_LENGTH);
                //設定刃數(Tool>Dimensions>Flutes)
                toolBuilder.TlNumFlutesBuilder.Value = int.Parse(millToolData.FLUTE_NUM);

                //設定刀把階段
                //設定段數(Holder>Holder Steps>Step)
                int sectionIndex = 0;
                //設定直徑(Holder>Holder Steps>Diameter)
                double sectionDiameter = 60.0;
                //設定長度(Holder>Holder Steps>Length)
                double sectionLength = 20.0;
                //設定錐度(Holder>Holder Steps>Taper Angle)
                double sectionTaper = 2.0;
                //設定下端R角(Holder>Holder Steps>Corner Radius)
                double sectionRadius = 1.0;
                //新增階段
                toolBuilder.HolderSectionBuilder.Add(sectionIndex, sectionDiameter, sectionLength, sectionTaper, sectionRadius);


                toolBuilder.Commit();
                toolBuilder.Destroy();
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow("CreateMillToolNxopen()..." + ex.Message);
                return(false);
            }
            return(true);
        }
예제 #10
0
        //建立車刀刀具(給刀片、刀桿資料類別)
        public static bool CreateTurningToolNxopen(int toolNo, TurningInsertData insertData, ExternalHolderData exHolder, InternalHolderData inHolder, out Tool turningTool)
        {
            turningTool = null;
            try
            {
                Part workPart = theSession.Parts.Work;

                //取得Machine Tool Root的NCGroup
                NCGroup machineToolRoot = workPart.CAMSetup.GetRoot(CAMSetup.View.MachineTool);

                //建立刀具
                string toolType    = "turning";
                string toolSubtype = "OD_80_R";

                string toolName    = "";
                string preToolName = string.Format("T{0}_{1}", toolNo.ToString(), insertData.PRODUCT_NO);
                GetToolName(preToolName, "", out toolName);

                NCGroup createToolGroup = workPart.CAMSetup.CAMGroupCollection.CreateTool(
                    machineToolRoot, toolType, toolSubtype, NCGroupCollection.UseDefaultName.False, toolName);
                Tool createTool = (Tool)createToolGroup;

                string shapeCode        = insertData.ISO_SPEC.Substring(0, 1);
                string relifeAngleCode  = insertData.ISO_SPEC.Substring(1, 1);
                string toleranceCode    = insertData.ISO_SPEC.Substring(2, 1);
                string crossSectionCode = insertData.ISO_SPEC.Substring(3, 1);
                string sizeCode         = insertData.ISO_SPEC.Substring(4, 2);
                string thicknessCode    = insertData.ISO_SPEC.Substring(6, 2);
                string radiusColde      = insertData.ISO_SPEC.Substring(8, 2);

                //開始設定刀具參數
                NXOpen.CAM.TurnToolBuilder turnToolBuilder;
                turnToolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateTurnToolBuilder(createTool);
                //設定刀號
                turnToolBuilder.TlNumberBuilder.Value = toolNo;
                //設定刀片形狀(Tool>Insert>ISO Insert Shape)
                turnToolBuilder.InsertShape = GetTurningInsertShape(shapeCode);
                //設定刀片位置(Tool>Insert>Insert Position)
                turnToolBuilder.InsertPosition = TurningToolBuilder.InsertPositions.Underside;
                //設定刀片刀尖R角(Tool>Dimensions>Nose Radius)
                turnToolBuilder.NoseRadiusBuilder.Value = GetTurningInsertRadius(radiusColde);
                //設定刀片切削角度(Tool>Dimensions>Orient angle)
                //turnToolBuilder.OrientAngleBuilder.Value = 80;
                //設定刀片刀尖夾角(Tool>Dimensions>Nose Angle,刀片形狀需指定為X)
                if (turnToolBuilder.InsertShape == TurnToolBuilder.InsertShapes.User)
                {
                    turnToolBuilder.NoseAngleBuilder.Value = 20;
                }
                //設定刀片尺寸類型(Tool>Insert Size>Measurement)
                turnToolBuilder.SizeOption = TurnToolBuilder.SizeOptions.InscribedCircle;
                //設定刀片尺寸(Tool>Insert Size>Length)
                turnToolBuilder.SizeBuilder.Value = GetTurningInsertSize(shapeCode, sizeCode);
                //設定刀片後角類型(Tool>More>Relief Angle)
                turnToolBuilder.ReliefAngleType = GetTurningInsertReliefAngle(relifeAngleCode);
                //設定刀片後角角度(Tool>More>Relief Angle,刀片後角類型需指定為O)
                if (turnToolBuilder.ReliefAngleType == TurnToolBuilder.ReliefAngleTypes.OOther)
                {
                    turnToolBuilder.ReliefAngleBuilder.Value = 45;
                }
                //設定刀片厚度(Tool>More>Thickness)
                double thicknessValue = 0.0;
                turnToolBuilder.ThicknessType = GetTurninInsertThickness(thicknessCode, out thicknessValue);
                if (turnToolBuilder.ThicknessType == TurnToolBuilder.ThicknessTypes.ThicknessUserDefined)
                {
                    turnToolBuilder.ThicknessBuilder.Value = thicknessValue;
                }

                #region 刀桿設定
                if (exHolder == null && inHolder == null)
                {
                    //設定是否使用刀桿(Tool>Holder(Shank)>Use Turn Holder)
                    turnToolBuilder.HolderUse = false;
                }
                else
                {
                    //設定是否使用刀桿(Tool>Holder(Shank)>Use Turn Holder)
                    turnToolBuilder.HolderUse = true;
                    if (exHolder != null)
                    {
                        //外徑
                        turnToolBuilder.TlDescription = exHolder.PRODUCT_NO;
                        string holderStyleCode = exHolder.ISO_CODE.Substring(2, 1);
                        //設定刀桿類型(Tool>Holder(Shank)>Style)
                        turnToolBuilder.HolderStyle = GetTurningHolderStyle(holderStyleCode);
                        //設定刀桿左右手(Tool>Holder(Shank)>Hand)
                        turnToolBuilder.HolderHand = GetTurningHolderHand(exHolder.HAND_SIDE);
                        //設定刀桿方形圓形(Tool>Holder(Shank)>Shank Type)
                        turnToolBuilder.HolderShankType = TurnToolBuilder.HolderShankTypes.Square;
                        //設定刀桿角度(Holder>Dimensions>Holder Angle)
                        turnToolBuilder.HolderAngleBuilder.Value = 90.0;

                        //設定刀桿尺寸
                        //設定刀具長度(Holder>Dimensions>Length)
                        turnToolBuilder.HolderLengthBuilder.Value = double.Parse(exHolder.SHANK_L_NX);
                        //設定刀尖位置(寬)(Holder>Dimensions>Width)
                        turnToolBuilder.HolderWidthBuilder.Value = double.Parse(exHolder.FUNC_W_NX);
                        //設定刀桿寬度(Holder>Dimensions>Shank Width)
                        turnToolBuilder.HolderShankWidthBuilder.Value = double.Parse(exHolder.SHANK_W);
                        //設定刀尖位置(長)(Holder>Dimensions>Shank Line)
                        turnToolBuilder.HolderShankLineBuilder.Value = double.Parse(exHolder.FUNC_L_NX);
                    }
                    else
                    {
                        //內徑
                        turnToolBuilder.TlDescription = inHolder.PRODUCT_NO;
                        string holderStyleCode = inHolder.ISO_CODE.Substring(2, 1);
                        //設定刀桿類型(Tool>Holder(Shank)>Style)
                        turnToolBuilder.HolderStyle = GetTurningHolderStyle(holderStyleCode);
                        //設定刀桿左右手(Tool>Holder(Shank)>Hand)
                        turnToolBuilder.HolderHand = GetTurningHolderHand(inHolder.HAND_SIDE);
                        //設定刀桿方形圓形(Tool>Holder(Shank)>Shank Type)
                        turnToolBuilder.HolderShankType = TurnToolBuilder.HolderShankTypes.Round;
                        //設定刀桿角度(Holder>Dimensions>Holder Angle)
                        turnToolBuilder.HolderAngleBuilder.Value = 0.0;

                        //設定刀桿尺寸
                        //設定刀具長度(Holder>Dimensions>Length)
                        turnToolBuilder.HolderLengthBuilder.Value = double.Parse(inHolder.SHANK_L_NX);
                        //設定刀尖位置(寬)(Holder>Dimensions>Width)
                        turnToolBuilder.HolderWidthBuilder.Value = double.Parse(inHolder.FUNC_W_NX);
                        //設定刀桿寬度(Holder>Dimensions>Shank Width)
                        turnToolBuilder.HolderShankWidthBuilder.Value = double.Parse(inHolder.SHANK_W);
                        //設定刀尖位置(長)(Holder>Dimensions>Shank Line)
                        turnToolBuilder.HolderShankLineBuilder.Value = double.Parse(inHolder.FUNC_L_NX);
                    }

                    //設定刀桿刀片是否固定角度(Tool>Holder(Shank)>Lock Insert and Holder Orientation,刀桿類型需指定為Ud)
                    if (turnToolBuilder.HolderStyle == TurnToolBuilder.HolderStyles.Ud)
                    {
                        turnToolBuilder.HolderLock = false;
                    }
                }
                #endregion


                ////設定Tracking Point
                //NXOpen.CAM.TrackingBuilder trackingBuilder = turnToolBuilder.TrackingBuilder;
                ////取得預設的Tracking Point
                //NXObject trackingPoint = trackingBuilder.GetTrackPoint(0);
                ////修改參數
                ////名稱(Tracking>Tracking Points>Name)
                //string tpName = "TP";
                ////位置點(Tracking>Tracking Points>P Number,0-8代表p2, p6, p1, p7, p9, p5, p3, p8, p4)
                //int tpNo = 6;
                //trackingBuilder.Modify(trackingPoint, tpName, 0, tpNo, 0, 0, 0, 0, 0, 0);

                //圓形刀片專用
                //turnToolBuilder.ButtonDiameterBuilder
                //turnToolBuilder.HolderControlAngleBuilder
                //turnToolBuilder.HolderControlWidthBuilder

                turningTool = (NXOpen.CAM.Tool)turnToolBuilder.Commit();
                turnToolBuilder.Destroy();

                theUfSession.UiOnt.Refresh();
            }
            catch (System.Exception ex)
            {
                CaxLog.ShowListingWindow("CreateTurningToolNxopen()..." + ex.Message);
                return(false);
            }
            return(true);
        }