This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
Now that it's live, don't forget to accept your certification badge on Credly today! Learn more here.
We are currently experiencing an issue with Email verification at this time and working towards a solution. Should you encounter this issue, please click on the "Send Verification Button" a second time and the request should go through. If the issue still persists for you, please email email@example.com for assistance.
This article is part of the CS Macro Development Series. The goal of this series is to communicate tips, tricks, and the thought process that goes into developing good, dynamic macros.
Many macros need to be especially dynamic to allowthe user to select which field to use in a very complex process. Take the Make Grid tool for example. It asks the user to specifya spatial object field, and only carries that field through its calculations. What comes out of the tool are two new fields, GridName and Grid, and none of the original fields at all.
I set out to build a macro just like this tool, except to generate a hexagonal grid. I started by building a normal workflow that could do this process, andwhen I was ready to convert it to a macro, I realized that I wasn't sure of the best way to enable it to choose this field dynamically.
There are two main ways to get data into your macro. Here's a quick summary of how they work:
The Macro Input tool has a checkbox in its configuration that reads Show Field Map.
If this is unchecked, then your macro won't do anything with the data - it will just stream in everything as is and trust that the stuff inside knows how to account for anything you throw at it.
If it is checked, then your macro will create drop down menus in its configuration window that will ask for the fields you have present in theTemplate Input. These drop down menus will let you select which fields to stream in to the macro in place of the ones in its template.
The field map needs all those drop downs to be filled out for it to do its thing, but ifyou want to make one of these inputs optional, just add(Optional)to the field name in your macro template.
1. Easy to set up! One checkbox and your template are all that's needed.
2. Makes sure only mapped fields enter the macro. This is good when converting a workflow to a macro because you don't need to worry about every form the input data stream could be in. If your stream has other fields, they will get tacked on to thestuff coming out of the macro.
Drop Down menus are an alternativeway you can bring fields into your macro that offers a bit more control of the process.
They're particularly usefulwhen connected to theanchor of a Macro Input tool.
You can then update a Selecttool with the selected field to choose which field is being passed along.
1. Allows you to specify which fields to show to the user from a list of field types. (In this example,I am only allowing spatial objects.)
2. You can have a default selection populate the interface. (Here we will have any field starting with "SpatialObj" get selected automatically in the configuration of the macro.)
3. If you want something to be optional, you can use the [None] option.
"The Select Tool Trick"
If you make use of the Drop Down tool to bring in your data you'll need to update a Select tool. Here's a little trick that will make converting your workflows a lot easier.
First you'll want to uncheck*Unknownin the Select tool, since this will bring in every field not explicitly unchecked here. Then, have only the field you're selecting for checked, and navigate over to your Action tool andpoint it at the selected field.
Instead of having this repeated for every tool using this field, just have the field renamed in the Select tool, and refer to it by that name in all your downstream fields.
This turned out to be just what I needed for the Make Hex Grid macro, where I have a ton of stuff happening downstream and I only wanted one field to get through my Select tool.
Check out the example for a simplified version of this.