UG NX二次开发源码分享: 导出parasolid 格式文件
UG NX二次开发源码分享: 导出parasolid 格式文件#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_obj.h>
#include <uf_object_types.h>
#include <uf_modl.h>
#include <uf_part.h>
#include <uf_assem.h>
#include <uf_ps.h>
#define ECHO(X) { UF_UI_open_listing_window(); \
UF_UI_write_listing_window(X); \
UF_print_syslog(X, FALSE); }
#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);
ECHO(msg);
ECHO(err);
ECHO("\n");
ECHO(call);
ECHO(";\n");
}
return(irc);
}
static tag_t ask_next_solid_body(tag_t part, tag_t body)
{
int
subtype,
type;
while (!UF_CALL(UF_OBJ_cycle_objs_in_part(part, UF_solid_type, &body))
&& (body != NULL_TAG))
{
UF_CALL(UF_OBJ_ask_type_and_subtype(body, &type, &subtype));
if (subtype == UF_solid_body_subtype)
{
UF_CALL(UF_MODL_ask_body_type(body, &type));
if (type == UF_MODL_SOLID_BODY) return body;
}
}
return NULL_TAG;
}
static int allocate_memory(unsigned int nbytes, void **where)
{
int
resp;
*where = UF_allocate_memory(nbytes, &resp);
return resp;
}
static int make_an_array(uf_list_p_t *object_list, tag_t **objects)
{
int
ii,
n;
uf_list_p_t
temp;
UF_CALL(UF_MODL_ask_list_count(*object_list, &n));
UF_CALL(allocate_memory(n * sizeof(tag_t), (void **)objects));
for (ii = 0, temp = *object_list; ii < n; temp = temp->next, ii++)
(*objects) = temp->eid;
UF_CALL(UF_MODL_delete_list(object_list));
return n;
}
static int ask_all_prototype_solids(tag_t part, tag_t **solids)
{
tag_t
solid = NULL_TAG;
uf_list_p_t
solid_list;
UF_CALL(UF_MODL_create_list(&solid_list));
while ((solid = ask_next_solid_body(part, solid)) != NULL_TAG)
{
if (UF_ASSEM_is_occurrence(solid))
UF_CALL(UF_MODL_put_list_item(solid_list,
UF_ASSEM_ask_prototype_of_occ(solid)));
else
UF_CALL(UF_MODL_put_list_item(solid_list, solid));
}
return (make_an_array(&solid_list, solids));
}
#define WRITE_D(X) (write_integer_to_listing_window(#X, X))
static void write_integer_to_listing_window(char *title, int n)
{
char
msg;
sprintf(msg, "%s = %d\n", title, n);
ECHO(msg);
}
#define WRITE_S(X) (write_string_to_listing_window(#X, X))
void write_string_to_listing_window(char *title, char *string)
{
char
msg;
if (string != NULL)
sprintf(msg, "%s = \"%s\"\n", title, string);
else
sprintf(msg, "%s = NULL\n", title);
ECHO(msg);
}
static void build_unique_temp_name(char *fspec, int ftype)
{
char
*tmp_dir,
unique;
UF_CALL(UF_translate_variable("UGII_TMP_DIR", &tmp_dir));
UF_CALL(uc4577(unique));
UF_CALL(uc4575(tmp_dir, ftype, unique, fspec));
}
static uf_list_p_t make_a_list(int count, tag_t *item_array)
{
int
ii;
uf_list_p_t
list;
UF_CALL(UF_MODL_create_list(&list));
for (ii = 0; ii < count; ii++)
UF_CALL(UF_MODL_put_list_item(list, item_array));
return (list);
}
static void do_it(void)
{
int
ii,
n;
tag_t
part = UF_PART_ask_display_part(),
*proto_solids;
char
exported_to,
*handle;
uf_list_p_t
body_list;
n = ask_all_prototype_solids(part, &proto_solids);
for (ii = 0; ii < n; ii++)
{
WRITE_D(ii);
WRITE_D(proto_solids);
handle = UF_TAG_ask_handle_of_tag(proto_solids);
WRITE_S(handle);
UF_free(handle);
build_unique_temp_name(exported_to, 0);
strcat(exported_to, ".x_t");
body_list = make_a_list(1, &proto_solids);
UF_CALL(UF_PS_export_data(body_list, exported_to));
UF_CALL(UF_MODL_delete_list(&body_list));
WRITE_S(exported_to);
}
if (n > 0) UF_free(proto_solids);
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
if (UF_CALL(UF_initialize())) return;
do_it();
UF_terminate();
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}
谢谢,好东西 好非常好 学习中,谢谢分享!
页:
[1]