def my_change_prolog(self, **words):
    try:                     
        # this is relevant only when using iocontrol-v2.
        if self.params[5600] > 0.0:
            if self.params[5601] < 0.0:
                self.set_errormsg("Toolchanger hard fault %d" % (int(self.params[5601])))
                return INTERP_ERROR
            print "change_prolog: Toolchanger soft fault %d" % int(self.params[5601])
                             
#******************          
        tool_max_x = 0       
        tool_max_z = 0       
        current_orientation = -1
        for i in range(len(self.tool_table)):
            if self.tool_table[i].offset.v > tool_max_x:
                tool_max_x = self.tool_table[i].offset.v
            if self.tool_table[i].offset.w > tool_max_z:
                tool_max_z = self.tool_table[i].offset.w
            if self.tool_table[i].toolno == self.current_tool:
                current_orientation = self.tool_table[i].orientation
#******************          

        if self.selected_pocket < 0:
            self.set_errormsg("M6: no tool prepared")
            return INTERP_ERROR

        if self.cutter_comp_side:
            self.set_errormsg("Cannot change tools with cutter radius compensation on")
            return INTERP_ERROR
        self.params["tool_in_spindle"] = self.current_tool
        self.params["selected_tool"] = self.selected_tool
        self.params["current_pocket"] = self.current_pocket # this is probably nonsense
        self.params["selected_pocket"] = self.selected_pocket

#********************
        self.params["tool_orientation"] = current_orientation
        self.params["tool_max_x"] = tool_max_x
        self.params["tool_max_z"] = tool_max_z
#********************
        return INTERP_OK

    except Exception, e:
        self.set_errormsg("M6/change_prolog: %s" % (e))
        return INTERP_ERROR
