블로그 이미지
진연
3차원 CAD프로그램인 UGS에서 지원하는 API를 이용하여 프로그램하는 방법등을 소개하는 블로그입니다. 혹시 연락이 필요하신분은 youni7311@hanmail.net로 메일 보내주세요..

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
2008. 8. 5. 11:50 코드자료

Macro를 프로그램에서 Playback 할수 있는 코드입니다. 독일에 모 사이트에서 얻었습니다...^^;
VS2005, NX5에서 확인했고, 문제없이 실행됩니다.

#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_exit.h>
#include <uf_cfi.h>
#include <uf_ui.h>
#include <uf_disp.h>


#define  __API_LIBRARY_V16   "libugui"
#define  __API_LIBRARY_V15   "libinternal"
#define  __API_LIBRARY_V14   "ugraf140"
#define  __API_LIBRARY_V13   "ugraf130"

#define  __API_FUNCTION  "?MACRO_playback_from_usertool@@YAXPBD@Z"

static void (* MACRO_playback_from_usertool_f_p)
          (
          char  *macroSpecP  /*  => */
          ) = NULL;


#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[133],
         messg[300];

    UF_get_fail_message (irc,
                         err);
    sprintf (messg,
             "\n%s\nerror %d at line %d in %s\n%s",
             err,
             irc,
             line,
             file,
             call);
     printf ("%s\n",
             messg);
     strcpy (&messg[129],
             "...");
     uc1601 (messg,
             TRUE);  /* Internal only - remove for external */
  }
return(irc);
}


void ufusr ( char *param, int *retcode, int paramLen )
{
char     libSpec[UF_CFI_MAX_PATH_NAME_LEN + 1];
char     *ugRootDirP;
char     *releaseP;
char     *libNameP;
char     *macroFileP;
int      rc;

rc = UF_CALL ( UF_initialize () );
if ( rc ) return;

/*
 *   Get UG release string.
 */

rc = UF_CALL ( UF_get_release (&releaseP) );
if ( rc ) return;

printf ("releaseP = \"%s\"\n",releaseP);

/*
 *   Build library filename.
 */

rc = UF_CALL ( UF_translate_variable ("UGII_ROOT_DIR",
                                      &ugRootDirP) );
if ( rc ) return;

for ( ; ; )
  {
    if ( strncmp (releaseP, "NX", 2) == 0 || strcmp (releaseP, "V16.0") >= 0 )
      {
        libNameP = __API_LIBRARY_V16;
        break;
      } /* if */
    if ( strcmp (releaseP, "V15.0") == 0 )
      {
        libNameP = __API_LIBRARY_V15;
        break;
      } /* if */
    if ( strcmp (releaseP, "V14.0") == 0 )
      {
        libNameP = __API_LIBRARY_V14;
        break;
      } /* if */
    if ( strcmp (releaseP, "V13.0") == 0 )
      {
        libNameP = __API_LIBRARY_V13;
        break;
      } /* if */
    return;
  } /* for */

rc = UF_CALL ( uc4575 (ugRootDirP,
                       115,  /* .dll */
                       libNameP,
                       libSpec) );
if ( rc ) return;

printf ("libSpec = \"%s\"\n",libSpec);

/*
 *   Execute macro file.
 */

rc = UF_CALL ( UF_load_library (libSpec,
                                __API_FUNCTION,
                                (void *)&MACRO_playback_from_usertool_f_p) );
if ( rc ) return;

printf ("MACRO_playback_from_usertool_f_p = %p\n",MACRO_playback_from_usertool_f_p);

rc = UF_CALL ( UF_translate_variable ("__MACRO_FILE",
                                      &macroFileP) );
if ( rc ) return;

printf ("__MACRO_FILE = %s\n",macroFileP);

if ( macroFileP == NULL ) return;

MACRO_playback_from_usertool_f_p (macroFileP);

rc = UF_CALL ( UF_terminate () );
if ( rc ) return;
}


int ufusr_ask_unload ( void )
{
return (UF_UNLOAD_IMMEDIATELY);
}


posted by 진연
prev 1 2 3 4 5 6 7 8 ··· 23 next