My little Python script is intended to run in a Python-Addin tool where the user clicks on a parcel, grabs the PIN attribute and then opens an MS Access form with the PIN as a parameter to a query. I'm very close to getting this working but can't seem to get Access to open the form with the parameter.
Thanks again to Mike Hunter for the assist with the parcel feature selection.
Thanks again to Mike Hunter for the assist with the parcel feature selection.
Code:
import arcpy
from arcpy import env
import pythonaddins
import win32com.client, types, pythoncom, sys, os, string
import subprocess
class ToolClass2(object):
"""Implementation for ArcGISAddins_addin.tool (Tool)"""
def onMouseDownMap(self, x, y, button, shift):
# set up environment
arcpy.env.workspace = "C:/temp/python/test.gdb"
Parcels = "C:/temp/python/test.gdb/Parcels"
mxd = arcpy.mapping.MapDocument("current")
df = mxd.activeDataFrame
# build point geometry, run your getSearchDistanceInches function
pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference)
#searchdistance = getSearchDistanceInches(df.scale, 3)
# make an arcpy.mapping layer obj and do the selection by location
plyr = arcpy.mapping.Layer(Parcels)
arcpy.SelectLayerByLocation_management(plyr, "INTERSECT", pointGeom, "0 meters","NEW_SELECTION")
arcpy.CopyFeatures_management(plyr, "climate")
fc = "C:/temp/python/test.gdb/selected_parcel"
# Create a search cursor
#
rows = arcpy.SearchCursor(fc)
# Create a list of string fields
fields = arcpy.ListFields(fc, "", "String")
for row in rows:
for field in fields:
if field.name == "PIN":
pin = row.getValue(field.name)
out = "%s: Value = %s" % (field.name, pin)
pythonaddins.MessageBox(out, "My Coordinates")
# all done, now add our layer to the map
#arcpy.mapping.AddLayer(df, plyr, "BOTTOM")
#arcpy.RefreshActiveView()
strDbName = "BloomingtonQuad.mdb"
#print strDbName
PIN = "2123301001"
path = "N:/Work/20130419_COBTA_Application/Query_BlmTransfer"
accapp = win32com.client.Dispatch("Access.Application")
accapp.Visible = True
accapp.opencurrentdatabase(path + '/' + strDbName, False)
accapp.OpenForm(frmQuad)
accapp.Forms("frmQuad").controls("TxtID").Value = PIN
#accapp.Application.CloseCurrentDatabase()
#accapp.Application.Quit()