秋爱 发表于 2015-7-23 17:23:00

创建两个圆柱体,求和,涂色,输出表达式并倒圆角。

本帖最后由 秋爱 于 2015-7-23 17:27 编辑

#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_obj.h>
#include <uf_part.h>


#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))


static int report_error( char *file, int line, char *call, int irc)
{
    if (irc)
    {
      char err,
             msg;


      sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
            irc, line, file);
      UF_get_fail_message(irc, err);


      UF_print_syslog(msg, FALSE);
      UF_print_syslog(err, FALSE);
      UF_print_syslog("\n", FALSE);
      UF_print_syslog(call, FALSE);
      UF_print_syslog(";\n", FALSE);


      if (!UF_UI_open_listing_window())
      {
            UF_UI_write_listing_window(msg);
            UF_UI_write_listing_window(err);
            UF_UI_write_listing_window("\n");
            UF_UI_write_listing_window(call);
            UF_UI_write_listing_window(";\n");
      }
    }


    return(irc);
}




/*****************************************************************************
**Activation Methods
*****************************************************************************/
/*Explicit Activation
**      This entry point is used to activate the application explicitly, as in
**      "File->Execute UG/Open->User Function..." */


tag_t part_tag = NULL_TAG;


UF_FEATURE_SIGN sign = UF_NULLSIGN;
double origin = {0,0,0};
char * height = "50";
char * diam = "30";
double direction = {0.0,0.0,1.0};
tag_t cyltag = NULL_TAG;


UF_FEATURE_SIGN sign1 = UF_POSITIVE;
double origin1 = {27,0,0};
char * height1 = "50";
char * diam1 = "30";
double direction1 = {0.0,0.0,1.0};
tag_t cyltag1 = NULL_TAG;


tag_t cyl_body_tag1 = NULL_TAG;


int num;
tag_t* exps;
int i;


char* string ;


uf_list_t * edge_list;


tag_t blendtag;


extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
    /* Initialize the API environment */
    if( UF_CALL(UF_initialize()) )
    {
      /* Failed to initialize */
      return;
    }
   
    /* TODO: Add your application code here */


      UF_PART_new("e:\\nxopen\\cc.prt",1,&part_tag);
      UF_MODL_create_cyl1(sign,origin,height,diam,direction,&cyltag);
      UF_MODL_create_cyl1(sign1,origin1,height1,diam1,direction1,&cyltag1);//与第一个圆柱求和
      UF_MODL_ask_feat_body(cyltag,&cyl_body_tag1);
      UF_OBJ_set_color(cyl_body_tag1,128);   //设置颜色
      UF_MODL_ask_exps_of_part(part_tag,&num,&exps);    //访问部件的所有表达式


      for (i=0;i<num;i++)
      {
    UF_MODL_ask_exp_tag_string(exps,&string);   //输入表达式标识,返回该表达式串
      UF_UI_open_listing_window();
      UF_UI_write_listing_window(string);
      UF_UI_write_listing_window("\n");
      }
    UF_free(exps);
      UF_free(string);


      UF_MODL_create_list(&edge_list);//创建链表以存放要倒角的边
      UF_MODL_ask_body_edges(cyl_body_tag1,&edge_list);//获取圆柱体的边
      UF_MODL_create_blend("0.7",edge_list,0,0,0,0.001,&blendtag);//对圆柱体的所有边进行倒圆角
      UF_MODL_delete_list(&edge_list);    //删除链表


    /* Terminate the API environment */
    UF_CALL(UF_terminate());
}


/*****************************************************************************
**Utilities
*****************************************************************************/


/* Unload Handler
**   This function specifies when to unload your application from Unigraphics.
**   If your application registers a callback (from a MenuScript item or a
**   User Defined Object for example), this function MUST return
**   "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload( void )
{
    return( UF_UNLOAD_IMMEDIATELY );
}






admin 发表于 2015-7-24 20:03:47

Perfect~!

admin 发表于 2015-7-24 20:03:48

Perfect~!
页: [1]
查看完整版本: 创建两个圆柱体,求和,涂色,输出表达式并倒圆角。