|
楼主 |
发表于 2012-5-14 14:05
|
显示全部楼层
代码
/*================================================*\
创建拉伸特征
\*================================================*/
int UsrCreateExtrudeFeat(ProSelection *sketch_refs,double depth_value)
{
ProErrorlist errors;
ProMdl model;
ProModelitem model_item;
ProSelection model_sel;
ProFeature feature;
ProFeatureCreateOptions opts[1];
ProElempath path;
ProElempathItem path_items[2];
ProSection section;
ProAsmcomppath comp_path;
ProAsmcomppath *p_comp_path = NULL;
ProValue value;
ProElement sketch_element;
ProElement created_elemtree;
ProElement pro_e_feature_tree;
ProElement pro_e_feature_form;
ProElement pro_e_ext_surf_cut_solid_type;
ProElement pro_e_remove_material;
ProElement pro_e_feat_form_is_thin;
ProElement pro_e_std_direction;
ProElement pro_e_std_ext_depth;
ProElement pro_e_ext_depth_from;
ProElement pro_e_ext_depth_from_type;
ProElement pro_e_ext_depth_from_value;
ProElement pro_e_ext_depth_to;
ProElement pro_e_ext_depth_to_type;
ProElement pro_e_std_section;
ProElement pro_e_std_sec_setup_plane;
ProElement pro_e_std_sec_plane;
ProElement pro_e_std_sec_plane_view_dir;
ProElement pro_e_std_sec_plane_orient_dir;
ProElement pro_e_std_sec_plane_orient_ref;
ProError status;
ProValueData value_data;
//CreatDefDtm();//创建三个基准面
status = ProElementAlloc ( PRO_E_FEATURE_TREE, &pro_e_feature_tree );
ProElement pro_e_feature_type;
ProElementAlloc ( PRO_E_FEATURE_TYPE, &pro_e_feature_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_FEAT_PROTRUSION;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_feature_type, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_type );
status = ProElementAlloc ( PRO_E_FEATURE_FORM, &pro_e_feature_form );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_EXTRUDE;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_feature_form, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_form );
status = ProElementAlloc ( PRO_E_EXT_SURF_CUT_SOLID_TYPE, &pro_e_ext_surf_cut_solid_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_EXT_FEAT_TYPE_SOLID;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_ext_surf_cut_solid_type, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_ext_surf_cut_solid_type );
status = ProElementAlloc ( PRO_E_REMOVE_MATERIAL, &pro_e_remove_material );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_EXT_MATERIAL_ADD;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_remove_material, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_remove_material );
status = ProElementAlloc ( PRO_E_FEAT_FORM_IS_THIN, &pro_e_feat_form_is_thin );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_EXT_FEAT_FORM_NO_THIN;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_feat_form_is_thin, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feat_form_is_thin );
status = ProElementAlloc (PRO_E_STD_DIRECTION, &pro_e_std_direction );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_EXT_CR_IN_SIDE_TWO;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_std_direction, value );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_direction );
status = ProElementAlloc ( PRO_E_STD_EXT_DEPTH, &pro_e_std_ext_depth );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_ext_depth );
status = ProElementAlloc ( PRO_E_EXT_DEPTH_FROM, &pro_e_ext_depth_from );
status = ProElemtreeElementAdd ( pro_e_std_ext_depth, NULL, pro_e_ext_depth_from );
status = ProElementAlloc ( PRO_E_EXT_DEPTH_FROM_TYPE, &pro_e_ext_depth_from_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_EXT_DEPTH_FROM_NONE;//BLIND
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_ext_depth_from_type, value );
status = ProElemtreeElementAdd ( pro_e_ext_depth_from, NULL, pro_e_ext_depth_from_type );
status = ProElementAlloc ( PRO_E_EXT_DEPTH_TO, &pro_e_ext_depth_to );
status = ProElemtreeElementAdd ( pro_e_std_ext_depth, NULL, pro_e_ext_depth_to );
status = ProElementAlloc ( PRO_E_EXT_DEPTH_TO_TYPE, &pro_e_ext_depth_to_type );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_EXT_DEPTH_TO_BLIND;
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_ext_depth_to_type, value );
status = ProElemtreeElementAdd ( pro_e_ext_depth_to, NULL, pro_e_ext_depth_to_type );
status = ProElementAlloc ( PRO_E_EXT_DEPTH_TO_VALUE, &pro_e_ext_depth_from_value );
value_data.type = PRO_VALUE_TYPE_DOUBLE;
value_data.v.d = depth_value;///拉伸的厚度
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_ext_depth_from_value, value );
status = ProElemtreeElementAdd ( pro_e_ext_depth_to, NULL, pro_e_ext_depth_from_value );
status = ProElementAlloc ( PRO_E_STD_SECTION, &pro_e_std_section );
status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_section );
status = ProElementAlloc ( PRO_E_STD_SEC_SETUP_PLANE, &pro_e_std_sec_setup_plane );
status = ProElemtreeElementAdd ( pro_e_std_section, NULL, pro_e_std_sec_setup_plane );
status = ProElementAlloc ( PRO_E_STD_SEC_PLANE, &pro_e_std_sec_plane );
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = sketch_refs[0]; //可能需要修改
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_std_sec_plane, value );
status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane );
status = ProElementAlloc ( PRO_E_STD_SEC_PLANE_VIEW_DIR, &pro_e_std_sec_plane_view_dir );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_SEC_VIEW_DIR_SIDE_ONE; /* 1 */
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_std_sec_plane_view_dir, value );
status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane_view_dir );
status = ProElementAlloc ( PRO_E_STD_SEC_PLANE_ORIENT_DIR, &pro_e_std_sec_plane_orient_dir );
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_SEC_ORIENT_DIR_UP; /* 1 *///
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_std_sec_plane_orient_dir, value );
status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane_orient_dir );
status = ProElementAlloc ( PRO_E_STD_SEC_PLANE_ORIENT_REF, &pro_e_std_sec_plane_orient_ref );
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = sketch_refs[1];//可能需要修改
status = ProValueAlloc ( &value );
status = ProValueDataSet ( value, &value_data );
status = ProElementValueSet ( pro_e_std_sec_plane_orient_ref, value );
status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane_orient_ref );
status = ProMdlCurrentGet (&model);
if ( status != PRO_TK_NO_ERROR ) return ( status );
status = ProMdlToModelitem( model, &model_item );
status = ProSelectionAlloc (p_comp_path, &model_item, &model_sel);
opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT;
status = ProFeatureCreate (model_sel, pro_e_feature_tree, opts, 1,&feature, &errors);
status = ProFeatureElemtreeCreate ( &feature, &created_elemtree ); ///获得特征树
//特征的草绘截面
path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
path_items[0].path_item.elem_id = PRO_E_STD_SECTION;
path_items[1].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
path_items[1].path_item.elem_id = PRO_E_SKETCHER;
status = ProElempathAlloc (&path);
status = ProElempathDataSet (path, path_items, 2);
status = ProElemtreeElementGet ( created_elemtree, path, &sketch_element);
status = ProElementValueGet ( sketch_element, &value);
status = ProValueDataGet (value, &value_data);
section = (ProSection)value_data.v.p;
status = UserSectionBuild (( ProSection )(value_data.v.p), sketch_refs,1);
ProElempathFree (&path);
opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT;
status = ProSelectionAsmcomppathGet (model_sel, &comp_path);
status = ProFeatureRedefine (&comp_path, &feature, created_elemtree,opts, 1, &errors);
ProSelectionFree (&model_sel);
//UserSktExtrusionCut(( ProSection )(value_data.v.p), sketch_refs );
//ProViewRefit (model, NULL);
return (status);
}
/*====================================================================*\
FUNCTION : UsrCreateSection() (创建截面)
\*====================================================================*/
int CreateSection(ProSection section,int index,ProSelection *sketch_refs)//草绘截面
{
Pro2dLinedef line[12];
int line_id[12];
Pro2dCircledef circle1;
circle1.center[0]=0.0;
circle1.center[1]=0.0;
circle1.radius=48;//
circle1.type=PRO_2D_CIRCLE;
ProSectionEntityAdd (section,(Pro2dEntdef*)&circle1, &line_id[1]);
return (1);
}
ProError UserSectionBuild(ProSection section,ProSelection *sketch_refs,int index)
{
ProError status=PRO_TK_NO_ERROR;
int ent_id;
ProWSecerror serrors;
/*--------------------------------------------------------------------*\
调用UsrCreateSection()函数作截面草图
\*--------------------------------------------------------------------*/
if(!CreateSection(section,index,sketch_refs))
{
AfxMessageBox(_T("截面草图错误!"));
return status;
}
ProSectionEntityFromProjection(section, sketch_refs[1], &ent_id);
status=ProSectionEntityFromProjection(section, sketch_refs[2], &ent_id);
/*--------------------------------------------------------------------*\
自动标注截面
\*--------------------------------------------------------------------*/
ProSecerrorAlloc(&serrors);
status=ProSectionAutodim(section, &serrors);
ProSecerrorFree(&serrors);
return status ;
}
代码如上所示,我在CreateSection()函数处设置了断点,但是一直不能调试进去。。还麻烦各位高手帮忙指点,不甚感激。 |
|