I'm developing a Python Addin for ArcMap. This will consist of a button that will run another python script:

import arcpy
from arcpy import env
import pythonaddins
import os

class ButtonClass1(object):
    """Implementation for Schaltflaeche_UID_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        os.system(r'C:\Users\admin\Desktop\ToeB 10.2\Addins\Schaltflaeche_UID\Install\Insert_UID.py')

I've tried F_Kelner's answer posted in ArcGIS python add in to call Python script for importing mdb data, but I'm getting the following error, even though I have imported the os module:

Traceback (most recent call last): File "C:\Users\admin\AppData\Local\ESRI\Desktop10.2\AssemblyCache{D9E1A7BE-8FE5-4EE5-9C9E-93C2B867EA3E}\Schaltflaeche_UID_addin.py", line 17, in onClick workspace = os.path.dirname(workspace) NameError: global name 'os' is not defined

Anyone have any ideas?

closed as off-topic by PolyGeo Mar 21 '16 at 6:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to GIS SE! As a new user please take the Tour to learn about the site. For ArcPy questions please always include a code snippet that illustrates what you have tried and where you are stuck. Also, error messages should always ne posted as text in preferemce to pictures so that they can be searched. Your error here is that you appear to have missed including import os in your script. – PolyGeo Mar 7 '16 at 8:31
  • edited. as you can see, i'm importing os in the addin script. – user151631 Mar 7 '16 at 8:41
  • You won´t need the import arcpy directive, as you already import env from arcpy on next line. Having two imports means first import the whole arcpy-namespace and afterwards load the env from arcpy (which has already been loaded by the previous directive). – HimBromBeere Mar 7 '16 at 8:41
  • Thanks, HimBromBeere, you are correct, but that isn't the problem... – user151631 Mar 7 '16 at 8:50
  • Has your Python AddIn been re-made and re-installed since a possible addition of an import os line? – PolyGeo Mar 7 '16 at 10:08

Browse other questions tagged or ask your own question.