I have been creating a toolbox that contains 4 parameters. Two of my parameters involve editing the labels of a shapefile. I want to have these two parameters as optional: if the user does not want to have the labels edited, then don't edit them!

I should mention that I'm not up to that point yet though. The two parameters are the label text size and a boolean to see if the user wants the text to be bold. I have set the parameters to be optional in my getParameterInfo method:

def getParameterInfo(self):
    """Define parameter definitions"""

    # First parameter = layer with customized features
    param0 = arcpy.Parameter(
        displayName = "Source layer with customized features",
        name = "source",
        datatype = "Feature Layer",
        parameterType = "Required",
        direction = "Input")

    # Second parameter = layers to which customized features will be applied
    param1 = arcpy.Parameter(
        displayName = "Layers with features to be updated",
        name = "updlayers",
        datatype = "GPValueTable",
        parameterType = "Required",
        direction = "Input")

    param2 = arcpy.Parameter(
        displayName = "Label Font Size",
        name = "labelFontSize",
        datatype = "GPDouble",
        parameterType = "Optional",
        direction = "Input")

    param3 = arcpy.Parameter(
        displayName = "Bold Font:",
        name = "labelBoldFont",
        datatype = "GPBoolean",
        parameterType = "Optional",            
        direction = "Input")            

    param1.columns = [['Feature Layer', 'Features']]        

    params = [param0, param1, param2, param3]

    return params

However, although they are set as optional (param2 and param3), the tool still requires an input in both cases. Here is a screenshot of what I see when I open my toolbox. Notice the green bubble next to the last two parameters, which indicates that they are required:

enter image description here

Is there a way for the last two parameters to be truly optional? As in, the user does not have to do anything with them if they don't want to? I'd imagine that this is something I can do in the getParameterInfo() method, but I am unsure of how to do this. Would I be able to set default values for these parameters in some way?

One extra thing to mention is that if I click on the check box for bold font to enable it, and then click it again to disable it, the tool will run. This is a temporary workaround. However, it is not ideal. I would hope to have the user not have to interact with these options if they don't want to.

  • Have you tried setting default values after creating the parameters? E.g. param3.value = False? (Not that you should have to, but this could be a workaround.) – nmpeterson Oct 8 '14 at 18:48

I believe you're overthinking this. I was able to create a Tool in a PYT using your parameter code and it ran just fine when I didn't set those values and hit the 'Ok' button to run it.

| improve this answer | |
  • You're right, it suddenly started working for me as well. How do I get ArcMap to recognize any edits I do to my Toolbox? My typical process consists of the following: 1. Add toolbox to ArcMap 2. Test to see if it works. If it doesn't, right-click on toolbox -> Edit -> Apply edits to code within editor once it opens. 3. Once edits are finished, close editor (Notepad++ in my case), and right-click on toolbox -> Refresh to make sure edits are applied. I have run into multiple occasions where ArcMap doesn't recognize changes to my code. Is this the right work flow? – coolDude Oct 8 '14 at 19:30
  • In order to notice that my code was indeed working, I have to close ArcMap, reopen the toolbox, and then my parameters came up as being optional. – coolDude Oct 8 '14 at 19:31
  • 1
    You don't need to close your editor, but that's about right. Edit PYT, save, right click->refresh in catalog window, double click to open tool dialog. – Jason Scheirer Oct 8 '14 at 19:31
  • Okay, so I've been adding my toolbox directly into the ArcToolbox window, not through Catalog, maybe that's the difference. I will play around with this, thanks for the input! – coolDude Oct 8 '14 at 19:48

You have to set the parameter as "Optional" in the script tool properties-->parameters tab within ArcMap or ArcCatalog. Right click the script tool within the toolbox and select "Properties". Navigate to the "Parameters" tab. Once there highlight the parameter you want to set as optional and then select "Optional" from the "Type" dropdown menu.

enter image description here

| improve this answer | |
  • I unfortunately don't have that option though. This is a toolbox and not a script tool: resources.arcgis.com/en/help/main/10.1/index.html#/… Hence, I define my parameters all within the toolbox code and not with a wizard. – coolDude Oct 8 '14 at 18:37
  • 1
    A Python toolbox? If so you should edit your question and add the python-toolbox tag. Now that I'm reading the code I can tell it is but just for clarity. – landocalrissian Oct 8 '14 at 18:40

Your Answer

