|
- int UsrCreatDefDtm_gear(ProDtmplnConstrType pro_dtmpln_def,ProName dtm_name,ProGeomitem *pln)
- {
- ProError status;
- ProElement elem_tree,elem_type,elem_consts,elem_const,elem_const_type;
- ProValueData value_data;
- ProValue value;
- ProModelitem model_modelitem;
- ProSelection mdl_sel;
- ProFeature feature;
- ProErrorlist errors;
- ProSolid solid;
- ProElementAlloc (PRO_E_FEATURE_TREE, &elem_tree);
- ProElementAlloc (PRO_E_FEATURE_TYPE/*基准平面特征元素,代表特征类型*/, &elem_type);
- value_data.type = PRO_VALUE_TYPE_INT/*数据类型*/;
- value_data.v.i = PRO_FEAT_DATUM/*有效值*/;
- ProValueAlloc (&value);
- ProValueDataSet (value, &value_data);
- ProElementValueSet (elem_type, value); //设置一个单值元素
- ProElemtreeElementAdd (elem_tree, NULL, elem_type);
- ProElementAlloc (PRO_E_DTMPLN_CONSTRAINTS/*基准平面特征元素,代表约束*/, &elem_consts);
- ProElemtreeElementAdd (elem_tree, NULL, elem_consts);
- ProElementAlloc (PRO_E_DTMPLN_CONSTRAINT/*基准平面特征元素,代表约束*/, & elem_const);
- ProElemtreeElementAdd (elem_consts, NULL, elem_const);
-
- ProElementAlloc (PRO_E_DTMPLN_CONSTR_TYPE/*基准平面特征元素,代表类型*/, &elem_const_type);
- value_data.type = PRO_VALUE_TYPE_INT;/*数据类型*/
- value_data.v.i = pro_dtmpln_def;/*有效值是ProDtemplnConstrType*/
- ProValueAlloc (&value);
- ProValueDataSet (value, &value_data);
- ProElementValueSet(elem_const_type, value); //设置一个单值元素
- ProElemtreeElementAdd (elem_const, NULL,elem_const_type);
- ProMdlCurrentGet((ProMdl*)&solid);//为当前编辑的模型提供ProMdl句柄
- ProMdlToModelitem(solid, &model_modelitem);
- ProSelectionAlloc(NULL, &model_modelitem, &mdl_sel);
- ProFeatureCreate (mdl_sel, elem_tree, NULL, 0,&feature,&errors);
- status=ProModelitemNameSet(&feature,dtm_name);
- status=ProFeatureRedefine(NULL, &feature, elem_tree, NULL, 0, &errors);
- // UsrGeomitemPlnGet_gear(feature,pln);
- ProElementFree (&elem_tree);
-
- if(status!=PRO_TK_NO_ERROR)//
- {
- AfxMessageBox(_T("1"));
- return status;
- }
- ProSelectionFree (&mdl_sel);
- return (status);
-
- }
- void CreatDefDtm()///创建三个基准面
- {
-
- ProName dtm_name;
- UsrCreatDefDtm_gear(PRO_DTMPLN_DEF_X,ProStringToWstring (dtm_name, "RIGHT1"),&geomright);
- UsrCreatDefDtm_gear(PRO_DTMPLN_DEF_Y,ProStringToWstring (dtm_name, "TOP1"),&geomtop);
- UsrCreatDefDtm_gear(PRO_DTMPLN_DEF_Z,ProStringToWstring (dtm_name, "FRONT1"),&geomfront);
- ProSelectionAlloc(NULL, &geomright, &right);
- ProSelectionAlloc(NULL, &geomtop, &top);
- ProSelectionAlloc(NULL, &geomfront, &front);
- }
- /*圆形*/int UserCreateSection(ProSection section)
- { AfxMessageBox(_T("22"));
- ProError err;
- Pro2dCircledef circle;
- int circle_id;
-
- circle.center[0]=0.0;
- circle.center[1]=0.0;
- circle.radius=maxr;
- circle.type=PRO_2D_CIRCLE;AfxMessageBox(_T("24"));
- err=ProSectionEntityAdd (section,(Pro2dEntdef*)&circle, &circle_id);
- if(err!=PRO_TK_NO_ERROR)
- {AfxMessageBox(_T("25"));}
- AfxMessageBox(_T("23"));
- return (1);
- }
- ProError UserSectionBuild_gear(ProSection section)
- {
- ProError status;
- int ent_id;
- ProWSecerror serrors1;
- ProWSecerror serrors2;
- ProSecerrorAlloc(&serrors1);
- ProSecerrorAlloc(&serrors2);
- //AfxMessageBox(_T("11"));
- if(!UserCreateSection(section))
- {AfxMessageBox(_T("8"));
- return (PRO_TK_NO_ERROR);
- }
- AfxMessageBox(_T("9"));
- ProSectionEntityFromProjection(section,top, &ent_id);
- ProSectionEntityFromProjection(section,right, &ent_id);
- status = ProSectionEpsilonSet( section, 0.1 );
- status= ProSectionAutodim(section, &serrors1);
- status = ProSectionRegenerate ( section,&serrors2 );
- //ProSecerrorFree(&serrors);
- AfxMessageBox(_T("10"));
- return (status) ;
- }
- ProError lashen()
- {
- 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_matrlside;
- ProElement pro_e_std_ext_depth;
- ProElement pro_e_ext_depth_from;
- ProElement pro_e_ext_depth_from_type;
- ProElement pro_e_ext_depth_to;
- ProElement pro_e_ext_depth_to_type;
- ProElement pro_e_ext_depth_from_value;
- 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;/*有效值为PRO_FEAT_DATUM*/
- 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_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]*/front;/*草绘平面*/
- 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;/*平面方向*/
- 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; /*定位方向*/
- 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]*/top;/*参照基准*/
- 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 = 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_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_FROM_VALUE, &pro_e_ext_depth_from_value );
- value_data.type = PRO_VALUE_TYPE_DOUBLE;
- value_data.v.d = houdu;///////////
- status = ProValueAlloc ( &value );
- status = ProValueDataSet ( value, &value_data );
- status = ProElementValueSet ( pro_e_ext_depth_from_value, value );//设置一个单值元素
- status = ProElemtreeElementAdd ( pro_e_ext_depth_from, NULL, pro_e_ext_depth_from_value );
-
- 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_SYMMETRIC;
- 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 = 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);
- //AfxMessageBox(_T("14"));
- //if ( status != PRO_TK_NO_ERROR )
- //{AfxMessageBox(_T("15"));}
- status = ProElementValueGet ( sketch_element, &value);
- /*AfxMessageBox(_T("18"));
- if ( status != PRO_TK_NO_ERROR )
- {AfxMessageBox(_T("17"));}*/
- status = ProValueDataGet (value, &value_data);
- section = (ProSection)value_data.v.p;
- //AfxMessageBox(_T("26"));
- ProElempathFree (&path);
- //AfxMessageBox(_T("27"));
- //构建和求解截面
- status=UserSectionBuild_gear (( ProSection )(value_data.v.p));
- //ProElempathFree (&path);
- AfxMessageBox(_T("19"));
- path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
- path_items[0].path_item.elem_id = PRO_E_STD_MATRLSIDE;
- status = ProElempathAlloc (&path);//分配新的空ProElempath对象
- status = ProElempathDataSet (path, path_items, 1);//通过从一个ProElempathItem结构中复制数据来设置一个ProElempath的内容
- status = ProElemtreeElementGet ( created_elemtree, path, &pro_e_std_matrlside);//读取特征元素树中的一个指定元素
- status = ProElementValueGet ( pro_e_std_matrlside, &value );//提供一个带单值元素的ProValue对象
- value_data.type = PRO_VALUE_TYPE_INT;
- value_data.v.i = PRO_EXT_MATERIAL_SIDE_ONE;
- status = ProValueDataSet ( value, &value_data );
- status = ProElementValueSet ( pro_e_std_matrlside, value );//设置一个单值元素
- ProElempathFree (&path);//释放ProElempath
- AfxMessageBox(_T("5"));
- path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID;
- path_items[0].path_item.elem_id = PRO_E_STD_DIRECTION;
- status = ProElempathAlloc (&path);//分配新的空ProElempath对象
- status = ProElempathDataSet (path, path_items, 1);//通过从一个ProElempathItem结构中复制数据来设置一个ProElempath的内容
- status = ProElemtreeElementGet ( created_elemtree, path,&pro_e_std_direction);//读取特征元素树中的一个指定元素
- status = ProElementValueGet ( pro_e_std_direction, &value );//提供一个带单值元素的ProValue对象
- value_data.type = PRO_VALUE_TYPE_INT;
- value_data.v.i = PRO_EXT_CR_IN_SIDE_TWO;
- status = ProValueDataSet ( value, &value_data );
- status = ProElementValueSet ( pro_e_std_direction, value );//设置一个单值元素
- ProElempathFree (&path);//释放ProElempath
- AfxMessageBox(_T("3"));
- opts[0] = PRO_FEAT_CR_DEFINE_MISS_ELEMS;
- //opts[0] = PRO_FEAT_CR_INCOMPLETE_FEAT;
- status = ProSelectionAsmcomppathGet (model_sel, &comp_path);//获取组员成员路径
- AfxMessageBox(_T("6"));
- AfxMessageBox(_T("20"));
- //status = ProFeatureRedefine (NULL, &feature, created_elemtree,opts, 1, &errors);
- status = ProFeatureRedefine (&comp_path, &feature, created_elemtree,opts, 1, &errors);
- AfxMessageBox(_T("21"));
- ProFeatureElemtreeFree(&feature,created_elemtree);
- ProElementFree(&pro_e_feature_tree);
- //ProWindowRepaint (PRO_VALUE_UNUSED);
- return (status);
- }
复制代码 这是我照着帮助文件写的一个拉伸圆的代码,但是运行到创建草图的时候(函数int UserCreateSection(ProSection section) ),弹框出现了24,没有23和25,也就是说在运行“err=ProSectionEntityAdd (section,(Pro2dEntdef*)&circle, &circle_id);”的时候proe自动退出了,有没有大神帮忙看看是为什么?或者告诉我怎么找到问题在哪里? |
|