/* Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved. */ /*---------------------- Pro/Toolkit Includes ------------------------*/ #include "ProToolkit.h" #include "ProFeature.h" #include "ProElemId.h" #include "ProExtrude.h" #include "ProModFeat.h" #include "ProStdSection.h" #include "ProElement.h" #include "ProElempath.h" #include "ProFeatType.h" #include "ProFeatForm.h" #include "ProSelection.h" #include "ProSection.h" #include "ProExtrude.h" static ProFileName message_file; #define C_LOG(a) ProTKPrintf ("Status for %s is = %d\n", a, status ); \ ERROR_CHECK( a, "UgSktExtrusionCreate.c", status ); #define C_PRINT(a) ProTKPrintf ( "%s\n", a); /*===============================================================*\ FUNCTION : UserSktExtrusionThin() PURPOSE : Demonstrates the creation of the extruded thin cut. \*===============================================================*/ ProError UserSktExtrusionThin() { ProReference REPDEP_ref2; ProReference REPDEP_ref1; ProReference REPDEP_ref3; ProReference REPDEP_ref4; ProErrorlist errors; ProMdl model; ProModelitem model_item; ProSelection model_sel; ProFeature feature; ProFeatureCreateOptions *opts = 0; ProElempath path; ProElempathItem path_items[2]; ProSection section; ProAsmcomppath comp_path; ProAsmcomppath *p_comp_path = NULL; ProValue value; double width; double height; double bite_radius; double bite_height; char name[PRO_NAME_SIZE]; ProBoolean alloc; ProSelection selection; ProElement sketch_element; ProElement created_elemtree; ProElement pro_e_feature_tree; ProElement pro_e_feature_type; 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_thickness; ProElement pro_e_std_matrlside; ProElement pro_e_std_direction; ProElement pro_e_std_ext_depth; ProElement pro_e_ext_depth_from; ProElement pro_e_ext_depth_from_ref; int from_ref_id, from_ref_type; ProModelitem from_ref_item; 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_to_ref; int to_ref_id, to_ref_type; ProModelitem to_ref_item; ProElement pro_e_std_section; ProElement pro_e_std_sec_method; 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; ProSelection *sketch_refs; ProError status; ProValueData value_data; ProSelection * p_select; int n_select; ProStringToWstring ( message_file, "utilities.txt" ); log_file = PTApplsUnicodeFopen ( "ug_sketched_curve.log", "w" ); status = ProMdlCurrentGet (&model); if ( status != PRO_TK_NO_ERROR ) return ( status ); /*---------------------------------------------------------------*\ Populating root element PRO_E_FEATURE_TREE \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_FEATURE_TREE *** " ); status = ProElementAlloc ( PRO_E_FEATURE_TREE, &pro_e_feature_tree ); C_LOG( " ProElementAlloc " ); /*---------------------------------------------------------------*\ Populating element PRO_E_FEATURE_FORM \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_FEATURE_FORM *** " ); status = ProElementAlloc ( PRO_E_FEATURE_FORM, &pro_e_feature_form ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet(pro_e_feature_form,PRO_EXTRUDE); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feature_form ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_EXT_SURF_CUT_SOLID_TYPE \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_EXT_SURF_CUT_SOLID_TYPE *** " ); status = ProElementAlloc ( PRO_E_EXT_SURF_CUT_SOLID_TYPE, &pro_e_ext_surf_cut_solid_type ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet(pro_e_ext_surf_cut_solid_type,PRO_EXT_FEAT_TYPE_SOLID); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_ext_surf_cut_solid_type ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_REMOVE_MATERIAL \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_REMOVE_MATERIAL *** " ); status = ProElementAlloc ( PRO_E_REMOVE_MATERIAL, &pro_e_remove_material ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet(pro_e_remove_material,PRO_EXT_MATERIAL_REMOVE); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_remove_material ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_FEAT_FORM_IS_THIN \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_FEAT_FORM_IS_THIN *** " ); status = ProElementAlloc ( PRO_E_FEAT_FORM_IS_THIN, &pro_e_feat_form_is_thin ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet(pro_e_feat_form_is_thin,PRO_EXT_FEAT_FORM_THIN); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_feat_form_is_thin ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_THICKNESS (thin only) \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_THICKNESS *** " ); status = ProElementAlloc ( PRO_E_THICKNESS, &pro_e_thickness ); C_LOG( " ProElementAlloc " ); status = ProElementDecimalsSet( pro_e_thickness,4 ); status = ProElementDoubleSet(pro_e_thickness,1); C_LOG( " ProElementDoubleSet" ); status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_thickness ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating compound element PRO_E_STD_EXT_DEPTH \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_EXT_DEPTH *** " ); status = ProElementAlloc ( PRO_E_STD_EXT_DEPTH, &pro_e_std_ext_depth ); C_LOG( " ProElementAlloc" ); status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_ext_depth ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_EXT_DEPTH -> PRO_E_EXT_DEPTH_FROM \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_EXT_DEPTH_FROM *** " ); status = ProElementAlloc ( PRO_E_EXT_DEPTH_FROM, &pro_e_ext_depth_from ); C_LOG( " ProElementAlloc" ); status = ProElemtreeElementAdd ( pro_e_std_ext_depth, NULL, pro_e_ext_depth_from ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_EXT_DEPTH -> PRO_E_EXT_DEPTH_FROM -> PRO_E_EXT_DEPTH_FROM_TYPE \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_EXT_DEPTH_FROM_TYPE *** " ); status = ProElementAlloc ( PRO_E_EXT_DEPTH_FROM_TYPE, &pro_e_ext_depth_from_type ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet(pro_e_ext_depth_from_type,PRO_EXT_DEPTH_FROM_REF); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_ext_depth_from, NULL, pro_e_ext_depth_from_type ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_EXT_DEPTH -> PRO_E_EXT_DEPTH_FROM -> PRO_E_EXT_DEPTH_FROM_REF \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_EXT_DEPTH_FROM_REF *** " ); status = ProElementAlloc ( PRO_E_EXT_DEPTH_FROM_REF, &pro_e_ext_depth_from_ref ); C_LOG( " ProElementAlloc " ); value_data.type = PRO_VALUE_TYPE_SELECTION; /* PRO_SURFACE, PRO_AXIS, PRO_EDGE, PRO_CURVE, PRO_POINT, PRO_EDGE_START, PRO_EDGE_END, PRO_CRV_START, PRO_CRV_END */ UserUtilItemSelect ("surface,sldface,qltface,datum,axis,edge,curve,edge_end,curve_end", "USER Select reference.", &from_ref_id, ( ProType * )&from_ref_type); status = ProModelitemInit ( model, from_ref_id, from_ref_type, &from_ref_item); C_LOG ( " ProModelitemInit" ); status = ProSelectionAlloc (NULL, &from_ref_item, &selection); C_LOG ( " ProSelectionAlloc" ); status = ProSelectionToReference( selection,&REPDEP_ref3 ); status = ProElementReferenceSet(pro_e_ext_depth_from_ref,REPDEP_ref3); C_LOG( " ProElementReferenceSet" ); status = ProElemtreeElementAdd ( pro_e_ext_depth_from, NULL, pro_e_ext_depth_from_ref ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_EXT_DEPTH -> PRO_E_EXT_DEPTH_TO \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_EXT_DEPTH_TO *** " ); status = ProElementAlloc ( PRO_E_EXT_DEPTH_TO, &pro_e_ext_depth_to ); C_LOG( " ProElementAlloc" ); status = ProElemtreeElementAdd ( pro_e_std_ext_depth, NULL, pro_e_ext_depth_to ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_EXT_DEPTH -> PRO_E_EXT_DEPTH_TO -> PRO_E_EXT_DEPTH_TO_TYPE \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_EXT_DEPTH_TO_TYPE *** " ); status = ProElementAlloc ( PRO_E_EXT_DEPTH_TO_TYPE, &pro_e_ext_depth_to_type ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet(pro_e_ext_depth_to_type,PRO_EXT_DEPTH_TO_REF); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_ext_depth_to, NULL, pro_e_ext_depth_to_type ); C_LOG( " ProElemtreeElementAdd" ); /*--------------------------------------------------------------*\ Populating element PRO_E_STD_EXT_DEPTH -> PRO_E_EXT_DEPTH_TO -> PRO_E_EXT_DEPTH_TO_REF \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_EXT_DEPTH_TO_REF *** " ); status = ProElementAlloc ( PRO_E_EXT_DEPTH_TO_REF, &pro_e_ext_depth_to_ref ); C_LOG( " ProElementAlloc " ); value_data.type = PRO_VALUE_TYPE_SELECTION; /* PRO_SURFACE, PRO_AXIS, PRO_EDGE, PRO_CURVE, PRO_POINT, PRO_EDGE_START, PRO_EDGE_END, PRO_CRV_START, PRO_CRV_END */ UserUtilItemSelect ("surf,datum,axis,edge,curve,edge_end,curve_end", "USER Select reference.", &to_ref_id, ( ProType *) &to_ref_type); status = ProModelitemInit ( model, to_ref_id, to_ref_type, &to_ref_item); C_LOG ( " ProModelitemInit" ); status = ProSelectionAlloc (NULL, &to_ref_item, &selection); C_LOG ( " ProSelectionAlloc" ); status = ProSelectionToReference(selection,&REPDEP_ref4 ); status = ProElementReferenceSet(pro_e_ext_depth_to_ref,REPDEP_ref4); C_LOG( " ProElementReferenceSet" ); status = ProElemtreeElementAdd ( pro_e_ext_depth_to, NULL, pro_e_ext_depth_to_ref ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_SECTION \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_SECTION *** " ); status = ProElementAlloc ( PRO_E_STD_SECTION, &pro_e_std_section ); C_LOG( " ProElementAlloc" ); status = ProElemtreeElementAdd ( pro_e_feature_tree, NULL, pro_e_std_section ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_SECTION -> PRO_E_STD_SEC_SETUP_PLANE \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_SEC_SETUP_PLANE *** " ); status = ProElementAlloc ( PRO_E_STD_SEC_SETUP_PLANE, &pro_e_std_sec_setup_plane ); C_LOG( " ProElementAlloc" ); status = ProElemtreeElementAdd ( pro_e_std_section, NULL, pro_e_std_sec_setup_plane ); C_LOG( " ProElemtreeElementAdd" ); sketch_refs = ( ProSelection *) calloc ( 2, sizeof ( ProSelection )); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_SECTION -> PRO_E_STD_SEC_SETUP_PLANE -> PRO_E_STD_SEC_PLANE \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_SEC_PLANE *** " ); status = ProMessageDisplay ( message_file, "Select Surface for sketch placement"); C_LOG( " ProMessageDisplay" ); ProTKPrintf ( "Please select datum,surface,sldface,qltface_ID_5 type of Modelitem\n"); status = ProSelect ( "datum,surface,sldface,qltface", 1, NULL, NULL, NULL, NULL, &p_select, &n_select ); C_LOG( " ProSelect" ); if ( n_select <= 0 ) return -1; else { status = ProSelectionCopy( p_select[0], &sketch_refs[0]); C_LOG (" ProSelectionCopy "); } status = ProElementAlloc ( PRO_E_STD_SEC_PLANE, &pro_e_std_sec_plane ); C_LOG( " ProElementAlloc " ); status = ProSelectionToReference( p_select[0],&REPDEP_ref1 ); status = ProElementReferenceSet(pro_e_std_sec_plane,REPDEP_ref1); C_LOG( " ProElementReferenceSet" ); status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_SECTION -> PRO_E_STD_SEC_SETUP_PLANE -> PRO_E_STD_SEC_PLANE_VIEW_DIR \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_SEC_PLANE_VIEW_DIR *** " ); status = ProElementAlloc ( PRO_E_STD_SEC_PLANE_VIEW_DIR, &pro_e_std_sec_plane_view_dir ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet(pro_e_std_sec_plane_view_dir,PRO_SEC_VIEW_DIR_SIDE_ONE); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane_view_dir ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_SECTION -> PRO_E_STD_SEC_SETUP_PLANE -> PRO_E_STD_SEC_PLANE_ORIENT_DIR \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_SEC_PLANE_ORIENT_DIR *** " ); status = ProElementAlloc ( PRO_E_STD_SEC_PLANE_ORIENT_DIR, &pro_e_std_sec_plane_orient_dir ); C_LOG( " ProElementAlloc " ); status = ProElementIntegerSet ( pro_e_std_sec_plane_orient_dir, PRO_SEC_ORIENT_DIR_UP ); C_LOG( " ProElementIntegerSet" ); status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane_orient_dir ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_SECTION -> PRO_E_STD_SEC_SETUP_PLANE -> PRO_E_STD_SEC_PLANE_ORIENT_REF \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_SEC_PLANE_ORIENT_REF *** " ); status = ProMessageDisplay ( message_file, "Select Surface for sketch orientation"); C_LOG( " ProMessageDisplay" ); ProTKPrintf ( "Select datum,surface,sldface,qltface_ID_5 type of Modelitem\n"); status = ProSelect ( "datum,surface,sldface,qltface", 1, NULL, NULL, NULL, NULL, &p_select, &n_select ); C_LOG( " ProSelect" ); if ( n_select <= 0 ) return -1; else { status = ProSelectionCopy( p_select[0], &sketch_refs[1]); C_LOG (" ProSelectionCopy "); } status = ProElementAlloc ( PRO_E_STD_SEC_PLANE_ORIENT_REF, &pro_e_std_sec_plane_orient_ref ); C_LOG( " ProElementAlloc " ); status = ProSelectionToReference( p_select[0],&REPDEP_ref2 ); status = ProElementReferenceSet(pro_e_std_sec_plane_orient_ref,REPDEP_ref2); C_LOG( " ProElementReferenceSet" ); status = ProElemtreeElementAdd ( pro_e_std_sec_setup_plane, NULL, pro_e_std_sec_plane_orient_ref ); C_LOG( " ProElemtreeElementAdd" ); /*---------------------------------------------------------------*\ Creating incomplete feature in the current model. \*---------------------------------------------------------------*/ status = ProMdlToModelitem( model, &model_item ); status = ProSelectionAlloc (p_comp_path, &model_item, &model_sel); status = ProArrayAlloc(1,sizeof(ProFeatureCreateOptions), 1, (ProArray*)&opts); opts[0]= PRO_FEAT_CR_INCOMPLETE_FEAT; status = ProFeatureWithoptionsCreate (model_sel, pro_e_feature_tree, opts, PRO_REGEN_NO_FLAGS, &feature, &errors); C_LOG (" ProFeatureWithoptionsCreate"); status = ProArrayFree((ProArray*)&opts); /* Using the element tree from created feature */ status = ProFeatureElemtreeExtract (&feature, NULL, PRO_FEAT_EXTRACT_NO_OPTS, &created_elemtree); C_LOG ("ProFeatureElemtreeExtract()"); /*---------------------------------------------------------------*\ Getting the initialized section element from the database. \*---------------------------------------------------------------*/ /* path to PRO_E_SKETCHER element */ 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); C_LOG (" ProElemtreeElementGet PRO_E_SKETCHER "); status = ProElementSpecialvalueGet(sketch_element, NULL, (ProAppData *) §ion); C_LOG (" ProElementSpecialvalueGet PRO_E_SKETCHER "); /*---------------------------------------------------------------*\ Creating a 3-D section \*---------------------------------------------------------------*/ status = UserSectionBuild (( ProSection )(section), sketch_refs ); C_LOG ("UserSectionBuild"); ProElempathFree (&path); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_MATRLSIDE (must be done once section is set) \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_MATRLSIDE *** " ); path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID; path_items[0].path_item.elem_id = PRO_E_STD_MATRLSIDE; status = ProElempathAlloc (&path); status = ProElempathDataSet (path, path_items, 1); status = ProElemtreeElementGet ( created_elemtree, path, &pro_e_std_matrlside); C_LOG (" ProElemtreeElementGet PRO_E_SKETCHER "); status = ProElementIntegerSet ( pro_e_std_matrlside, PRO_EXT_MATERIAL_BOTH_SIDES ); C_LOG( " ProElementIntegerSet" ); ProElempathFree (&path); /*---------------------------------------------------------------*\ Populating element PRO_E_STD_DIRECTION (must be done once section is set) \*---------------------------------------------------------------*/ C_PRINT( " *** Processing Element PRO_E_STD_DIRECTION *** " ); path_items[0].type = PRO_ELEM_PATH_ITEM_TYPE_ID; path_items[0].path_item.elem_id = PRO_E_STD_DIRECTION; status = ProElempathAlloc (&path); status = ProElempathDataSet (path, path_items, 1); status = ProElemtreeElementGet ( created_elemtree, path, &pro_e_std_direction); C_LOG (" ProElemtreeElementGet PRO_E_SKETCHER "); status = ProElementIntegerSet ( pro_e_std_direction, PRO_EXT_CR_IN_SIDE_ONE ); C_LOG( " ProElementIntegerSet" ); ProElempathFree (&path); /*---------------------------------------------------------------*\ Redefining the feature to make it complete. \*---------------------------------------------------------------*/ status = ProSelectionAsmcomppathGet (model_sel, &comp_path); C_LOG (" ProSelectionAsmcomppathGet"); status = ProArrayAlloc(1,sizeof(ProFeatureCreateOptions), 1, (ProArray*)&opts); opts[0]= PRO_FEAT_CR_DEFINE_MISS_ELEMS; status = ProFeatureWithoptionsRedefine (&comp_path, &feature, created_elemtree, opts, PRO_REGEN_NO_FLAGS, &errors); C_LOG (" ProFeatureWithoptionsRedefine"); status = ProArrayFree((ProArray*)&opts); /*---------------------------------------------------------------*\ Free up the allocated memory. \*---------------------------------------------------------------*/ status = ProFeatureElemtreeFree (&feature, created_elemtree ); C_LOG (" ProFeatureElemtreeFree"); status = ProElementFree (&pro_e_feature_tree ); C_LOG (" ProElementFree"); free(sketch_refs); return (status); } #undef C_LOG #undef C_PRINT