On Sat, Mar 10, 2001 at 07:18:01PM -0000, Bill Payter wrote:
> I cannot get the macro I'm writing for Free-Form 11.5 to work properly.
>
> At the end of the macro I want to create code with a variable file name,
> always to the same directory, and then save the .pm4 file with a variable
> file name, always to the same directory.
>
> I cannot get this to work, I've even managed to save files called %#SNAME
> which I thought impossible.
>
> Your help is required urgently, I have to deliver the macro to the customer
> this week!
>
> (CW is deisol 'as the sun', and CCW is widdershins.)
Hi Bill,
Perhaps not the most timely response, but...
Following is a macro which I wrote for a previous employer, you should be
able extract most of what you need from it.
Best regards,
Kelly
// Code macro follows
//////////////////////////////////////////////////////////////////////////////
// Production_Milling v10.0 Windows
// Wes-Tech Code Generation Macro File
//////////////////////////////////////////////////////////////////////////////
// Revision history:
//
// 02/10/98, KDGrills
// Created.
//
// 02/12/98, KDGrills
// added F_EXIST code to @FILE_NAME, to suppress false overwrite prompt
//
// 01/22/99, KDGrills
// added @VALIDATE_TOOL_NO section to validate tool numbers
//
//////////////////////////////////////////////////////////////////////////////
// To add additional machine:
//
// 1. Add declaration for machine (@VAR_DECLARE Section):
// (STRING:#MACH_XX)
// 2. Add path to .tmp / .smf files (@VAR_ASSIGN Section):
// (#MACH_XX=m:\\cnc\\post\\machine)
// 3. Increment number of machines (@VAR_ASSIGN Section):
// (#MACH_QTY=XX)
// 4. Insert additional Else - If block for tool capacity (@VALIDATE_TOOL_NO Section):
// ELSE
// IF(#MACHINE=XX)
// #max_tool=XX
// 5. Insert corresponding ENDIF
// 6. Insert additional Else - If block for machine (@CODE Section):
// ELSE
// IF(#MACHINE=XX)
// CODE[FN=#FILE, MF=STRTMP("%#MACH_4%#SMF_EXT"),
// TF=STRTMP("%#MACH_XX%#TMP_EXT"), SH=#DISPLAY, DC=#DISPLAY, ST=0, DT=0, SP=5]
// 7. Insert corresponding ENDIF
//
//////////////////////////////////////////////////////////////////////////////
pause[TX="Wes-Tech Automation Systems\n
Code Generation Macro File\n
Developed by Kelly D. Grills",LR=10,LC=15,PT=2]
//////////////////////////////////////////////////////////////////////////////
@VAR_DECLARE
//Variable declarations
STRING:#ERROR_STRING
STRING:#CURRENT_MACRO
STRING:#EDITOR
STRING:#FILE_PATH
STRING:#FILE_EXT
STRING:#FILE
STRING:#MACH_1
STRING:#MACH_2
STRING:#MACH_3
STRING:#MACH_4
STRING:#MACH_5
STRING:#MACH_6
STRING:#TMP_EXT
STRING:#SMF_EXT
//////////////////////////////////////////////////////////////////////////////
@VAR_ASSIGN
//Variable assignments
#CURRENT_MACRO=MCLFILE()
//Path to text editor
#EDITOR=D:\\Data\\winedit\\WINEDIT.EXE
//Default path
#FILE_PATH=m:\\CNC\\DOWNLOAD\\
//Default extension
#FILE_EXT=.NC
//Default code file
#FILE=STRIP_EXT(GET_NAME(SHPFILE()))
#FILE=STRTMP("%#FILE_PATH%#FILE%#FILE_EXT")
//Paths to .tmp / .smf files
#MACH_1=m:\\cnc\\post\\mc-4vae
#MACH_2=m:\\cnc\\post\\vtc-30c
#MACH_3=m:\\cnc\\post\\vtc-20B
#MACH_4=m:\\cnc\\post\\mx-45vae
#MACH_5=m:\\cnc\\post\\vf-3
#MACH_6=m:\\cnc\\post\\mcv1000
//Number of machines
#MACH_QTY=6
//Default template / machine file extensions
#TMP_EXT=.tmp
#SMF_EXT=.smf
//////////////////////////////////////////////////////////////////////////////
@MACHINE_NAME
//Get machine to code for
#MACHINE=1
prompt[TX="Machine to code for:\n
1. Okuma MC-4VAE 2. Mazak VTC-30C\n
3. Mazak VTC-20B 4. Okuma MX-45VAE\n
5. Haas Vf-3 6. Leadwell MCV1000AP",VN="machine",LR=10,LC=15]
WHILE(#MACHINE <1, OR #MACHINE >#MACH_QTY)
#MACHINE=1
prompt[TX="Machine to code for:\n
1. Okuma MC-4VAE 2. Mazak VTC-30C\n
3. Mazak VTC-20B 4. Okuma MX-45VAE\n
5. Haas Vf-3 6. Leadwell MCV1000AP",VN="machine",LR=10,LC=15]
ENDW
//////////////////////////////////////////////////////////////////////////////
@VALID_TOOL
//Validate tool numbers??
#VALID=1
prompt[TX="Validate tool numbers?\n
0. No\n
1. Yes",VN="VALID",LR=10,LC=15]
WHILE(#VALID < >0, AND #VALID < >1)
#VALID=1
prompt[TX="Validate tool numbers?\n
0. No\n
1. Yes",VN="VALID",LR=10,LC=15]
ENDW
IF(#VALID=0)
GOTO(FILE_NAME)
ENDIF
//////////////////////////////////////////////////////////////////////////////
@VALIDATE_TOOL_NO
//Validate tool numbers
IF(#MACHINE=1)
#max_tool=20
ELSE
IF(#MACHINE=2)
#max_tool=48
ELSE
IF(#MACHINE=3)
#max_tool=24
ELSE
IF(#MACHINE=4)
#max_tool=20
ELSE
IF(#MACHINE=5)
#max_tool=20
ELSE
IF(#MACHINE=6)
#max_tool=24
//Insert additional machine here
ELSE
#ERROR_STRING="Invalid Machine Value"
GOTO(EXIT_FAILURE)
//Insert corresponding ENDIF here
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
#COUNTER=1
#INVALID_COUNT=0
#FLAG=0
WHILE(#COUNTER<=TOTEL()) //Loop thru all elements...
IF(LAY(#COUNTER)=-1) //If element is toolpath...
#CURRENT_TOOL=JTOOL(#COUNTER) //Extract its tool number
IF(#CURRENT_TOOL>#MAX_TOOL) //If it's greater than the machines
capacity...
IF(#FLAG<>#CURRENT_TOOL) //If this tool is different than the
previous one...
#FLAG=#CURRENT_TOOL //Save for the next comparison
#INVALID_COUNT=#INVALID_COUNT + 1 //Increment the invalid count, and prompt
the user
pause[TX=STRTMP("Current tool number = %#CURRENT_TOOL
Magazine capacity = %#MAX_TOOL"),LR=10,LC=15,PT=0]
ENDIF
ENDIF
ENDIF
#COUNTER=#COUNTER + 1 //Increment the counter
ENDW
IF(#INVALID_COUNT>0) //If there was an invalid tool number exit
with an error
#ERROR_STRING=STRTMP("%#INVALID_COUNT tools violate magazine capacity of %#MAX_TOOL")
GOTO(EXIT_FAILURE)
ENDIF
//////////////////////////////////////////////////////////////////////////////
@FILE_NAME
//Get / validate file name
prompt[TX="Name for Code file:",VN="FILE",LR=10,LC=15]
IF(F_EXIST(#FILE)=0)
AUTO_ANSWER[AA=YES] //if file doesn't exist automatically overwrite
ELSE
AUTO_ANSWER[AA=OFF] //otherwise prompt for overwrite permission
ENDIF
F_OPEN[FN=#FILE, TY=W] //try to open file for writing
IF(F_ERROR() > 0) //if open fails, or file is not writeable:
#ERROR_STRING=F_ERRSTR() //save the error type
F_CLOSE[FN=#FILE] //close the file
GOTO(EXIT_FAILURE) //exit with an error
ELSE
F_CLOSE[FN=#FILE] //otherwise simply close the file
ENDIF
//////////////////////////////////////////////////////////////////////////////
@DISPLAY
//Display toolpath??
#DISPLAY=1
prompt[TX="Show toolpath?\n
0. No\n
1. Yes",VN="DISPLAY",LR=10,LC=15]
WHILE(#DISPLAY < >0, AND #DISPLAY < >1)
#DISPLAY=1
prompt[TX="Show toolpath?\n
0. No\n
1. Yes",VN="DISPLAY",LR=10,LC=15]
ENDW
//////////////////////////////////////////////////////////////////////////////
@CODE
//Generate the code file
IF(#MACHINE=1)
CODE[FN=#FILE, MF=STRTMP("%#MACH_1%#SMF_EXT"),
TF=STRTMP("%#MACH_1%#TMP_EXT"), SH=#DISPLAY, DC=#DISPLAY, ST=0, DT=0, SP=5]
ELSE
IF(#MACHINE=2)
CODE[FN=#FILE, MF=STRTMP("%#MACH_2%#SMF_EXT"),
TF=STRTMP("%#MACH_2%#TMP_EXT"), SH=#DISPLAY, DC=#DISPLAY, ST=0, DT=0, SP=5]
ELSE
IF(#MACHINE=3)
CODE[FN=#FILE, MF=STRTMP("%#MACH_3%#SMF_EXT"),
TF=STRTMP("%#MACH_3%#TMP_EXT"), SH=#DISPLAY, DC=#DISPLAY, ST=0, DT=0, SP=5]
ELSE
IF(#MACHINE=4)
CODE[FN=#FILE, MF=STRTMP("%#MACH_4%#SMF_EXT"),
TF=STRTMP("%#MACH_4%#TMP_EXT"), SH=#DISPLAY, DC=#DISPLAY, ST=0, DT=0, SP=5]
ELSE
IF(#MACHINE=5)
CODE[FN=#FILE, MF=STRTMP("%#MACH_5%#SMF_EXT"),
TF=STRTMP("%#MACH_5%#TMP_EXT"), SH=#DISPLAY, DC=#DISPLAY, ST=0, DT=0, SP=5]
ELSE
IF(#MACHINE=6)
CODE[FN=#FILE, MF=STRTMP("%#MACH_6%#SMF_EXT"),
TF=STRTMP("%#MACH_6%#TMP_EXT"), SH=#DISPLAY, DC=#DISPLAY, ST=0, DT=0, SP=5]
//Insert additional machine here
ELSE
#ERROR_STRING="Invalid Machine Value"
GOTO(EXIT_FAILURE)
//Insert corresponding ENDIF here
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
//////////////////////////////////////////////////////////////////////////////
@EDIT
//Edit the code file??
#EDIT=1
prompt[TX=STRTMP("Edit NC File?\n
0. No\n
1. Yes"),VN="EDIT",LR=10,LC=15]
WHILE(#EDIT < >0, AND #EDIT < >1)
#EDIT=1
prompt[TX=STRTMP("Edit NC File?\n
0. No\n
1. Yes"),VN="EDIT",LR=10,LC=15]
ENDW
IF(#EDIT=1)
SHELL[CMD_LN=STRTMP("%#EDITOR %FILE"),WA=0,DP=0]
ENDIF
GOTO(EXIT_SUCCESS)
//////////////////////////////////////////////////////////////////////////////
//Houston, we have a problem.
@EXIT_FAILURE
pause[TX=STRTMP("Error!!\n
%#ERROR_STRING"),LR=10,LC=15,PT=0]
GOTO(DONE)
//////////////////////////////////////////////////////////////////////////////
//Success!!
@EXIT_SUCCESS
#FILE_SIZE=JOS(nc_size)
pause[TX=STRTMP("Successfully coded:\n
%#FILE\n
%#FILE_SIZE bytes"),LR=10,LC=15,PT=0]
//////////////////////////////////////////////////////////////////////////////
//Done
@DONE
======================================================================
To find out more about this mailing list including how to unsubscribe,
send the message "info mfg-smartcam" to [EMAIL PROTECTED]
======================================================================