青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

青华模具培训学院
查看: 1882|回复: 1

[教程] UG NXapi二次开发教程源代码_创建一个圆柱,并打孔倒角

[复制链接]
发表于 2014-3-12 09:44 | 显示全部楼层 |阅读模式

原帖地址:http://www.ugufun.com/?p=111

ug NXapi二次开发教程源代码_创建一个圆柱,并打孔倒角

以下为代码部分:

#include <stdio.h>

#include <uf.h>

#include <uf_ui.h>

#include <uf_disp.h>

#include<uf_modl.h>

#include<uf_layer.h>

#include<uf_assem.h>

#include<uf_obj.h>

#include<uf_part.h>

#include<iostream>

#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);

}

static void do_UGopen_api(void)

{

     UF_FEATURE_SIGN sign = UF_NULLSIGN;

     tag_t target = NULL_TAG;

     double origin [] = {0.0,0.0,0.0};

     char* height = "100";

     char* cyl_diam = "80";

     double cyl_direction [] = {0.0,0.0,1.0};

     tag_t cyl_feat_tag = NULL_TAG;

     UF_MODL_create_cylinder(sign,target,origin,height,cyl_diam,cyl_direction,&cyl_feat_tag);

     double value;

     tag_t target1;

     UF_MODL_create_exp_tag(height,&target1);//Creates a parameter expression, based upon the input string.

     UF_MODL_ask_exp_tag_value(target1,&value);//Asks the value of an expression tag.

     double location[3]={0.0,0.0,0.0} ;

      double direction [] = {0.0,0.0,1.0};

     tag_t obj=null_tag;

     char *diam="30";

     char *angle="0";

     tag_t bottom,top;

     tag_t feature_obj_id ;

     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,&count);//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_data,&norm_dir);//Queries the data associated with a face

     if(type==22)//“22”代表有界平面

     {

         if(fabs(point[2]-origin[2])<0.0005)

         {

             bottom=obj;

         }

         if(fabs(point[2]-value)<0.0001)

         {

             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_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_CYLINDRICAL_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_overflow, 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);

}

" M1 V! ~7 A" s8 s* M3 X2 |
发表于 2014-5-4 14:45 | 显示全部楼层
如何利用vc编写代码,通过向mfc制作的界面输入数值改变已经绘制好的圆柱体的尺寸啊???请教!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|关于我们|sitemap|小黑屋|Archiver|手机版|UG网-UG技术论坛-青华数控模具培训学校 ( 粤ICP备15108561号 )

GMT+8, 2024-5-4 02:05 , Processed in 0.052511 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表