admin 发表于 2014-6-7 10:50:25

UG二次开发源码分享:UG NX CAM加工开发简单实例





#include <stdlib.h>
#include <stdio.h>#include <uf.h>
#include <uf_object_types.h>
#include <uf_ui.h>
#include <uf_disp.h>
#include <uf_obj.h>
#include <uf_cam.h>
#include <uf_camgeom.h>#include <ufd_camgeom_ugroup.h>#define MAX_CAMGEOM 20
#define EXIT_SUCCESS 0/*#define DEBUG*/static char *title1 = "Select an API routine...";static int geoption;
static char *title3 = "Select Geometry Type(s) for operation then Selection Complete";//创建几何
static char menu3[] = { "1) Part Geometry",
"2) Blank Geometry",
"3) Drive Geometry",
"4) Cut Area Geometry",
"5) Trim Geometry",
"6) Selection Complete"};static int init_proc(UF_UI_selection_p_t select, void *user_data);//初始化程序static void init_camgeom_app_data(UF_CAMGEOM_app_data_p_t app_data);int ufd_camgeom_ugroup( tag_t objTag, int obj_count ){
UF_CAMGEOM_app_data_p_t app_data_list;
tag_t *objects, entity_list;
int i, entity_count, object_count, err_code, type, subtype;char atitle[] = "Geometry Selection.";
char *cue = "Identify Geometry - Wait for the Filter!";
char errorstrg;
int response, irc;
tag_t eid, view;
double cursor;#ifdef DEBUG
printf( "Object tag passed into camgeom_ugroup is %d \n", objTag );
#endifgeoption = 0;while ( geoption < 10 )//为什么是10呢????
{
/* Statements go here for each geometry selection type. 声明起作用 对于选择类型的每个几何体*/geoption = uc1603(title3, 1, menu3, 6);if (geoption == 1 || geoption == 2 || geoption == 10 )
{
break;
}
#ifdef DEBUG
printf("\n Geometry option returns %d\n", geoption);
#endif
/* Allow the user to select faces or bodies. 选取面和实体*//* Pass in this function the object to be assigned geometry 通过函数,对象被分配到几何体 */if (obj_count > 0 )
{
entity_count = 0;while (TRUE){UF_UI_select_with_single_dialog(cue,atitle,
UF_UI_SEL_SCOPE_NO_CHANGE, init_proc, NULL,
&response, &eid, cursor, &view);//选择单个对象,可输名也可打进去。选择范围在UF_UI中定义
//cue 提示显示的信息,atitle 对话框头标题,UF选取范围,init初始化程序,NULL初始化程序,cursor光标位置坐标if (response == UF_UI_OBJECT_SELECTED)
{
entity_list = eid;
#ifdef DEBUG
printf(" EID number returns %d\n", eid );
#endif/* Allocate the memory for the application data of an item. 为当前的应用数据分配内存*/app_data_list = (UF_CAMGEOM_app_data_p_t)UF_allocate_memory(sizeof(UF_CAMGEOM_app_data_t),
&err_code);/* Initialize the application data.初始化应用数据 */init_camgeom_app_data(app_data_list);entity_count++;
}
else if (response == UF_UI_OK || UF_UI_BACK || UF_UI_CANCEL )
{
/* Geometry selection is finished.几何体选取完成 */
break;
}
}
#ifdef DEBUG
printf(" Entity count this selection is %d\n",entity_count);
#endifif (entity_count > 0)
{
/* UF_CAMGEOM_item_t *items;
int item_count;*/for( i = 0; i < obj_count; i++ )
{
irc = UF_OBJ_ask_type_and_subtype( objTag, &type, &subtype );//返回对象类型与子类型TAG值if( type == UF_machining_operation_type ||
type == UF_machining_geometry_grp_type)#ifdef DEBUG
printf("\n Current entity count is %d", entity_count);
printf("\n Current object count is %d", obj_count);
printf("\n Geometry option is %d \n", geoption );
#endif/* Above prints to help in debugging if "DEBUG" defined. */{
switch (geoption)
{
case 1:
case 2:
case 3:
case 4:
case 5: /* Part Geometry 部件几何体*/
{
#ifdef DEBUG
printf("\n Type returned is %d", type);
printf("\n Subtype returned is %d", subtype);
#endif
{
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_part, entity_count,
entity_list, app_data_list );
//附加一个几何实体链表给对象 几何体包括实体等 切削区域仅薄壁实体和面 修剪的几何体不允许。
//objtag几何体父级组,UF几何体类型,en_list链表指针,app_data_list链表数据。
}
if ( irc != 0 )
{
UF_get_fail_message( irc, errorstrg );
printf("\n The return code is %d\n", irc);
printf("\n Error code translates to %s\n", errorstrg);
return objTag;
}
break;
}case 6: /* Blank Geometry 空白几何体*/
{
#ifdef DEBUG
printf("\n Type returned is %d", type);
printf("\n Subtype returned is %d", subtype);
#endif
{
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_blank, entity_count,
entity_list, app_data_list );
}
if ( irc != 0 )
{
UF_get_fail_message( irc, errorstrg );
printf("\n The return code is %d\n", irc);
printf("\n Error code translates to %s\n", errorstrg);
return objTag;
}
break;}case 7: /* Check Geometry 检查几何体 驱动*/
{
#ifdef DEBUG
printf("\n Type returned is %d", type);
printf("\n Subtype returned is %d", subtype);
#endif
{
irc=UF_CAMGEOM_append_items(objTag,UF_CAM_drive,entity_count,
entity_list,app_data_list);
}
if ( irc != 0 )
{
UF_get_fail_message( irc, errorstrg );
printf("\n The return code is %d\n", irc);
printf("\n Error code translates to %s\n", errorstrg);
return objTag;
}
break;}case 8: /* Cut Area Geometry 切削区域几何体*/
{
#ifdef DEBUG
printf("\n Type returned is %d", type);
printf("\n Subtype returned is %d", subtype);
#endif
{
irc = UF_CAMGEOM_append_items( objTag, UF_CAM_cut_area, entity_count,
entity_list, app_data_list );
}
if ( irc != 0 )
{
UF_get_fail_message( irc, errorstrg );
printf("\n The return code is %d\n", irc);
printf("\n Error code translates to %s\n", errorstrg);
return objTag;
}
break;
}
case 9: /* Trim Geometry 修剪几何体 */
{
printf("This case not implemented.\n");
break;
}
/*Drive Geometry 驱动几何体*/default: /* Selection Complete 完成选取 表达式没有相应的则走这条语句*/
{
break;
}
}
}
}
}
}
}
/* Free the Allocated Memory. 释放内存*/
for (i=0; i<entity_count; i++)
{
UF_free (app_data_list);
}/* UF_free (objects);*/return(0);
}
/* Selection initialization procedure 选择初始化程序*/
static int init_proc
(
UF_UI_selection_p_t select,//指针 pointer
void* user_data
)
{
int num_triples = 3;
//最终指定的特征类型
UF_UI_mask_t mask_triples[] = {
UF_line_type, 0, 0,
UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE,
UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY};/* Enable Faces and Solid Bodies允许选取面和实体 */if((UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
num_triples, mask_triples)) == 0)//3倍 3*3=9{
return (UF_UI_SEL_SUCCESS);
}
else
{
return (UF_UI_SEL_FAILURE);
}
}
static void init_camgeom_app_data
(
UF_CAMGEOM_app_data_p_t app_data
)
{
if (app_data)
{
/* Set flags. 设置标识*/app_data->has_stock = 0; /* Used 1 - Else 0 */
app_data->has_cut_stock = 0; /* Used 1 - Else 0 */
app_data->has_tolerances = 0 ; /* Used 1 - Else 0 */
app_data->has_feedrate = 0 ; /* Used 1 - Else 0 */
app_data->has_offset = 0; /* Used 1 - Else 0 */
app_data->has_avoidance_type = 0 ; /* Used 1 - Else 0 *//* Set values.设置参数值 */
app_data->stock = 0.033 ;
app_data->cut_stock = 0.2 ;
app_data->cut_stock = 0.1 ;
app_data->cut_stock = 0.5 ;
app_data->tolerances = 0.003 ;
app_data->tolerances = 0.003 ;
app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;
app_data->feedrate_value = 33.0 ;
app_data->offset = 0.055 ;
app_data->avoidance_type = UF_CAM_avoidance_type_warning;
}
}

wskgumnm 发表于 2014-8-5 00:57:44

很好好好学习

Jocelyn 发表于 2017-7-18 21:43:08

UF_CAMGEOM_append_items

Jocelyn 发表于 2017-7-18 21:44:34

UF_CAMGEOM_append_items我是用C#写的,用这个函数总是报‘Method not found’错误。
有了解可能的原因的吗?

至简天成 发表于 2017-12-11 15:36:10

不错不错,正需要的东西

至简天成 发表于 2017-12-11 15:49:09


不错不错,正需要的东西
页: [1]
查看完整版本: UG二次开发源码分享:UG NX CAM加工开发简单实例