NX二次開發(fā)習(xí)習(xí)題及源碼_第1頁
NX二次開發(fā)習(xí)習(xí)題及源碼_第2頁
NX二次開發(fā)習(xí)習(xí)題及源碼_第3頁
NX二次開發(fā)習(xí)習(xí)題及源碼_第4頁
NX二次開發(fā)習(xí)習(xí)題及源碼_第5頁
免費(fèi)預(yù)覽已結(jié)束,剩余19頁可下載查看

付費(fèi)下載

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、1、創(chuàng)建NXhello界面代碼:#include <>In a non-assembly part, this is the same as the work part. If there currently isn't a displayed part, a NULL_TAG is returned. */obj=UF_PART_ask_display_part();if(obj = NULL_TAG) ll文件時(shí),就直接跑到建模環(huán)境了,沒有信息提示框。當(dāng)然你可以多申明幾個(gè)tag_tchar part_name13 = "F:"/ UF_get_fai

2、l_message(error_code, fail_message); UF_UI_set_status (fail_message); printf ( "%sn", fail_message ); UF_terminate(); return;extern int ufusr_ask_unload (void) return ( UF_UNLOAD_IMMEDIATELY );extern void ufusr_cleanup (void) return;int CHANGE_apply_cb ( int dialog_id,void * client_data,UF

3、_STYLER_item_value_type_p_t callback_data) if ( UF_initialize() != 0) return ( UF_UI_CB_CONTINUE_DIALOG ); / UF_get_fail_message(error_code, fail_message); UF_UI_set_status (fail_message); printf ( "%sn", fail_message ); UF_terminate(); return;extern int ufusr_ask_unload (void) /* unload i

4、mmediately after application exits*/ return ( UF_UNLOAD_IMMEDIATELY ); /*via the unload selection dialog. */ /*return ( UF_UNLOAD_SEL_DIALOG ); */ /*when UG terminates. */ /*return ( UF_UNLOAD_UG_TERMINATE ); */extern void ufusr_cleanup (void) return;int CHANGE_apply_cb ( int dialog_id, void * clien

5、t_data, UF_STYLER_item_value_type_p_t callback_data) /* Make sure User Function is available. */ if ( UF_initialize() != 0) return ( UF_UI_CB_CONTINUE_DIALOG ); /* - Enter your callback code here - */ UF_terminate (); /* Callback acknowledged, do not terminate dialog */ /* A return value of UF_UI_CB

6、_EXIT_DIALOG will not be accepted */ /* for this callback type. You must respond to your apply button.*/ return (UF_UI_CB_CONTINUE_DIALOG); int CHANGE_action_1_act_cb ( int dialog_id, void * client_data, UF_STYLER_item_value_type_p_t callback_data) /* Make sure User Function is available. */ if ( UF

7、_initialize() != 0) return ( UF_UI_CB_CONTINUE_DIALOG ); /* - Enter your callback code here - */ UF_UI_create_filebox ( prompt_string, title_string, filter_string, default_name, filename, &response); /* 從文件中讀信息*/ int error; fstream file1(filename); char *file_contents = (char*)UF_allocate_memory

8、(sizeof(char*)*16,&error); int i=0; while(!() file_contentsi = (char*)UF_allocate_memory(MAX_LINE_SIZE+1,&error); file1>>file_contentsi; UF_UI_write_listing_window(file_contentsi); UF_UI_write_listing_window("n"); i+; UF_STYLER_item_value_type_t data; = "MTXT_0" = U

9、F_STYLER_VALUE; = UF_STYLER_STRING_PTR_VALUE; = i; = file_contents; UF_STYLER_set_value(dialog_id,&data); UF_STYLER_free_value(&data); (); UF_terminate (); /* Callback acknowledged, do not terminate dialog */ return (UF_UI_CB_CONTINUE_DIALOG); /* or Callback acknowledged, terminate dialog. *

10、/ /* return ( UF_UI_CB_EXIT_DIALOG ); */int CHANGE_action_2_act_cb ( int dialog_id, void * client_data, UF_STYLER_item_value_type_p_t callback_data) /* Make sure User Function is available. */ if ( UF_initialize() != 0) return ( UF_UI_CB_CONTINUE_DIALOG ); /* - Enter your callback code here - */ UF_

11、STYLER_item_value_type_t data; = "MTXT_0" = UF_STYLER_VALUE; UF_STYLER_ask_value(dialog_id,&data); char prompt_string="Select File" char title_string="File Access" char filter_stringUF_CFI_MAX_PATH_NAME_SIZE+1="*.txt" char default_name133="" char

12、 filenameUF_CFI_MAX_PATH_NAME_SIZE; int response; int error = UF_UI_create_filebox(prompt_string, title_string, filter_string, default_name, filename, &response); if(error !=0 ) return UF_UI_CB_CONTINUE_DIALOG; fstream file2(filename); for (int i=0;i<i+) if(!(file2<<&&file2<&

13、lt;endl) (); UF_STYLER_free_value(&data); UF_terminate (); /* Callback acknowledged, do not terminate dialog */ return (UF_UI_CB_CONTINUE_DIALOG); /* or Callback acknowledged, terminate dialog. */ /* return ( UF_UI_CB_EXIT_DIALOG ); */ 注意:這個(gè)項(xiàng)目需要在UG中創(chuàng)建一個(gè)人機(jī)交互界面8、(1)創(chuàng)建點(diǎn)收集器,創(chuàng)建參考點(diǎn)并返回點(diǎn)的坐標(biāo)代碼如下:#include

14、 <> #include <>#include <>#define UF_CALL(X) (report( _FILE_, _LINE_, #X, (X) static int report( char *file, int line, char *call, int irc) if (irc) char messg133; printf("%s, line %d: %sn", file, line, call); (UF_get_fail_message(irc, messg) printf(" returned a %dn&

15、quot;, irc) : printf(" returned error %d: %sn", irc, messg); return(irc); static void do_ugopen_api(void) bject;UF_UI_open_listing_window(); char str 133;for(int i=0;i<3;i+)sprintf(str,"%f",points0.pti);nn",msg);exit(1);static void report_error(int result,char *alt_msg)ch

16、ar err_message200;int found = UF_get_fail_message(result,err_message);if (found != 0)error_return(alt_msg);elseerror_return(err_message);static void create_blo( double origin_y, char *blo_length,char*blo_width,char*blo_height ) UF_FEATURE_SIGN sign = UF_NULLSIGN; tag_t taget = NULL_TAG; double blo_o

17、rigin 3 = 0,0,0; */ if(UF_CALL(UF_UI_select_with_class_dialog(cue, title, UF_UI_SEL_SCOPE_NO_CHANGE ,init_proc, NULL, &response, &count, &objects) = 0) In a non-assembly part, this is the same as the work part. If there currently isn't a displayed part, a NULL_TAG is returned. */tag_

18、t root_occ = UF_ASSEM_ask_root_part_occ(display_part);if(root_occ=null_tag)rom_part_occ = from_part_occ;0.from_status = UF_ASSEM_ok;0.from = UF_ASSEM_ask_prototype_of_occ( objs0 );0.from_type = UF_ASSEM_planar_face;0.to = UF_ASSEM_ask_prototype_of_occ( objs1 );0.to_part_occ = to_part_occ;0.to_status

19、 = UF_ASSEM_ok;0.to_type = UF_ASSEM_planar_face;0.mate_type = UF_ASSEM_align;UF_ASSEM_mc_status_t status;UF_ASSEM_dof_t dof;double transform_matrix44; UF_MODL_ask_exp_tag_value(target1,&value); /創(chuàng)建孔特征的變量聲明區(qū) double location3=, ; double direction = ,; tag_t obj=null_tag; char *diam="30"

20、char *angle="0" tag_t bottom,top; tag_t feature_obj_id ; /鏈表,把圓柱所有的面放進(jìn)去 uf_list_p_t face_list; UF_MODL_create_list(&face_list);/Retrieves an object from a linked list of objects UF_MODL_ask_feat_faces(cyl_feat_tag,&face_list); int count=0; UF_MODL_ask_list_count(face_list,&coun

21、t);/Retrieves the count from a linked list of objects for(int i=0;i<count;i+) UF_MODL_ask_list_item(face_list,i,&obj); int type; double point 3 ; double dir 3 ; double box 6 ; double radius; double rad_data; int norm_dir ; UF_MODL_ask_face_data(obj,&type,point,dir,box,&radius,&rad

22、_data,&norm_dir);/Queries the data associated with a face if(type=22)/“22”代表有界平面 if(fabs(point2-origin2)< bottom=obj; if(fabs(point2-value)< UF_MODL_ask_feat_location(obj,location); top=obj; UF_MODL_create_simple_hole(location,direction,diam,height,angle,top,bottom,&feature_obj_id);UF_

23、MODL_ask_feat_faces(feature_obj_id,&face_list);UF_MODL_ask_list_count(face_list,&count);for(int i=0;i<count;i+) UF_MODL_ask_list_item(face_list,i,&obj);/Retrieves an object from a linked list of objects int typel; UF_MODL_ask_face_type(obj,&typel); /倒圓角 if(typel= UF_MODL_CYLINDRIC

24、AL_FACE ) uf_list_p_t facesl; UF_MODL_create_list(&facesl); UF_MODL_ask_shared_edges(top,obj,&facesl); const char * radius="3" int smooth_overflow=0; int cliff_overflow=0; int notch_overflow=0; double vrb_tool=3; tag_t feature_obj_idl; UF_MODL_create_blend(radius, facesl, smooth_ov

25、erflow, cliff_overflow, notch_overflow, vrb_tool, &feature_obj_id ); void ufusr(char *param, int *retcode, int param_len) if (!UF_CALL(UF_initialize() do_ugopen_api(); UF_CALL(UF_terminate(); int ufusr_ask_unload(void) return (UF_UNLOAD_IMMEDIATELY);運(yùn)行結(jié)果截屏如下:(2)創(chuàng)建一個(gè)對(duì)象,使其沿著X軸平移100,以Z軸為旋轉(zhuǎn)軸旋轉(zhuǎn)90度。代碼如下:#include <>#include<>#include<>#include<>#include<>#include<>#include<>extern void ufusr(char *param, int *retcode, int paramLen) if(UF_initialize()!=0) return; /獲取實(shí)體 tag_t display_part = UF_PART_ask_display_part(); tag_t objects = NULL_TAG; UF_OBJ_cycle

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論