文星和合 发表于 2015-4-21 21:14:38

lesson2exercise_CreateCylinder

/* Include files */
#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_part.h>
#include <uf_obj.h>;
#include <uf_curve.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..." */

extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
    /* Initialize the API environment */
tag_t partTag=NULL_TAG;
double origin={0,0,0};
char *height="200";
char *diam="20";
double direction={1,1,1};
tag_t cy_obj_id=NULL_TAG;
uf_list_p_t edge_list;
int count=0;
tag_t edge=NULL_TAG;
double originalpoint;
UF_CURVE_line_t curve_coords;
UF_CURVE_line_t mycurve_coords;
tag_t linetag=NULL_TAG;
tag_t body_ID=NULL_TAG;
int i;
char mymsg;
    if( UF_CALL(UF_initialize()) )
    {
      /* Failed to initialize */
      return;
    }
   
    /* TODO: Add your application code here */
// 1 new part
UF_CALL(UF_PART_new("E:\\NX\\rob.prt",1,&partTag));   //双斜杠

//2 new cylinder
UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,origin,height,diam,direction,&cy_obj_id));
UF_MODL_ask_feat_body(cy_obj_id,&body_ID);
//feature -> body
UF_OBJ_set_color(body_ID,21);
//change translucency
UF_OBJ_set_translucency(body_ID,50);//先设置:菜单->首选项->可视化性能->一般图形,反选禁用透明度
//UF_OBJ_set_color(cy_obj_id,21);//错误的用法,cy_obj_id是feature的tag,不是body的tag
//3 new line
UF_CALL(UF_MODL_ask_feat_edges(cy_obj_id,&edge_list));
UF_MODL_ask_list_count(edge_list,&count);
if (count>0)
{
   for(i=0;i<count;i++)
{
   UF_MODL_ask_list_item(edge_list,i,&edge);
   UF_CURVE_ask_centroid(edge,originalpoint);//计算圆弧中心
}
for (i = 0; i <3; i++)
{
      curve_coords.start_point=originalpoint;
   curve_coords.end_point=originalpoint;
}
// UF_UI_open_listing_window();
// sprintf_s(mymsg,sizeof(mymsg),"point1:%f,%f,%f point2:%f,%f,%f\n",curve_coords.start_point,curve_coords.start_point,curve_coords.start_point,curve_coords.end_point,curve_coords.end_point,curve_coords.end_point);
//UF_UI_write_listing_window(mymsg);
// uc1601(mymsg,1);
UF_CURVE_create_line(&curve_coords,&linetag);   //创建直线
UF_CURVE_ask_line_data(linetag,&mycurve_coords);//获取直线的端点
sprintf_s(mymsg,sizeof(mymsg),"start:%f,%f,%fend:%f,%f,%f\n",mycurve_coords.start_point,mycurve_coords.start_point,mycurve_coords.start_point,mycurve_coords.end_point,mycurve_coords.end_point,mycurve_coords.end_point);
//UF_CURVE_ask_line_data(linetag,&curve_coords);
//sprintf_s(mymsg,sizeof(mymsg),"start:%f,%f,%fend:%f,%f,%f\n",curve_coords.start_point,curve_coords.start_point,curve_coords.start_point,curve_coords.end_point,curve_coords.end_point,curve_coords.end_point);
//UF_UI_write_listing_window(mymsg);
uc1601(mymsg,1);
}
else
{
uc1601("no edge founf",1);
}


//UF_OBJ_set_color(cy_obj_id, UF_OBJ_WHITE);
//UF_PART_save();//保存部件
//UF_PART_close_all();   //关闭所有

    /* 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 );
}


我把圆柱的方向设成【1,1,1】,成功了

admin 发表于 2015-4-22 11:10:39

支持 !不错!

hcaini0829 发表于 2015-7-17 22:23:12

很厉害 支持支持
页: [1]
查看完整版本: lesson2exercise_CreateCylinder