Repeating set of actions within a macro

Hello.
I am wondering if anyone can help out here.

I have a macro that first asks the user to input a variable between 1-16.
This is followed by an if/then action.
If the user inputs '1' then it runs through a bunch of steps and then quits the script.
If it's a higher number, it keeps going down the list until it reaches that number and then runs from there.
For each of the 16 sections, there are slightly different behaviors which I have scripted but they all share several steps in common.
As it stands, I am repeating those common steps over and over and the script is getting lengthy and slow to edit.
Is there a way to have the common/repeated actions contained in a single action that is called within each loop?
ie.
run sub-macro 'common' then continue

I have attached the script.
I do realize that I am going about all of this the long way and there's probably a much more elegant/robust way to write this but I'm just getting the hang of this stuff.

Thanks in advance.
populate layout edit e.kmmacros (770.9 KB)

Hi @macsearcher,

Yes. You can create a new, separate macro that contains the common actions you want to repeat, then use the Execute a Macro action to run those actions at the relevant point(s) in the macro.

Thanks gglick!
Perfect.

1 Like

@gglick has provided one solution to reuse of common Actions, but I think you could also benefit from using Switch or Case action instead of a bunch of IF/THEN Actions.

Another approach, instead of using Execute Macro, is to place the common Actions before or after the Switch Action, as appropriate.

Questions?


Moderators Note:
This post was moved from Help with macro for repeating action variables , and should have appeared at the top of this topic. But it did not for some reason.

So logically this post should appear at the top of this topic.

@macsearcher, in the future please do not double-post your questions. Starting a new topic, which you did, is all you need to do.


Hi Peter.
I've had some time to work with this and I've got it working pretty well.
I'm using a lot of your suggestions but still using a lot of my bulky script and I'd like to refine it a lot further but I'm learning a lot in the process.
There is another issue that I'm trying to get my head around.
Essentially, I am hoping to create a sub-macro within my macro that I can call as many times as I like. There are 10 or so actions that are common to every sub section of the script and every time that I want to change one variable, I have to copy and paste those 10 actions to each sub-section.
Can I simply put them in a container and say
run sub-macro A and continue?
I've attached the new script as it stands if you are curious.
I have described it in detail in a new post on the forum.
Thanks again for all of your help.populate layout edit e.kmmacros (770.9 KB)