Hello, Large python scripts when embeded in a toolbox with a password take to long to extract and run. In order to get around that I want to make an embedded password protected module of the part of the code that I want to protect.

1172
3
08-06-2016 08:57 AM
DanielGreene
New Contributor III

Here is the sample that I have been testing.

Script1A is embedded in the toolbox but not password protected

SCRIPT1A

# import ArcGis Geoprocessing module

import arcpy

import os

relPath = os.path.dirname(__file__)

arcpy.AddMessage(relPath)

toolPath = relPath + r"\TestModulesEmbed.tbx"

arcpy.AddMessage(toolPath)

arcpy.AddMessage(". . . Starting Script1A")

# The tool is identified by the toolname and the toolbox alias

# Import the custom toolbox

arcpy.ImportToolbox(toolPath)

# Run the tool

arcpy.Script1B_TestModules

arcpy.TestModules.Script1B

Script1B is embedded (imported) into the toolbox and also password protected

SCRIPT1B

# import ArcGis Geoprocessing module

import arcpy

import os

arcpy.AddMessage(". . . Script1B has been called")

def printmessage():

  arcpy.AddMessage(". . . Starting Script1B")

This is the result when running the code:

Executing: Script1A

Start Time: Sat Aug 06 09:52:10 2016

Running script Script1A...

C:\Data\NewContract\MyWork

C:\Data\NewContract\MyWork\TestModulesEmbed.tbx

. . . Starting Script1A

Completed script Script1A...

Succeeded at Sat Aug 06 09:52:10 2016 (Elapsed Time: 0.08 seconds)

Ideas of how to make this work will be appreciated.  I would like to protect the portion of the

script that accesses Oracle.

Thanks,

Dan

0 Kudos
3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

I don't know if you have set this up as a package, but you can slow most down by just distributing the *.pyc files if you are doing imports of your base code.  The best protection is a license

DanielGreene
New Contributor III

Thanks for the input.  But basically all I want to know is how to call an embedded script from another embedded script.  The final product will be a python ADD-IN.  I can call a script that is not embedded without a problem but cannot duplicate that for embedded scripts.

Toolbox Script Not Embedded

# import ArcGis Geoprocessing module

import arcpy

import Script1B

arcpy.AddMessage(". . . Starting Script1A")

Script1B.printmessage()

Toolbox Script not Embedded in same location on C: drive

Script

# import ArcGis Geoprocessing module

import arcpy

def printmessage():

  arcpy.AddMessage(". . . Starting Script1B")

Output when running Script 1A

Executing: Script1A

Start Time: Tue Aug 09 08:45:47 2016

Running script Script1A...

. . . Starting Script1A

. . . Starting Script1B

Completed script Script1A...

Succeeded at Tue Aug 09 08:45:47 2016 (Elapsed Time: 0.04 seconds)

So, I first get everything working as it should from a toolbox and then embed all of the scripts.  Then when creating the python add-in I simply point the buttons at the toolbox scripts.  I just cannot get Script1A to call Script1B when both scripts are embedded (imported into the toolbox).

Dan

0 Kudos
DanielGreene
New Contributor III

As it turns out my scripts embedded in a toolbox were working.  It is just that the arcpy.AddMessage tool does not work in a called script.

SCRIPT1A IMPORTED IN A TOOLBOX

cr

SCRIPT1B IMPORTED INTO A TOOLBOX AND PASSWORD PROTECTED

The output does create the TestDB.gdb

Therefore, in order to get around the very slow time processing a large imported script in a toolbox the solution will be to put the portion I want to protect in it's own script so that the portion to decrypt when running the script will be small and fast.

Dan

Edit - I forgot the mention that the variable relPath passed from Script1A to Script1B needs to be defined for Script1B under properties, parameters:

Display Name     Data Type

relPath                File

Working with this more I ended up using the arcpy.RemoveToolbox(toolPath) command if it existed because if the old one had an error and you did not leave and restart ArcMap, it would still run the old one.  So, for multiple runs the called script is always refreshed.

0 Kudos