点击查看详细介绍

NX UGapi二次开发创建一个圆柱打孔倒角的源代码

nxopen 11年前 14091 56

购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008  QQ号:85585969  


NX UGapi二次开发创建一个圆柱打孔倒角的源代码


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


4

最新回复 (56)
  • zcdong86 11年前
    1

    资料不错!谢谢分享!

  • zcdong86 11年前
    2

    资料不错!谢谢分享!

  • 豆沙包2010 11年前
    3

    谢谢楼主分享,学习下

  • gentelwind 11年前
    4

    谢谢楼主分享,学习下

  • kevin 11年前
    5

    继续努力,我要学习,我要向上!

  • SNFGDGVJX 10年前
    6

    资料不错!谢谢分享!

  • lzhyi VIP会员 10年前
    7

    谢谢分享,谢楼主了.

  • f1632947 10年前
    8

    谢谢楼主,好好学习,天天向上

  • watersam 10年前
    9

    谢谢楼主,好好学习,天天向上

  • xiongruiabc 10年前
    10

    hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

  • ZF6655 10年前
    11

    学习学习,此代码是在VS几中生成的呀

  • songsi8 10年前
    12

    学习一下!!!!!!!!!

  • yuleihz 10年前
    13

    谢谢楼主好好学习,天天向上

  • yangshizhan 10年前
    14

    资料不错!谢谢分享!

  • awnusspgy VIP会员 10年前
    15

    顶一个,正需要这方面的资料,非常好

请登录后发表新帖