0

I have a python script which runs fine. I am creating toolbar and button. When I copy my script into the addin python file. it does not run.

import arcpy
import pythonaddins

class ButtonClass1(object):
    """Implementation for RMS_Export_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        Geodatabases = arcpy.GetParameterAsText(0)
        if Geodatabases == '#' or not Geodatabases:
             Geodatabases = "E:\\RMS_Export\\Models\\Geodatabases" # provide a default value if unspecified

        # Local variables:
        Parcels_gdb = Geodatabases
        Informal_Units_gdb = Geodatabases
        LFL_gdb = Geodatabases
        Valuations_gdb = Geodatabases
        Formal_Units_gdb = Geodatabases
        Proposed_gdb = Geodatabases
        Export_gdb = Geodatabases

        # Process: Create File GDB
        arcpy.CreateFileGDB_management(Geodatabases, "Parcels", "CURRENT")

        # Process: Create File GDB (3)
        arcpy.CreateFileGDB_management(Geodatabases, "Informal_Units", "CURRENT")

        # Process: Create File GDB (4)
        arcpy.CreateFileGDB_management(Geodatabases, "LFL", "CURRENT")

        # Process: Create File GDB (5)
        arcpy.CreateFileGDB_management(Geodatabases, "Valuations", "CURRENT")

        # Process: Create File GDB (6)
        arcpy.CreateFileGDB_management(Geodatabases, "Formal_Units", "CURRENT")

        # Process: Create File GDB (7)
        arcpy.CreateFileGDB_management(Geodatabases, "Proposed", "CURRENT")

        # Process: Create File GDB (2)
        arcpy.CreateFileGDB_management(Geodatabases, "Export", "CURRENT")  
5
  • arcpy.GetParameterAsText(0) are for script tools not python addins. Commented Dec 9, 2021 at 10:41
  • I exported my model from Modelbuilder into a python script. Any help to adjust the script to work in my add in would be great. I have no python coding experience Commented Dec 9, 2021 at 12:24
  • 1
    May be leave it as model and not try to import functionality (the obtaining of the parameter) that is inherently a script style interaction into a python addin which is more to do with interacting with a map interface. You are trying to force a large square peg into a small round hole... Commented Dec 9, 2021 at 14:58
  • 2
    Agree with @Hornbydd suggested approach. I'll add that while a Python Addin is not the most complicated thing in the world, it is more complex than just a regular script or script tool. As you said you have no coding experience, you're jumping into the "hardest" Python implementation inside ArcMap and starting from a Model export is pushing you into a "tool" design, not a "button" (small, but important design differences in the final product) Commented Dec 9, 2021 at 15:33
  • 2
    Also a good idea to avoid Python Add-Ins if you ever intend to upgrade from ArcMap to ArcGIS Pro. ESRI have made it clear that Python Add-Ins will not be supported for ArcGIS Pro. Commented Dec 10, 2021 at 0:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.