且听风吟 发表于 2015-7-26 22:12:05

第二课圆柱创建轴线

/*****************************************************************************
**
** test.c
**
** Description:
**   Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_curve.h>
#include <uf_part.h>
#include <uf_modl_types.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;
tag_t tar_tag=NULL_TAG;
double origin={0.0,0.0,0.0};
char *height="30";
char *diam="100";
double direction={0.0,1.0,0.0};
tag_t cylinderfea_tag=NULL_TAG;
uf_list_p_t edge_list=NULL;
int edge_count;
char msg;
int i=0;
tag_t edge_tag=NULL_TAG;
tag_t curve_tag=NULL_TAG;
tag_t point_tag=NULL_TAG;
tag_t line_tag=NULL_TAG;
tag_t point_tag2=NULL_TAG;
double cen;
UF_CURVE_line_t line_coord;//最好不要定义为指针
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 */
//1.create a new part
UF_PART_new("C:\\nx_work\\cylinder.prt",1,&part_tag);
//2.create a new cylinder
UF_MODL_create_cylinder(UF_NULLSIGN,tar_tag,origin,height,diam,direction,&cylinderfea_tag);
//3.get the edge list
UF_MODL_ask_feat_edges(cylinderfea_tag,&edge_list);
//4.get the edges
UF_MODL_ask_list_count(edge_list,&edge_count);

//5.get the centers
for(;i<edge_count;++i){
UF_MODL_ask_list_item(edge_list,i,&edge_tag);
//UF_MODL_create_curve_from_edge(edge_tag,&curve_tag);
UF_CURVE_ask_centroid(edge_tag,cen);
}
//6.create line
//UF_CURVE_create_point(cen,&point_tag);
//UF_CURVE_create_point(cen,&point_tag2);
line_coord.start_point=cen;
line_coord.start_point=cen;
line_coord.start_point=cen;
line_coord.end_point=cen;
line_coord.end_point=cen;
line_coord.end_point=cen;
UF_CURVE_create_line(&line_coord,&line_tag);
//UF_MODL_ask_list_item()
    /* 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-27 11:00:52

继续加油哦 !!!
页: [1]
查看完整版本: 第二课圆柱创建轴线