나는 arcpy 만 사용하여 선택한 항목을 가져 오는 한 가지 방법을 알고 있습니다.
#get an map object
mxd = arcpy.mapping.MapDocument("CURRENT")
#get an dataframe object, here the first one is taken
df = arcpy.mapping.ListDataFrames(mxd)[0]
#get a layer object
lyr = arcpy.mapping.ListLayers(mxd,"NameOfRequiredLayer",df)
#now get the FIDs of the selected Elements of your layer
selection = arcpy.Describe(lyr).FIDSet
"선택"에는 선택한 요소의 FID가 포함됩니다. 그것으로 당신은 당신이해야만하는 것을 가지고 다닐 수 있습니다. 예를 들어 레이어 정의 쿼리를 설정할 수 있습니다.
#shapes use FID, feature classes use OBJECTID, so you better check
IDname = "\"OBJECTID\""
if lyr.dataSource.endswith("shp"):
IDname = "\"FID\""
querystring = IDname + " = " + str(selection[0])
for count in range(1,len(selection)):
querystring = querystring + " OR " + IDname + " = " + str(selection[count])
if lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = querystring