Perhaps you should post your code. You can define a function to do anything you like, and call it at any point in your code.