2

I am trying to create a python addin for ArcMap. The toolbar that I am creating has four buttons which will run one python script per button. These scripts are all running data management processes which are mostly centred around transfering data from one or more personal geodatabases to an oracle database. I have each of the individual python scripts which work but need some updating to make them more user friendly. The issue I am having at the moment is that I want to keep the four scrupts seperate so I need to import/call them from a master script which the addin will be based off. At the moment each script is made up of a single class but in the future they may end up having more than one class.

The issue I am having at the moment is that the script below seems to not import/run the individual scripts when I try and use the toolbar in ArcMap. The four buttons are there but nothing happens when I click on them. I have an __init__.py script in the package directory where the four python scripts are stored. At the moment I am just trying to run the individual class from each script but I may need to run several classes/the whole script in the future.

import os
import sys
sys.path.append(os.path.dirname(__file__))
import arcpy
import pythonaddins
import getopt
import fnmatch
import traceback
import pyodbc
import csv
from datetime import datetime
import logging
from package import *

#print dir()

class AppendModelsOracle(object):
    """Implementation for Append_Models_Oracle.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        # Run the Append_Models_Oracle.py script stored in the package directory
        package.Append_Models_Oracle.AppendReachNetwork()

class SAGIStoOracle(object):
    """Implementation for SAGIS_to_Oracle.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        # Run the SAGIS_to_Oracle.py script stored in the package directory
        package.SAGIS_to_Oracle.SAGIS()

class ImportGIS1CSV(object):
    """Implementation for Import_GIS1_CSV.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        # Run the Import_GIS1_csv.py script stored in the package directory
        package.Import_GIS1_csv.ImportGIS1()

class ImportDeterminandCSV(object):
    """Implementation for Import_determinand_csv.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        # Run the Import_Determinands_csv.py script stored in the package directory
        package.Import_Determinands_csv.ImportDets()enter code here

I would be greatful for any help as to why individual scripts are not being imported/run when I try to use the python addin in ArcMap.

Thanks in advance,

Ben.

1 Answers1

0

As specified in this answer, you should have used the all variable to set the classes that will be imported when you use "*", as described in the python docs:

Now what happens when the user writes from sound.effects import *? Ideally, one would hope that this somehow goes out to the filesystem, finds which submodules are present in the package, and imports them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.

The only solution is for the package author to provide an explicit index of the package. The import statement uses the following convention: if a package’s init.py code defines a list named all, it is taken to be the list of module names that should be imported when from package import * is encountered. It is up to the package author to keep this list up-to-date when a new version of the package is released. Package authors may also decide not to support it, if they don’t see a use for importing * from their package. For example, the file sound/effects/init.py could contain the following code:

__all__ = ["echo", "surround", "reverse"]

This would mean that from sound.effects import * would import the three named submodules of the sound package.

If all is not defined, the statement from sound.effects import * does not import all submodules from the package sound.effects into the current namespace;

Pretty sure you already figure it out, answering for future questions.

Yoav Abadi
  • 403
  • 7
  • 16