UG NX二次开发(C#)-CAM-加工模板程序方法刀具和几何体的读取

Posted GimiGimmy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UG NX二次开发(C#)-CAM-加工模板程序方法刀具和几何体的读取相关的知识,希望对你有一定的参考价值。

1、前言

在UG NX的CAM模块中,加工程序是根据UG NX设置的加工模板来编程的,本人是针对CAM模块的UG NX二次开发,获取加工模板、程序名称、加工方法、刀具和几何体的字符串。

2、进入加工模块

UG NX的CAM开发需要进入CAM模块,如果打开的模型还是在建模环境或者基本环境中,CAM模块的功能就不能正常运行,这就需要在打开UI Styler时切换模块。采用NXOPEN.net(C#)切换UG NX的应用模块采用是的是
theSession.ApplicationSwitchImmediate
但是,如果已经进入了CAM模块,如果采用 theSession.ApplicationSwitchImmediate则可能报错,采用如下的代码可以防止错误的发生:

  			NXOpen.Session theSession = NXOpen.Session.GetSession();
            NXOpen.Part workPart = theSession.Parts.Work;
            NXOpen.Part displayPart = theSession.Parts.Display;
            // ----------------------------------------------
            //   菜单:应用模块(N)->加工(R)
            // ----------------------------------------------
            if (theSession.ApplicationName == "UG_APP_MANUFACTURING")
            
                return;
            
            theSession.ApplicationSwitchImmediate("UG_APP_MANUFACTURING");

3、获取加工模板、程序、方法、刀具和几何体信息

这些信息是通过CAMSession来实现的,首先要定义这个CAMSession,即:

 CAMSession cAMSession = theSession.CAMSession;

然后读取以上信息,代码如下:

  CAMSession cAMSession = theSession.CAMSession;
                    string []templateTypes = cAMSession.GetTemplateTypes();
                    theUFUi.OpenListingWindow();
                    theUFUi.WriteListingWindow("=====================加工模板类型===================\\n");
                    int i = 1;
                    foreach(var tm in templateTypes)
                    
                        theUFUi.WriteListingWindow(i.ToString()+"\\t" + "加工模板:\\t" + tm + "\\n");
                        theUFUi.WriteListingWindow("=====================子方法===================\\n");
                        string []subMethods =   cAMSession.GetTemplateSubtypes(tm,CAMSession.ObjectSubtype.Method);
                        int j = 1;
                        foreach(var sm in subMethods)
                        
                            int k = 1;
                            theUFUi.WriteListingWindow(i.ToString() + "_" + j.ToString() + "_" +k++.ToString() + "\\t" + sm + "\\n");
                        

                        subMethods = cAMSession.GetTemplateSubtypes(tm, CAMSession.ObjectSubtype.Operation);
                        theUFUi.WriteListingWindow("=====================操作===================\\n");
                        j++;
                        foreach (var sm in subMethods)
                        
                            int k = 1;
                            theUFUi.WriteListingWindow(i.ToString() + "_" + j.ToString() + "_" + k++.ToString() + "\\t" + sm + "\\n");
                        

                        subMethods = cAMSession.GetTemplateSubtypes(tm, CAMSession.ObjectSubtype.Program);
                        theUFUi.WriteListingWindow("=====================程序===================\\n");
                        j++;
                        foreach (var sm in subMethods)
                        
                            int k = 1;
                            theUFUi.WriteListingWindow(i.ToString() + "_" + j.ToString() + "_" + k++.ToString() + "\\t" + sm + "\\n");
                        
                        subMethods = cAMSession.GetTemplateSubtypes(tm, CAMSession.ObjectSubtype.Setup);
                        theUFUi.WriteListingWindow("=====================设置===================\\n");
                        j++;
                        foreach (var sm in subMethods)
                        
                            int k = 1;
                            theUFUi.WriteListingWindow(i.ToString() + "_" + j.ToString() + "_" + k++.ToString() + "\\t" + sm + "\\n");
                        

                        subMethods = cAMSession.GetTemplateSubtypes(tm, CAMSession.ObjectSubtype.Tool);
                        theUFUi.WriteListingWindow("=====================刀具===================\\n");
                        j++;
                        foreach (var sm in subMethods)
                        
                            int k = 1;
                            theUFUi.WriteListingWindow(i.ToString() + "_" + j.ToString() + "_" + k++.ToString() + "\\t" + sm + "\\n");
                        

                        subMethods = cAMSession.GetTemplateSubtypes(tm, CAMSession.ObjectSubtype.Geometry);
                        theUFUi.WriteListingWindow("=====================几何===================\\n");
                        j++;
                        foreach (var sm in subMethods)
                        
                            int k = 1;
                            theUFUi.WriteListingWindow(i.ToString() + "_" + j.ToString() + "_" + k++.ToString() + "\\t" + sm + "\\n");
                        
                        i++;
                                         
                                       
                            

运行结果

在生成的dll中,通过UI Styler调用,则能读取加工信息如下图所示:

=====================加工模板类型===================
1	加工模板:	mill_planar
=====================子方法===================
1_1_1	MILL_METHOD
=====================操作===================
1_2_1	FLOOR_WALL
1_2_1	FLOOR_WALL_IPW
1_2_1	FACE_MILLING
1_2_1	FACE_MILLING_MANUAL
1_2_1	PLANAR_MILL
1_2_1	PLANAR_PROFILE
1_2_1	CLEANUP_CORNERS
1_2_1	FINISH_WALLS
1_2_1	FINISH_FLOOR
1_2_1	GROOVE_MILLING
1_2_1	HOLE_MILLING
1_2_1	THREAD_MILLING
1_2_1	PLANAR_TEXT
1_2_1	MILL_CONTROL
1_2_1	MILL_USER
=====================程序===================
1_3_1	PROGRAM
=====================设置===================
=====================刀具===================
1_5_1	MILL
1_5_1	CHAMFER_MILL
1_5_1	BALL_MILL
1_5_1	SPHERICAL_MILL
1_5_1	T_CUTTER
1_5_1	BARREL
1_5_1	THREAD_MILL
1_5_1	MILL_USER_DEFINED
1_5_1	CARRIER
1_5_1	MCT_POCKET
1_5_1	HEAD
=====================几何===================
1_6_1	MCS
1_6_1	WORKPIECE
1_6_1	MILL_AREA
1_6_1	MILL_BND
1_6_1	MILL_TEXT
1_6_1	HOLE_BOSS_GEOM
1_6_1	MILL_GEOM
2	加工模板:	mill_contour
=====================子方法===================
2_1_1	MILL_METHOD
2_1_1	MOLD_ROUGH_HSM
2_1_1	MOLD_SEMI_FINISH_HSM
2_1_1	MOLD_FINISH_HSM
=====================操作===================
2_2_1	CAVITY_MILL
2_2_1	PLUNGE_MILLING
2_2_1	CORNER_ROUGH
2_2_1	REST_MILLING
2_2_1	ZLEVEL_PROFILE
2_2_1	ZLEVEL_CORNER
2_2_1	FIXED_CONTOUR
2_2_1	CONTOUR_AREA
2_2_1	CONTOUR_SURFACE_AREA
2_2_1	STREAMLINE
2_2_1	CONTOUR_AREA_NON_STEEP
2_2_1	CONTOUR_AREA_DIR_STEEP
2_2_1	FLOWCUT_SINGLE
2_2_1	FLOWCUT_MULTIPLE
2_2_1	FLOWCUT_REF_TOOL
2_2_1	SOLID_PROFILE_3D
2_2_1	PROFILE_3D
2_2_1	CONTOUR_TEXT
2_2_1	MILL_USER
2_2_1	MILL_CONTROL
=====================程序===================
2_3_1	PROGRAM
=====================设置===================
=====================刀具===================
2_5_1	MILL
2_5_1	CHAMFER_MILL
2_5_1	BALL_MILL
2_5_1	SPHERICAL_MILL
2_5_1	BARREL
2_5_1	T_CUTTER
2_5_1	CARRIER
2_5_1	MCT_POCKET
2_5_1	HEAD
=====================几何===================
2_6_1	MCS
2_6_1	WORKPIECE
2_6_1	MILL_AREA
2_6_1	MILL_BND
2_6_1	MILL_TEXT
2_6_1	MILL_GEOM
3	加工模板:	mill_multi-axis
=====================子方法===================
3_1_1	MILL_METHOD
=====================操作===================
3_2_1	VARIABLE_CONTOUR
3_2_1	VARIABLE_STREAMLINE
3_2_1	CONTOUR_PROFILE
3_2_1	FIXED_CONTOUR
3_2_1	ZLEVEL_5AXIS
3_2_1	SEQUENTIAL_MILL
3_2_1	GENERIC_MOTION
3_2_1	MILL_USER
3_2_1	MILL_CONTROL
=====================程序===================
3_3_1	PROGRAM
=====================设置===================
=====================刀具===================
3_5_1	MILL
3_5_1	CHAMFER_MILL
3_5_1	BALL_MILL
3_5_1	SPHERICAL_MILL
3_5_1	MILL_7_PARAMETER
3_5_1	MILL_10_PARAMETER
3_5_1	BARREL
3_5_1	T_CUTTER
3_5_1	CARRIER
3_5_1	MCT_POCKET
3_5_1	HEAD
=====================几何===================
3_6_1	MCS
3_6_1	WORKPIECE
3_6_1	MILL_AREA
3_6_1	MILL_BND
3_6_1	MILL_GEOM
4	加工模板:	mill_multi_blade
=====================子方法===================
4_1_1	MULTI_BLADE_FINISH
4_1_1	MILL_METHOD
=====================操作===================
4_2_1	MULTI_BLADE_ROUGH
4_2_1	HUB_FINISH
4_2_1	BLADE_FINISH
4_2_1	BLEND_FINISH
4_2_1	GENERIC_MOTION
4_2_1	MILL_USER
4_2_1	MILL_CONTROL
=====================程序===================
4_3_1	PROGRAM
=====================设置===================
=====================刀具===================
4_5_1	MILL
4_5_1	CHAMFER_MILL
4_5_1	BALL_MILL
4_5_1	SPHERICAL_MILL
4_5_1	MILL_7_PARAMETER
4_5_1	MILL_10_PARAMETER
4_5_1	BARREL
4_5_1	T_CUTTER
4_5_1	CARRIER
4_5_1	MCT_POCKET
4_5_1	HEAD
=====================几何===================
4_6_1	MCS
4_6_1	WORKPIECE
4_6_1	MULTI_BLADE_GEOM
5	加工模板:	mill_rotary
=====================子方法===================
5_1_1	MILL_METHOD
=====================操作===================
5_2_1	ROTARY_FLOOR
5_2_1	GENERIC_MOTION
5_2_1	MILL_USER
5_2_1	MILL_CONTROL
=====================程序===================
5_3_1	PROGRAM
=====================设置===================
=====================刀具===================
5_5_1	BALL_MILL
5_5_1	SPHERICAL_MILL
5_5_1	CARRIER
5_5_1	MCT_POCKET
=====================几何===================
5_6_1	MCS
5_6_1	WORKPIECE
5_6_1	ROTARY_GEOM
6	加工模板:	hole_making
=====================子方法===================
6_1_1	DRILL_METHOD
6_1_1	MILL_METHOD
=====================操作===================
6_2_1	SPOT_DRILLING
6_2_1	DRILLING
6_2_1	DEEP_HOLE_DRILLING
6_2_1	COUNTERSINKING
6_2_1	BACK_COUNTER_SINKING
6_2_1	TAPPING
6_2_1	HOLE_MILLING
6_2_1	HOLE_CHAMFER_MILLING
6_2_1	SEQUENTIAL_DRILLING
6_2_1	BOSS_MILLING
6_2_1	THREAD_MILLING
6_2_1	BOSS_THREAD_MILLING
6_2_1	RADIAL_GROOVE_MILLING
6_2_1	MILL_CONTROL
6_2_1	HOLE_MAKING
6_2_1	HOLE_MILL
=====================程序===================
6_3_1	PROGRAM
6_3_1	OPTIMIZED_NC
=====================设置===================
=====================刀具===================
6_5_1	STD_DRILL
6_5_1	CENTERDRILL
6_5_1	COUNTER_SINK
6_5_1	SPOT_DRILL
6_5_1	BORE
6_5_1	REAMER
6_5_1	STEP_DRILL
6_5_1	CORE_DRILL
6_5_1	COUNTER_BORE
6_5_1	TAP
6_5_1	THREAD_MILL
6_5_1	SPOT_FACING
6_5_1	CHAMFER_MILL
6_5_1	MILL
6_5_1	CARRIER
6_5_1	MCT_POCKET
6_5_1	HEAD
6_5_1	BACK_COUNTERSINK
6_5_1	T_CUTTER
=====================几何===================
6_6_1	MCS
6_6_1	WORKPIECE
6_6_1	MILL_AREA
6_6_1	SIMPLE_HOLE
6_6_1	CB_HOLE
6_6_1	CS_HOLE
6_6_1	THD_SIMPLE_HOLE
6_6_1	THD_CB_HOLE
6_6_1	THD_CS_HOLE
6_6_1	SYMBOLIC_THREAD
6_6_1	CAP_SCREW_CB
6_6_1	CAP_SCREW_CS
6_6_1	FIT_HOLE
6_6_1	STANDARD_THREAD
6_6_1	HOLE_BOSS_GEOM
7	加工模板:	turning
=====================子方法===================
7_1_1	LATHE_METHOD
=====================操作===================
7_2_1	CENTERLINE_SPOTDRILL
7_2_1	CENTERLINE_DRILLING
7_2_1	CENTERLINE_PECKDRILL
7_2_1	CENTERLINE_BREAKCHIP
7_2_1	CENTERLINE_REAMING
7_2_1	CENTERLINE_TAPPING
7_2_1	FACING
7_2_1	ROUGH_TURN_OD
7_2_1	ROUGH_BACK_TURN
7_2_1	ROUGH_BORE_ID
7_2_1	ROUGH_BACK_BORE
7_2_1	FINISH_TURN_OD
7_2_1	FINISH_BORE_ID
7_2_1	FINISH_BACK_BORE
7_2_1	TEACH_MODE
7_2_1	GROOVE_OD
7_2_1	GROOVE_ID
7_2_1	GROOVE_FACE
7_2_1	THREAD_OD
7_2_1	THREAD_ID
7_2_1	PART_OFF
7_2_1	LATHE_CONTROL
7_2_1	LATHE_USER
=====================程序===================
7_3_1	PROGRAM
=====================设置===================
=====================刀具===================
7_5_1	SPOTDRILLING_TOOL
7_5_1	DRILLING_TOOL
7_5_1	OD_80_L
7_5_1	OD_80_R
7_5_1	OD_55_L
7_5_1	OD_55_R
7_5_1	ID_80_L
7_5_1	ID_55_L
7_5_1	BACKBORE_55_L
7_5_1	OD_GROOVE_L
7_5_1	FACE_GROOVE_L
7_5_1	ID_GROOVE_L
7_5_1	OD_THREAD_L
7_5_1	ID_THREAD_L
7_5_1	FORM_TOOL
7_5_1	CARRIER
7_5_1	MCT_POCKET
=====================几何===================
7_6_1	MCS_SPINDLE
7_6_1	WORKPIECE
7_6_1	TURNING_WORKPIECE
7_6_1	TURNING_PART
7_6_1	CONTAINMENT
7_6_1	AVOIDANCE
8	加工模板:	wire_edm
=====================子方法===================
8_1_1	WEDM_METHOD
=====================操作===================
8_2_1	NOCORE
8_2_1	EXTERNAL_TRIM
8_2_1	INTERNAL_TRIM
8_2_1	OPEN_PROFILE
8_2_1	WEDM_CONTROL
8_2_1	WEDM_USER
=====================程序===================
8_3_1	PROGRAM
=====================设置===================
=====================刀具===================
8_5_1	WIRE
=====================几何===================
8_6_1	MCS_WEDM
8_6_1	WORKPIECE
8_6_1	SEQUENCE_INTERNAL_TRIM
8_6_1	SEQUENCE_EXTERNAL_TRIM
8_6_1	WEDM_GEOM
9	加工模板:	probing
=====================子方法===================
9_1_1	MILL_METHOD
9_1_1	LATHE_METHOD
=====================操作===================
9_2_1	MILL_PART_PROBING
9_2_1	TURN_PART_PROBING
9_2_1	MILL_TOOL_PROBING
9_2_1	TURN_TOOL_PROBING
9_2_1	GENERIC_MOTION
=====================程序===================
9_3_1	PROGRAM
=====================设置===================
=====================刀具===================
9_5_1	PROBE
9_5_1	GENERIC
=====================几何===================
9_6_1	MCS_MILL
9_6_1	WORKPIECE
10	加工模板:	solid_tool
=====================子方法===================
=====================操作===================
=====================程序===================
=====================设置===================
=====================刀具===================
10_5_1	GENERIC
10_5_1	PROBE
=====================几何===================
11	加工模板:	work_instruction
=====================子方法===================
11_1_1	MILL_METHOD
=====================操作===================
11_2_1	DOCUMENTATION
11_2_1	MANUAL_CONTROL
=====================程序===================
11_3_1	PROGRAM
=====================设置===================
=====================刀具===================
11_5_1	MILL
11_5_1	CHAMFER_MILL
11_5_1	BALL_MILL
11_5_1	SPHERICAL_MILL
11_5_1	T_CUTTER
11_5_1	BARREL
11_5_1	THREAD_MILL
11_5_1	MILL_USER_DEFINED
11_5_1	CARRIER
11_5_1	MCT_POCKET
11_5_1	HEAD
=====================几何===================
11_6_1	MCS
11_6_1	WORKPIECE
11_6_1	MILL_AREA
11_6_1	MILL_BND
11_6_1	MILL_TEXT
11_6_1	HOLE_BOSS_GEOM
11_6_1	MILL_GEOM
12	加工模板:	testPart1
=====================子方法===================
12_1_1	DRILL_METHOD
=====================操作===================
12_2_1	DRILLING
=====================程序===================
12_3_1	PROGRAM
=====================设置===================
=====================刀具===================
12_5_1	STD_DRILL
12_5_1	STD_DRILL_1
12_5_1	STD_DRILL_2
=====================几何===================
12_6_1	MCS
12_6_1	WORKPIECE
12_6_1	MCS_1
12_6_1	WORKPIECE_1
12_6_1	SIMPLE_HOLE
13	加工模板:	myDrillingTemplate
=====================子方法===================
13_1_1	DRILL_METHOD
=====================操作===================
13_2_1	DRILLING
13_2_1	DRILLING_1
=====================程序===================
13_3_1	PROGRAM
=====================设置===================
=====================刀具===================
13_5_1	STD_DRILL
13_5_1	STD_DRILL_1
=====================几何===================
13_6_1	MCS
13_6_1	WORKPIECE
14	加工模板:	template1
=====================子方法===================
14_1_1	DRILL_METHOD
=====================操作===================
14_2_1	DRILLING
=====================程序===================
14_3_1	PROGRAM
=====================设置===================
=====================刀具===================
14_5_1	STD_DRILL
=====================几何===================
14_6_1	MCS
14_6_1	WORKPIECE

以上是关于UG NX二次开发(C#)-CAM-加工模板程序方法刀具和几何体的读取的主要内容,如果未能解决你的问题,请参考以下文章

UG NX二次开发(C#)-CAM-加工程序NCGroup名称有哪些?

UG NX二次开发(C#)-CAM-加工程序NCGroup名称有哪些?

UG NX二次开发(C#)-CAM-不再高亮显示所有的加工特征(CAMFeature)

UG NX二次开发(C#)-CAM-UIStyler中切换到CAM不能正常显示加工界面的解决方法

UG NX二次开发(C#)-CAM-点击插件自动进入CAM模块

nx1926编程工序界面怎么改