Multivalue parameter and multi features

226
3
10-05-2021 04:11 PM
CCWeedcontrol
Regular Contributor

I have a script that I am trying to add/ include multiple parameters for multiple features. Parcels  can have multiple case numbers associated with them. For example Parcel Pin12345 can have permit MC2021-0001 and CD20201-0001. I want to be able to create two separate parcels\features with the same Pin12345 but different permit numbers but only if I input multiple Parameters. If I just enter one parameter in then I just need one pin with the case I enter. Sometimes case number can have 2 or 10 parcels for that particular case. I am not sure what is the best way to do this but this is what I have and it works great with just one case no.

 

 

lyr = arcpy.mapping.ListLayers(mxd, "TAXLOTS")[0]

#Parcel numbers
values = arcpy.GetParameterAsText(0)
fieldName = "PIN"
values = values.split(";")  # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)

#selects the parcel numbers and creates Subject property
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
   arcpy.Select_analysis("TAXLOTS", "SUBJECT")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")

#AddsPermitNumber
Casenum = arcpy.GetParameterAsText(2)
SP = "SUBJECT"

arcpy.SelectLayerByLocation_management(SP, "INTERSECT", SP, "", "NEW_SELECTION")
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
    arcpy.CalculateField_management(SP, "PermitNo", '"' +Casenum+'"', "PYTHON_9.3") #"!{0}!".format(values)

 

Example.png

0 Kudos
3 Replies
CCWeedcontrol
Regular Contributor

I have this but how do I split the GetParameter into two if two parameters(GetParameterAsText(2))  are given and apply one to each Pin? 

lyr = arcpy.mapping.ListLayers(mxd, "TAXLOTS")[0]

#Parcel numbers
values = arcpy.GetParameterAsText(0)
fieldName = "PIN"
values = values.split(";")  # split values into list
values = ["'{0}'".format(v) for v in values] # add single quotes
whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)

#selects the parcel numbers and creates Subject property
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
   arcpy.Select_analysis("TAXLOTS", "SUBJECT")
arcpy.SelectLayerByAttribute_management("TAXLOTS", "CLEAR_SELECTION")

#AddsPermitNumber
Casenum = arcpy.GetParameterAsText(2)
SP = "SUBJECT"

arcpy.SelectLayerByLocation_management(SP, "INTERSECT", SP, "", "NEW_SELECTION")
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
    arcpy.CalculateField_management(SP, "PermitNo", '"' +Casenum+'"', "PYTHON_9.3") #"!{0}!".format(values)

args = [arcpy.GetParameterAsText(1)for i in range(arcpy.GetArgumentCount())]
#pCount = arcpy.GetArgumentCount(1)

if args == 2: #
    dsc = arcpy.Describe(SP)
    fields = dsc.fields
    #out_fields = [dsc.OIDFieldName]
    fieldnames = [field.name for field in fields]

    #lstFields = [field.name for field in fields]

    with arcpy.da.SearchCursor(SP,fieldnames) as sCur:
       with arcpy.da.InsertCursor(SP,fieldnames) as iCur:
          for row in sCur:
              iCur.insertRow(row)
else:
    pass

   I get the following

 

PinPermit No
12345MC2021-0002;CD2021-0005
12346MC2021-0002;CD2021-0005

 

But need

PinPermit No
12345MC2021-0002
12346CD2021-0005
0 Kudos
CCWeedcontrol
Regular Contributor

I currently coping and pasting features and I haven't been able to find any examples or ideas o how I can accomplish this so any help would be very appreciated. 

 

0 Kudos
CCWeedcontrol
Regular Contributor

Hopefully this helps someone, not sure if this is the best way but was the only thing I can find.

Code below line 8 is by JoshuaBixby.

 

 

Casenum = arcpy.GetParameterAsText(1)
Splt = str(Casenum.split(";"))
arcpy.AddMessage("Case ={0}".format(Splt))
SP = "SUBJECT"
arcpy.SelectLayerByLocation_management(SP, "INTERSECT", SP, "", "NEW_SELECTION")
if int(arcpy.GetCount_management("TAXLOTS").getOutput(0)) > 0:
   arcpy.CalculateField_management(SP, "PermitNo", '"' + Casenum +'"', "PYTHON_9.3")
   
split_fld = "PermitNo" # Field to split
split_delim = ";"# Delimeter for splitting field

sys_flds = [
   'OIDFieldName', 'globalIDFieldName',
   'ShapeFieldName', 'areaFieldName', 'lengthFieldName' 
]

desc = arcpy.Describe(SP)
sys_fld_names = [
   name for name in (getattr(desc, fld, '') for fld in sys_flds) if name
]    
usr_fld_names = [
   fld.name for fld in desc.fields if fld.name not in [split_fld] + sys_fld_names
]
cur_flds = ["SHAPE@", split_fld] + usr_fld_names

with arcpy.da.Editor(desc.path) as edit:
   with arcpy.da.UpdateCursor(SP, cur_flds) as ucur:
       with arcpy.da.InsertCursor(SP, cur_flds) as icur:
           for row in ucur:
               shape = row.pop(0)
               split = row.pop(0).split(split_delim)
               for i in split[1:]:
                   icur.insertRow([shape, i] + row)
               ucur.updateRow([shape, split[0]] + row)

 

 

 

0 Kudos