[Tutor] ArcPro Add Field Toolbox

Mats Wichmann mats at wichmann.us
Mon Apr 6 12:23:37 EDT 2020


If you don't get an answer, it may be because this is specialized stuff. I've certainly never heard of ArcPro / arcpy. Perhaps there's a community for it you could try?  

On April 5, 2020 4:31:22 PM MDT, "K. Lunzner" <mambafrutty at gmail.com> wrote:
>Hello everybody,
>
>
>
>I've been attending a Python course for a few weeks now. In this course
>we
>briefly went through the basics. Now we have to make an Add Field
>toolbox,
>similar to the original one (AddField_management).
>
>
>
>
>
>>      import arcpy
>
>>      arcpy.env.workspace “C:…”
>
>>      inputFC = arcpy.GetParameterAsText(0)
>
>>      inputString = arcpy.GetParameterAsText(1)
>
>>      fieldList =inputString.split(";")
>
>>      inputString = arcpy.ValidateFieldName(inputString,
>arcpy.env.workspace)
>
>>      fieldType = arcpy.GetParameterAsText(2)
>
>>      fieldLength = arcpy.GetParameterAsText(2)
>
>>      for fieldName in fieldList:
>
>>       arcpy.AddField_management(inputFC , fieldName, fieldType)
>
>>
>
>>       arcpy.AddMessage("Field created:" + fieldName)
>
>>      arcpy.AddMessage ("Process completed")
>
>
>
>Problem 1: fieldLength
>
>
>
>The field should only be selectable if you enter "text" in the
>fieldtype. I
>tried:
>
>
>
>>  def updateParameters(self):
>
>>         if self.params[2].value: # check that parameter has a value
>
>>               if self.params[2].value == "TEXT":
>
>>                    self.params[3].enabled = True
>
>>         else:
>
>>                    self.params[3].enabled = False
>
>
>
>but it is not working
>
>
>
>Problem 2: ValidateField
>
>Entry with special characters or spacing is still possible. It appears
>in
>the table: ‘A !’
>
>
>
>Problem 3:
>
>
>
>>   existingFields = [f.name for f in arcpy.ListFields(inputFC)]
>
>>   for fieldName in fieldList:
>
>>    if fieldName in existingFields:
>
>>     arcpy.AddMessage('Feld mit folgendem Name existiert bereits:
>%s'%(fieldName))
>
>
>
>If the name of a field type already exists, a message should appear and
>inform the user. It still shows that the field was created. Tried a
>listfield function (iflen ..) but it didn't work either...
>
>
>
>I've been trying for days now and have gone through all Esri aids in
>the
>meantime, but haven't been able to solve any of these problems so far.
>Thank you very much for any help!
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


More information about the Tutor mailing list