2

I have written a number of standalone Tools for ArcMap.

These tools are all .py files and are run outside of ArcMap. At the moment it has only been me running these tools, but I have been asked to share these with other users.

I am happy to share these, I am however not entirely happy in sharing the lessons and tricks of the trade I have incorporated into the flow of these tools.

Can I lock these files from viewing by people who shouldn’t see the text within the .py file, but still keep the script accessible to the windows task manager or a single run “double-click”?

As an aside, I would prefer to not embed these in a Toolbox, as I want to run these outside of ArcMap /ArcGIS Pro.

2
  • 1
    If you don't want to embed/password protect the TBX, nor create a PYT in Pro and Encrypt it, and your question is about "Securing" basic .py files, I'd say you'd want to use stackoverflow to research your question as its no longer about GIS and just about securing python files.
    – KHibma
    Jan 29, 2019 at 13:37
  • Thank you @KHibma I thought I would try here first. Perhaps I should look at keeping them in a Toolbox as it’s easier to protect. Jan 29, 2019 at 14:05

2 Answers 2

3

There is a way to protect your scripts and run them from another script outside the ArcMap environment.

You need to create a toolbox and wire up your scripts as tools as if you were going to run them from tool box. You then import the script into the toolbox and protect with a password, this is documented as Embedding scripts and password protecting tools.

So for example create a toolbox called protected.tbx, set its alias to something, I used testtbx. Create a script tool, import and protect with password. Make a record of the script NAME not the LABEL.

So in my test I have a script tool called scrCount which takes as input a FeatureClass and does a count on the rows.

Now create your outside Arcmap script, the trick here is to import your script from your password protected toolbox so you could call it.

import arcpy
def main():
    fc = r"C:\Scratch\fGDB_Scratch.gdb\BankSide_Buffer"
    toolboxpath = r"C:\Scratch\protected.tbx"
    arcpy.ImportToolbox(toolboxpath,"testtbx")
    arcpy.scrCount_testtbx(fc) # Name_toolbox alias

if __name__ == '__main__':
    main()

I can only assume if you are reporting messages then you will need to use the print statement.

0
1

You can try to convert them to executables with PyInstaller (http://www.pyinstaller.org/). But then you are not able to run them from ArcMap anymore.

There may be some issues regarding ArcPy and PyInstaller. I think you will find some workarounds here: https://github.com/pyinstaller/pyinstaller/issues/576

1
  • Thank you. I will look into this. I tried PyInstaller once, it didn’t work as I intended. But I’ll definitely give it a go. Jan 29, 2019 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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