学UG二次开发就上UG网:
线性阵列函数:UF_MODL_create_linear_iset(创建一个方块体与一个圆柱,并执行求差,然后对得到的孔进行线性阵列)
阵列UG二次开发
NX二次开发阵列C++源代码:
- UF_FEATURE_SIGN sign;
- UF_FEATURE_SIGN sign1;
- #define a UF_NULLSIGN
- #define c UF_NEGATIVE
- int m;
- #define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
- static int report(char *file, int line, char *call, int irc)
- {
- if (irc)
- {
- char messg[133];
- printf("%s, line %d: %s\n", file, line, call);
- (UF_get_fail_message(irc, messg)) ?
- printf(" returned a %d\n", irc) :
- printf(" returned error %d: %s\n", irc, messg);
- }
- return(irc);
- }
- void float_to_char(double b, char cc[])
- {
- FILE *fp5;
- fp5 = fopen("aut.dat", "w");
- fprintf(fp5, "%15.8f\n", b);
- fclose(fp5);
- cc[0] = '\0';
- fp5 = fopen("aut.dat", "r");
- fscanf(fp5, "%s\n", cc);
- fclose(fp5);
- return;
- }
- static void do_ugopen_api(float abc[], float orig1[], float orig2[])
- {
- int method = 0;
- double block_orig[3] = { orig1[0], orig1[1], orig1[2] };
- double cyl_orig[3] = { orig2[0], orig2[1], orig2[2] };
- char *block_len[3];
- char bb[4][20];
- char *cyl_height;
- char *cyl_diam;
- char cc[3][20];
- double direction[3] = { 0, 0, m };
- char *number_in_x;
- char *distance_x;
- char *number_in_y;
- char *distance_y;
- char dd[5][20];
- tag_t blk_obj;
- tag_t cyl_obj_id;
- uf_list_p_t feature_list;
- tag_t feature_obj_id;
- float_to_char(abc[0], bb[0]);
- block_len[0] = bb[0];
- float_to_char(abc[1], bb[1]);
- block_len[1] = bb[1];
- float_to_char(abc[2], bb[2]);
- block_len[2] = bb[2];
- UF_CALL(UF_MODL_create_block1(sign, block_orig, block_len, &blk_obj));
- float_to_char(abc[3], cc[0]);
- cyl_height = cc[0];
- float_to_char(abc[4], cc[1]);
- cyl_diam = cc[1];
- UF_CALL(UF_MODL_create_cyl1(sign1, cyl_orig, cyl_height, cyl_diam, direction, &cyl_obj_id));
- float_to_char(abc[5], dd[0]);
- number_in_x = dd[0];
- float_to_char(abc[6], dd[1]);
- distance_x = dd[1];
- float_to_char(abc[7], dd[2]);
- number_in_y = dd[2];
- float_to_char(abc[8], dd[3]);
- distance_y = dd[3];
- UF_CALL(UF_MODL_create_list(&feature_list));
- UF_CALL(UF_MODL_put_list_item(feature_list, cyl_obj_id));
- UF_CALL(UF_MODL_create_linear_iset(method, number_in_x, distance_x, number_in_y, distance_y,
- feature_list, &feature_obj_id));
- return;
- }
- void main()
- {
- float bac[9] = { 5.0, 4.0, 3.0, 4.0, 1.0, 3.0, 1.5, 2.0, 2.0 };
- //长方体和圆柱体的尺寸参数
- float orig1[3] = { 0.0, 0.0, 0.0 }; //长方体的原点
- float orig2[3] = { 1.0, 1.0, 0.0 }; //圆柱体的原点
- sign1 = c; //表示圆柱体
- sign = a; //表示长方体
- m = 1;
- do_ugopen_api(bac, orig1, orig2);
- return;
- }
- 调用程序:
- /* TODO: Add your application code here */
- /*中磊国际模具培训-线型阵列*/
- {
- if (!UF_CALL(UF_initialize()))
- {
- main();
- }
- UF_CALL(UF_terminate());
- }
复制代码
|