1

I have been put on a project where I need to modify and optimize an existing PythonToolbox and associated Toolbar (each button calls a script). I want to add a new script tool in there but the Add Script Wizard isn't available on my Basic License (should it? when I right click on the toolbox and go to Add, the Script option is disabled).

enter image description here

What I've done is add a new class in the .pyt file and updated the self.tools of the Toolbox initialisation.

I've also, and I'm pretty this isn't the right thing to do, created a .xml file for the new tool with Notepad++. Basicaly I copied the file from another tool in the toolbox and modified the file name as well as the tool name under <resTitle> and <tool name="" displayname "">.

And of course what I get is a tool that is recognized but invalid. enter image description here

What would be the correct procedure to add a script tool outside of the Add Script Wizard? How should I handle the new .xml file so it links with the .pyt file?

2

The Add Script Wizard is used to add a tool to a standard toolbox (.tbx). To add a tool to a Python Toolbox (.pyt) you need to write a Python class. Fortunately, the template for one tool class is written when you create a New Toolbox.

To add more tools I copy/paste the first class and rename it. Then I add that tool name to the list of tools in the Toolbox class. The last step is to edit the tool class so that it does what you want.

If you break your Python Toolbox right-click on it in the Catalog window of ArcMap and you can get help about what is wrong with it.

Although you can edit the XML to modify tool help, there should normally be no need to touch it. You should be able to delete a broken XML file and let ArcGIS for Desktop recreate it for you.

  • Okay, I deleted the XML I created and let ArcGIS handle it, which it did wonderfuly. Thanks! But Toolbox and Toolbar are still broken and the Check synthax doesn't reveal anything. I'm still looking through the code for a mistake I have I made. – MPel May 17 '16 at 20:03
  • Does Check Syntax say anything? If so, precisely what? – PolyGeo May 17 '16 at 20:06
  • No Syntax Errors – MPel May 17 '16 at 20:36
  • 1
    The expedient may be to create a new Python Toolbox and copy/paste/test from your existing toolbox until it breaks. Then investigate the last addition. – PolyGeo May 17 '16 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.