Hi all

Meanwhile I did a number of jobs using sub programs. Most of the time I 
generate my gcode through rhinocam. I have modified the postprocessor, so that 
it puts out the code the way I want to have it. But after many times editing 
the code manually to be used in a sub program way, I wanted a better way.

here is a bash script that does the following:

reads a gcode file
adds "O <file> sub label" at the top of file.ngc
removes any M30 code lines
attaches "O <file> endsub" and "M2" lines at the end of file.ngc

generates a master file
if rerun edits the master file by adding just the next subfile

I thought someone else might like that too, as I felt it was handy and avoids 
my huge amount of typos :-) Maybe it finds it's way to the wiki?

feedback welcome,

greets chris

#! /bin/bash

##################################################################
#
# Parameters:
# 1 masterfile
# 2 subfile
#
##################################################################

ext=.ngc
nextsub="(###nextsub############################################)"

##################################################################
editsub() {
    # if there is other code to be checked, removed or altered,
    # code should go here
    echo "O <$2> sub" > $2$ext
    cat $1 | sed "/M30/d" >> $2$ext
    echo "O <$2> endsub" >> $2$ext
    echo "M2"  >> $2$ext
}

##################################################################

mkmasterskeleton () {

    echo $1$ext
    echo "(******************************************************)" \
         > $1$ext
    echo "( Run all seperate tasks in one master file            )" \
         >> $1$ext
    echo "(******************************************************)" \
         >> $1$ext
    echo "" >> $1$ext
    echo "$nextsub" >> $1$ext
    echo "" >> $1$ext
    echo "(******************************************************)" \
         >> $1$ext
    echo "( Back home                                            )" \
         >> $1$ext
    echo "(******************************************************)" \
         >> $1$ext
    echo "( your homing or eoj code goes here )" >> $1$ext

}

##################################################################

editmaster () {

    cat $1$ext | sed "s/$nextsub/O <$sub> label $sub\\n$nextsub/g" > 123456789
    rm $1$ext
    mv 123456789 $1$ext

}


# main ###########################################################

sub=$(echo "sub_"$2 | sed "s/.ngc//g" )
master=$(echo $1 | sed "s/.ngc//g" )

if  [ -f $sub$ext ]
then
    echo "file $sub$ext already exists. "
    exit 1
else
    editsub $2 $sub
fi

if  [ -f $master$ext ]
then
    if [ $(cat $master$ext | grep $sub) ]
    then
        echo "$sub already in $master:"
        cat $master$ext | grep $sub
        exit 1
    else
        editmaster $master $sub
    fi
else
    mkmasterskeleton $master
    editmaster $master $sub
fi

exit 0

##################################################################
 

__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen 
Massenmails. 
http://mail.yahoo.com 

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to