Running a Macro in a Macro
Moderators: Dorian (MJT support), JRL
Running a Macro in a Macro
I'm sure i've seen topics on this before, but despite numerous searches I cant find anything.. (the search function is a little lacking I've found on previous experience but I have no idea why.)
In any case, I have a series of macros that use the same first 80 lines or so.. and when I tweak those scripts, I dont want to have to manually edit & re-check in 8 different macros. Is there a way I can standardise a particular chunk, maybe read it from a text file dynamically in the macro??
In any case, I have a series of macros that use the same first 80 lines or so.. and when I tweak those scripts, I dont want to have to manually edit & re-check in 8 different macros. Is there a way I can standardise a particular chunk, maybe read it from a text file dynamically in the macro??
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Yes, use the Include> command, or the Macro> command.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I have to read some variables/values from a file that I create (in a different external program).
I am looping thru and each time the values can be different.
Can I use either the include or macro command, and get the variables/values read into my current macro so I can use them, and have it overwrite the old values as I loop thru?
For example, my old scripting tool had a file that you could create that contained
Var1=xyz
Var2=Apple
and by loading it, all the values for the variables would be loaded.
BTW, I am just starting with Macro Scheduler, but in testing the Image Recognition it's much better than the very expensive product I am using now.
I am converting my first macro over tonight.
Thanks,
Alan
I am looping thru and each time the values can be different.
Can I use either the include or macro command, and get the variables/values read into my current macro so I can use them, and have it overwrite the old values as I loop thru?
For example, my old scripting tool had a file that you could create that contained
Var1=xyz
Var2=Apple
and by loading it, all the values for the variables would be loaded.
BTW, I am just starting with Macro Scheduler, but in testing the Image Recognition it's much better than the very expensive product I am using now.
I am converting my first macro over tonight.
Thanks,
Alan
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Yes, with Include>. No with Macro>Can I use either the include or macro command, and get the variables/values read into my current macro so I can use them, and have it overwrite the old values as I loop thru?
Include pulls the code into the calling macro such that the code becomes a part of the overall macro. Therefore it has access to all variables and can modify them. The included .scp actually becomes part of the overall macro. You will see this in effect if you step past an Include line with the debugger - you'll see the code appear in the editor, and you'll note you have access to all subsequent variables.
Macro> just runs another macro. The calling macro does not have access to the called macros functions or variables. It can pass variables on the command line and can get results back via the MACRO_RESULT variable. But otherwise it is much like running another app with Run>.
If you want access to all the variables, functions etc then use Include>
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I just want to make sure I understand.
If I do the include, can it be done say once for each loop that I'm working on?
Simple example.
I have a file called File1.scp which has Var1=Apple
I have another file called File2.scp which has Var1=Orange
My macro will be looping thru and the first time will include File1.scp so Var1 will be equal to Apple? During the same processing, I will be looping and including File2.scp so now my Var1 variable with have Orange?
That would work for me, but I'm not sure that's how it really works.
I also will be compiling my main script, so I need to confirm that that would also work.
Basically the files I'm including really are values for different variables depending on what I'm processing in this loop.
Alan
If I do the include, can it be done say once for each loop that I'm working on?
Simple example.
I have a file called File1.scp which has Var1=Apple
I have another file called File2.scp which has Var1=Orange
My macro will be looping thru and the first time will include File1.scp so Var1 will be equal to Apple? During the same processing, I will be looping and including File2.scp so now my Var1 variable with have Orange?
That would work for me, but I'm not sure that's how it really works.
I also will be compiling my main script, so I need to confirm that that would also work.
Basically the files I'm including really are values for different variables depending on what I'm processing in this loop.
Alan
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Yes, it would work like that. If the included script contains a variable which has already been set by the calling script (or previously included script - same thing) then that variable will change.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Seriously, to visualise what Include does, try it in the debugger. It will become very clear.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
To visualise:
Imagine you had these two scripts:
File1.scp
Let>Var1=Apple
File2.scp
Let>Var1=Orange
And you had this script:
Include>File1.scp
Include>File2.scp
This is the same as saying:
Let>Var1=Apple
Let>Var1=Orange
Just PASTE the code in the Included file in place of the Include statement. That's all it is doing.
Imagine you had these two scripts:
File1.scp
Let>Var1=Apple
File2.scp
Let>Var1=Orange
And you had this script:
Include>File1.scp
Include>File2.scp
This is the same as saying:
Let>Var1=Apple
Let>Var1=Orange
Just PASTE the code in the Included file in place of the Include statement. That's all it is doing.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
It doesn't look like the include statement can use a variable name.
Piece of my code, not complete
The first include works, but it's hardcoded, the second include says it can't find the file, either with or without the %
I will probably just copy the file to a standard name, and then use it, but it would be nice if the include could have a variable name.
Thanks,
Alan
Piece of my code, not complete
Code: Select all
IfFileExists>filenamea
include>c:\ad1a.txt
include>%filenamea%
I will probably just copy the file to a standard name, and then use it, but it would be nice if the include could have a variable name.
Thanks,
Alan
In addition, once the first include statement has occurred, it looks like it destroys the actual include statement so it doesn't replace the old variables with the new ones.
Can anybody tell me how I might be able to get around this?
This is very important so hopefully I can come up with a solution, but I'm a little stumped at this point.
So basically this is my code.
Each filenamea file has the variables in it, for example
the first file might have
Let>Name=John
so after the include the variable Name will have John
What I want to do is that when I loop and next the next file
which may have
Let>Name=Joe
I want the variable Name to contain Joe.
It's really pretty powerful if I can get it to work.
Alan
Can anybody tell me how I might be able to get around this?
This is very important so hopefully I can come up with a solution, but I'm a little stumped at this point.
So basically this is my code.
Code: Select all
IfFileExists>filenamea
Let>CF_OVERWRITE=1
CopyFile>filenamea,c:\vars.txt
include>c:\vars.txt
End if
the first file might have
Let>Name=John
so after the include the variable Name will have John
What I want to do is that when I loop and next the next file
which may have
Let>Name=Joe
I want the variable Name to contain Joe.
It's really pretty powerful if I can get it to work.
Alan