lesson3_CreateBlock
/* Include files */#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_part.h>
#include <uf_modl.h>
#include <uf_obj.h>
#include <uf_disp.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 coner = {0,0,0};
char *edges = {"length=100","width=40","height=50"};
tag_t blockTag = NULL_TAG;
const char * radius ="10";
int smooth_overflow = 0;
int cliff_overflow = 0;
int notch_overflow = 0;
double vrb_tool = 0.01;
tag_t blendfeatureTag =NULL_TAG;
uf_list_p_t vertical_edges_list;
uf_list_p_t edgeslist;
tag_t blockbodyTag;
double firstpoint,endpoint;
int vertixCount;
tag_t edge;
int edgesCount;
int i;
char mymsg;
int vertical_edges_Count;
UF_ATTR_value_t myattrvalue;
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
/* TODO: Add your application code here */
UF_UI_open_listing_window();
//new part
UF_CALL(UF_PART_new("E:\\NX\\lesson3.prt",1,&partTag));
//new block
UF_CALL(UF_MODL_create_block1(UF_NULLSIGN,coner,edges,&blockTag));//得到block特征的tag:blockTag
//create vertical list
UF_MODL_create_list(&vertical_edges_list);//create list
//feature -> body -> edge -> vertical edge
// 1 feature -> body
UF_MODL_ask_feat_body(blockTag,&blockbodyTag);
//2 body -> edge
UF_MODL_ask_body_edges(blockbodyTag,&edgeslist);
//UF_MODL_ask_feat_edges(blockTag,&edgeslist);//feature->edge是可以的
UF_MODL_ask_list_count(edgeslist,&edgesCount);
sprintf(mymsg,"edge count:%d\n",edgesCount);
UF_UI_write_listing_window(mymsg);
//edge -> vertical edge
for (i = 0; i < edgesCount; i++)
{
UF_MODL_ask_list_item(edgeslist,i,&edge);
UF_MODL_ask_edge_verts(edge,firstpoint,endpoint,&vertixCount);
if ((firstpoint==endpoint)&&(firstpoint==endpoint)&&(firstpoint!=endpoint))
{
UF_MODL_put_list_item(vertical_edges_list,edge);
//add arrtibute
myattrvalue.type = UF_ATTR_real;
myattrvalue.value.real = 10;
UF_ATTR_assign(edge,"blendradius",myattrvalue);
}
}
UF_MODL_ask_list_count(vertical_edges_list,&vertical_edges_Count);
sprintf(mymsg,"vertical_edges_Count:%d\n",vertical_edges_Count);
UF_UI_write_listing_window(mymsg);
//create blend(倒圆角)
UF_CALL(UF_MODL_create_blend(radius,vertical_edges_list,smooth_overflow,cliff_overflow,notch_overflow,vrb_tool,&blendfeatureTag));
UF_MODL_delete_list(&vertical_edges_list);
//change body color、translucency
UF_OBJ_set_color(blockbodyTag,21);//186红;21白
UF_OBJ_set_translucency(blockbodyTag,50);
/* 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]