import arcpy #Variables Parcels = arcpy.GetParameterAsText(0) arcpy.AddMessage(Parcels) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, "Parcels", df)[0] arcpy.AddMessage(lyr.name) #Logic try: whereClause = "RENUM = "+Parcels+"" arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause) df.extent = lyr.getSelectedExtent() df.scale = df.scale*1.1 except: print arcpy.GetMessages()
Solved! Go to Solution.
James,
After much frustration, I was finally able to convert some of my tools to buttons. Back, to the initial part of my search. Can you provide an example string that would ask the user to provide their name? I would like to have the value entered directly into a field in the attribute table. Or at least point in the correct direction with which function to use.
Thanks again.
inputName = arcpy.GetParameter(0)
import pythonaddins class ButtonClass_Button_1(object): """Implementation for MyAddin_addin.button_1 (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): pythonaddins.GPToolDialog('C:\MyToolboxFoler\MyCustomToolbox.tbx', 'MyScriptTool')
James,
Logically, this seems like a long way around. Why create a button to call a toolbox? Why not just use the script in the toolbox? I will give it a shot and see if it works though. I am not try to come off as ungrateful or rude. I am new to python and scripting and I am just trying to gain some more knowledge and understanding.
Thanks.
import arcpy import pythonaddins class UpdatesDates_Name(object): """Implementation for UpdatesDates_Name.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): pythonaddins.GPToolDialog('E:\User\Python\BCPAO.tbx', 'NameDate.py')
import arcpy import pythonaddins class UpdatesDates_Name(object): """Implementation for UpdatesDates_Name.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): msg = "The click event worked!" pythonaddins.MessageBox(msg, 'Just a test', 0)
I double checked the toolbox path and it is fine. I included the latest suggestion, to add the message. Nothing. I have the toolbar name, but no picture or button name.