Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to specify parameters in command line in UG NX

Status
Not open for further replies.

rajesha24

Automotive
Mar 26, 2014
11
Hi

I have a Macro but it says to input certain parameters in command line before executing can you please advise me on this

Thanks
Rajesh
 
Replies continue below

Recommended for you

Is it possible for you to post a screen shot of when you are required to input a parameter?
 
I took one of this from UGII folder



* The modules are placed into UGSAMPLES.
*
* In order to execute this program, input the following parameters
* on the command line as described below.
*
* 1. part name: Full path name or the part name.
* 2. drawing name: The drawing which we want to plot. The drawing belongs to the part.
* 3. plot name
* for the drawing: Will be created in the directory specified by the environment
* variable PLOT_HPGL_OUTPUT_DIR using the name provided with an
* extension of .hpp.
* 4. log file name: File which contains error messages and comparison results.
* Will be created in the directory specified using the name provided.
*
* The printer and profile for the plot are given by the #define statements below. These
* need to correspond to a printer / profile pair set up to create HPGL output. See the
* sample program, ufd_plot_drawings_hpgl.c, for details on how to do this.
*
* The following is an example:
* cmp_dwg_create.platform part.prt SH1 part_sh1 log_file.txt
*
* The platform can be hpp, osf or sol. The source code provided for this example
* may be used to produce an executable on other platforms as well.
*

*
****************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <uf.h>
#include <uf_defs.h>
#include <uf_obj.h>
#include <uf_part.h>
#include <uf_draw.h>
#include <uf_plot.h>

/* Type Defines */
#define CMP_DWG_CREATE__NO_ERRORS (0)
#define CMP_DWG_CREATE__BAD_PART_FILE (1)
#define CMP_DWG_CREATE__BAD_SHEET_NAME (2)
#define CMP_DWG_CREATE__BAD_PLOT_NAME (3)
#define CMP_DWG_CREATE__BAD_PRINTER (4)
#define CMP_DWG_CREATE__BAD_PROFILE (5)
#define CMP_DWG_CREATE__BAD_LOG_FILE (6)
#define CMP_DWG_CREATE__BAD_PLOT_DIR (7)
#define CMP_DWG_CREATE__BAD_DRAWINGS (8)
#define CMP_DWG_CREATE__BAD_LOAD (9)

#define NUM_EXPECTED_ARG ( 7 )

#define CMP_DWG_CREATE__MAX_WAIT (60)
#define CMP_DWG_CREATE__SLEEP_TIME (5)


typedef struct CMP_DWG_CREATE__line_data_s
{
char part_file[UF_CFI_MAX_PATH_NAME_LEN+1];
char sheet_name[UF_CFI_MAX_FILE_NAME_LEN+1];
char plot_name[UF_CFI_MAX_FILE_NAME_LEN+1];
char printer[UF_CFI_MAX_FILE_NAME_LEN+1];
char profile[UF_CFI_MAX_FILE_NAME_LEN+1];
char log_file[UF_CFI_MAX_FILE_NAME_LEN+1];
FILE *log_file_p;
} CMP_DWG_CREATE__line_data_t, *CMP_DWG_CREATE__line_data_p_t;

typedef struct CMP_DWG_CREATE__env_data_s
{
char plot_out_dir[UF_CFI_MAX_PATH_NAME_LEN+1];
} CMP_DWG_CREATE__env_data_t, *CMP_DWG_CREATE__env_data_p_t;



static void process_drawing(
CMP_DWG_CREATE__line_data_p_t line_data,
const tag_t drawing_sheet );
static void print_help( char *command );

#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
/* #define UF_CALL(uf_func) ( print_fail_message( #uf_func, __FILE__, __LINE__, (uf_func))) */
#define PRINT_ERROR(args) {printf("ERROR: "); printf args; printf("\n");}

static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133],
msg[133];

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

return(irc);
}

static void sleep_wait(
int time
)
{
clock_t time_to_wait = time * CLOCKS_PER_SEC;
clock_t start_time = clock();
clock_t cur_time = 0;

while (cur_time < time_to_wait)
{
cur_time = clock() - start_time;
}
}

static logical check_file_availability(
char *file_name,
logical wait
)
{
logical status = FALSE;
int total_wait = 0;
logical file_found = FALSE;

while( (total_wait <= CMP_DWG_CREATE__MAX_WAIT) && (file_found == FALSE) )
{
int file_exists = 0;

UF_CFI_ask_file_exist(file_name, &file_exists);

if ( file_exists == 0 )
file_found = TRUE;
else
{
if (wait)
{
sleep_wait( CMP_DWG_CREATE__SLEEP_TIME );
total_wait = total_wait + CMP_DWG_CREATE__SLEEP_TIME;
}
else
total_wait = CMP_DWG_CREATE__MAX_WAIT + 1;
}
}

if (file_found)
{
status = TRUE;
}

return( status );
}

static logical check_hpgl_printer(
const char *check_printer
)
{
logical result = false;
int i, num;
char **printers;


UF_CALL( UF_PLOT_ask_printer_names( &num, &printers ) );

for ( i=0; i < num; i++ )
{

if ( strcmp( printers, check_printer ) == 0 )
{
result = true;
break;
}
}

UF_free( printers );

return result;
}

static logical check_hpgl_profile(
char *check_printer,
const char *check_profile
)
{
logical result = false;
int i, num;
char **profiles;

UF_CALL( UF_PLOT_ask_profile_names( check_printer, &num, &profiles ) );

for ( i=0; i < num; i++ )
{
if ( strcmp( profiles, check_profile ) == 0 )
{
result = true;
break;
}
}

UF_free( profiles );

return result;
}

static int query_line_data(
int argc,
char *argv[],
CMP_DWG_CREATE__line_data_p_t line_data
)
{
/* Initialize ARG module for UGManager */
UF_CALL(uc4624(0, argc, argv));

if (argc != NUM_EXPECTED_ARG)
{
printf( "ERROR: Invalid number of command line arguments.\n" );
print_help(argv[0]);
return(1);
}

/* Get part_file option */
if ((uc4621(line_data->part_file) != 1) ||
(!check_file_availability(line_data->part_file, false)))
{
PRINT_ERROR(( "Part file does not exist.\n"));
print_help(argv[0]);
return(CMP_DWG_CREATE__BAD_PART_FILE);
}

/* Get sheet_name option */
if (uc4621(line_data->sheet_name) != 1)
{
PRINT_ERROR(( "Sheet name not specified.\n"));
print_help(argv[0]);
return(CMP_DWG_CREATE__BAD_SHEET_NAME);
}

/* Get plot_name option */
if (uc4621(line_data->plot_name) != 1)
{
PRINT_ERROR(( "Plot name not specified.\n"));
print_help(argv[0]);
return(CMP_DWG_CREATE__BAD_PLOT_NAME);
}

/* Get printer option */
if (uc4621(line_data->printer) != 1)
{
PRINT_ERROR(( "Printer is not specified.\n"));
print_help(argv[0]);
return(CMP_DWG_CREATE__BAD_PRINTER);
}
else if ( !check_hpgl_printer(line_data->printer) )
{
PRINT_ERROR(( "Printer named %s is not defined.\n", line_data->printer ));
return(CMP_DWG_CREATE__BAD_PRINTER);
}

/* Get profile option */
if (uc4621(line_data->profile) != 1)
{
PRINT_ERROR(( "Profile is not specified.\n"));
print_help(argv[0]);
return(CMP_DWG_CREATE__BAD_PROFILE);
}
else if ( !check_hpgl_profile(line_data->printer, line_data->profile) )
{
PRINT_ERROR(( "Profile named %s is not defined.\n", line_data->profile ));
return(CMP_DWG_CREATE__BAD_PROFILE);
}

/* Get log_file option */
if (uc4621(line_data->log_file) != 1)
{
PRINT_ERROR(( "Unable to open log file.\n"));
print_help(argv[0]);
return(CMP_DWG_CREATE__BAD_LOG_FILE);
}
else
{
line_data->log_file_p = fopen( line_data->log_file, "w");

if (line_data->log_file_p == NULL)
{
PRINT_ERROR(( "Unable to open log file.\n"));
print_help(argv[0]);
return(CMP_DWG_CREATE__BAD_LOG_FILE);
}
}

return(CMP_DWG_CREATE__NO_ERRORS);
}

static int query_env_data(
CMP_DWG_CREATE__env_data_p_t env_data
)
{
int return_code = CMP_DWG_CREATE__NO_ERRORS;
char *plot_path_string = NULL;

UF_translate_variable("PLOT_HPGL_OUTPUT_DIR", &plot_path_string);

if (plot_path_string != NULL)
{
int file_exists = 0;
/* Ensure that the given path is a valid directory */
return_code = UF_CFI_ask_file_exist(plot_path_string, &file_exists);

if (return_code != CMP_DWG_CREATE__NO_ERRORS || file_exists != 0)
{
PRINT_ERROR(("The plot path specified does not exist.\n"));
PRINT_ERROR(("Please set PLOT_HPGL_OUTPUT_DIR variable.\n"));
}

if (return_code == CMP_DWG_CREATE__NO_ERRORS)
strcpy(env_data->plot_out_dir, plot_path_string);
}
else
{
PRINT_ERROR(("No plot path specified.\n"));
PRINT_ERROR(("Please set PLOT_HPGL_OUTPUT_DIR variable.\n"));
return_code = CMP_DWG_CREATE__BAD_PLOT_DIR;
}

return (return_code);
}

int main( int argc, char *argv[] )
{
CMP_DWG_CREATE__line_data_t line_data;
CMP_DWG_CREATE__env_data_t env_data;
int return_code = CMP_DWG_CREATE__NO_ERRORS;

char error_message[MAX_LINE_SIZE+1];
int ifail = 0;
int inx;
tag_t part_tag = NULL_TAG; /* for UF_PART_open */

memset( &line_data, 0, sizeof(CMP_DWG_CREATE__line_data_t) );
/* Initialize */
if ( (return_code = UF_CALL(UF_initialize())) != CMP_DWG_CREATE__NO_ERRORS)
{
PRINT_ERROR(( "UG could not be initialized properly. \n"));
return( return_code );
}

if (return_code == CMP_DWG_CREATE__NO_ERRORS)
return_code = query_line_data(argc, argv, &line_data);

if (return_code == CMP_DWG_CREATE__NO_ERRORS)
return_code = query_env_data(&env_data);

if ( return_code == CMP_DWG_CREATE__NO_ERRORS )
{
UF_PART_load_status_t err_status; /* for UF_PART_open */

ifail = UF_PART_open( line_data.part_file, &part_tag, &err_status );
if ( err_status.n_parts != 0 )
{
for ( inx=0; inx<err_status.n_parts; ++inx)
{
UF_free( err_status.statuses );
UF_free_string_array( err_status.n_parts, err_status.file_names );
}
}

/* When a part is not opened because it doesn't exist, the part_tag remains
* equal to NULL_TAG, and no actual error is returned.
* We therefore choose to write our own error message to the log_file here.
*/
if ( part_tag == NULL_TAG )
{
fprintf( line_data.log_file_p, "ERROR: Failed to retrieve part %s \n", line_data.part_file );
ifail = -1;
}
}

if ( ifail == 0 )
{
int num = 0;
tag_t *drawings = NULL;
tag_t drawing_sheet;
char drawing_name[UF_OBJ_NAME_LEN+1];

UF_CALL( UF_DRAW_ask_drawings( &num, &drawings ) );
drawing_sheet = NULL_TAG;
for ( inx=0 ; inx < num ; inx++ )
{
UF_CALL( UF_OBJ_ask_name( drawings[inx], drawing_name ) );
if ( strcmp( drawing_name, line_data.sheet_name ) == 0 )
{
drawing_sheet = drawings[inx];
break;
}
}

UF_free(drawings);

if ( drawing_sheet == NULL_TAG )
{
fprintf( line_data.log_file_p, "Part %s does not have a drawing named %s\n",
line_data.part_file, line_data.sheet_name );
ifail = -1;
}
else
{
int scope = 1; /* Close part and all sub-assemblies */
int mode = 1; /* Unload part even if modified */

process_drawing( &line_data, drawing_sheet );
ifail = UF_PART_close( part_tag, scope, mode );
}
}

if ( (ifail != 0) && (ifail != -1) )
{
ifail = UF_get_fail_message( ifail, error_message );
fprintf( line_data.log_file_p, "ERROR: %s \n\n", error_message );
}

UF_terminate();
fclose( line_data.log_file_p );

return(0);
}

/*
We need a full file spec for the name of the CGM to pass to the print
routine.
*/
static char * get_cgm_name( const char *plot_name )
{
char *cgm_name;
char dir_name[UF_CFI_MAX_PATH_NAME_SIZE];
char *ext_loc;
char cgm_ext[] = ".cgm";

uc4565( 1, dir_name );
cgm_name = (char *) malloc( UF_CFI_MAX_PATH_NAME_SIZE * sizeof(char) );
if( cgm_name != NULL )
{
uc4575( dir_name, 2, plot_name, cgm_name );
ext_loc = strrchr( cgm_name, '.' );
if ( ext_loc )
*ext_loc = '\0';
strcat( cgm_name, cgm_ext );
}
return cgm_name;
}

static void process_drawing(
CMP_DWG_CREATE__line_data_p_t line_data,
const tag_t drawing_sheet )
{
char *job_name;
char *cgm_name;

cgm_name = get_cgm_name( line_data->plot_name );
UF_CALL( UF_PLOT_ask_default_job_name( drawing_sheet, &job_name ) );
UF_CALL( UF_PLOT_save_cgm( drawing_sheet, NULL, job_name,
NULL, cgm_name ) );

/* NOTE that cgm_name must be a full file spec. */
UF_CALL( UF_PLOT_print_file( cgm_name, line_data->printer,
line_data->profile, 1 ) );
uc4561( cgm_name, 0 );
UF_free( job_name );
free( cgm_name );
}

static void print_help(
char *command
)
{
printf( "%s <part_name> <drawing_name> <plot_name> <printer> <profile> <log_file>\n", command );
printf( " <part_name> Full path and name of drawing part.\n" );
printf( " <drawing_name> Name of drawing sheet in part.\n" );
printf( " <plot_name> Name of .hpp file to be created.\n" );
printf( " <printer> Name of printer to use.\n" );
printf( " <profile> Name of printer profile to use.\n" );
printf( " <log_file> Full path and name of output log file.\n");
printf( "\n");
printf( "The following environmental variables should also be set: \n" );
printf( " PLOT_HPGL_OUTPUT_DIR Output directory of plotter.\n");
printf( "\n\n" );
}


How to input those parameters.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor