Hi,
I am trying to set up definition query in Pro. Purpose of the script is that it loops through table and creates new map based on the row value. However, I can't get my definition query to work. If I specify a specific pin number such as "DGCO.GIS_OWNER.ParcelQueue.JOINPIN = 56" the script will work fine, but I am needing to run through multiple row values, so the script will crash after "row number 56". Any ideas on how to get definition query to work through loop?
#Set definition query on Parcels using PIN
for lyr in m.listLayers("Parcel*"):
if lyr.supports("DefinitionQuery"):
lyr.definitionQuery = "DGCO.GIS_OWNER.ParcelQueue.JOINPIN = " + PIN
Below is PIN defined, which works and pulls the correct row value. However, my definition query above won't recognize it.
PIN = i.getValue(SearchField)
Solved! Go to Solution.
Issue solved... had to include "'" between PIN. Example below
#Set definition query on Parcels using PIN
for lyr in m.listLayers("Parcel"):
if lyr.supports("DefinitionQuery"):
lyr.definitionQuery = "DGCO.GIS_OWNER.ParcelQueue.JOINPIN = " + "'" + PIN + "'"
I highly recommend levering string literals in Python with f""
PEP 498 – Literal String Interpolation | peps.python.org
lyr.definitionQuery = f"DGCO.GIS_OWNER.ParcelQueue.JOINPIN = '{PIN}'"
Issue solved... had to include "'" between PIN. Example below
#Set definition query on Parcels using PIN
for lyr in m.listLayers("Parcel"):
if lyr.supports("DefinitionQuery"):
lyr.definitionQuery = "DGCO.GIS_OWNER.ParcelQueue.JOINPIN = " + "'" + PIN + "'"
I highly recommend levering string literals in Python with f""
PEP 498 – Literal String Interpolation | peps.python.org
lyr.definitionQuery = f"DGCO.GIS_OWNER.ParcelQueue.JOINPIN = '{PIN}'"
Agreed. However, by looking at the database name in the path, I assumed this was most likely pre python 3 and the .format works for both.
R_
@RhettZufelt wrote:Agreed. However, by looking at the database name in the path, I assumed this was most likely pre python 3 and the .format works for both.
R_
True! This only works in Python 3. Since @ScoutStanley mentioned Pro, I assumed Python 3.
Looks like maybe I should have read that better, skimmed past the pro.
Do love the f strings, makes query expressions much easier.
R_
Oh nice, I hadn't learned about f, added it to the script! Thanks for the tip!
Assuming PIN is numeric, maybe this will work?
lyr.definitionQuery = "DGCO.GIS_OWNER.ParcelQueue.JOINPIN = {0}".format(PIN)
R_