POST
|
Dear Community When defining parameters in a .pyt (Python toolbox) I would like to make one of the parameters optional - I think. It's a boolean parameter, allowing the user to specify weather the tool is allowed to overwrite certain values. I have made it default to False, and that would be the correct setting in 9 of 10 cases, so I would prefer if the tool would be able to just go with this default value. Unfortunately, when run, the tool insist that I toggle the boolean, before it will remove the little green dot. If I run the tool with the default values untouched, it gives me an error-box saying: "ERROR 000735: Overwrite Existing OBJNAM and NOBJNM: Value is required" I have tried to change the parameter from parameterType="Required", to parameterType="Optional", but it seems to have no effect on the tool behaviour. I have decided to paste the entire code here, it's still 90% cut-and-paste from ArcGIS Help (10.2, 10.2.1, and 10.2.2) , ArcGIS Help (10.2, 10.2.1, and 10.2.2) , and others but I guess the error is in a combination of things, and not the isolated line. I have marked the parameter (line 81), that I try to change to make a difference.
#-------------------------------------------------------------
# Name: GNDBtoolbox.pyt
# Purpose: A python-toolbox to work with the "Greenlandic Names Data Base" (GNDB) and NIS.
# Author: Martin Hvidberg
# e-mail: mahvi@gst.dk, Martin@Hvidberg.net
# Created: 2014-09-16
# Copyright: CopyLeft
# ArcGIS ver: 10.2.0
# Python ver: 2.7.3
#-------------------------------------------------------------
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the .pyt file)."""
self.label = "The_GNDB_Toolbox"
self.alias = "Toolbox to work with GNDB and NIS"
self.description = "This is the description of the toolbox..."
# List of tool classes associated with this toolbox
self.tools = [GNDBruninTOC]
class GNDBruninTOC(object):
"""
GNDB update NIS - assuming feature classes all ready opened in TOC
Created on 27 Sep 2011
@author: mahvi@gst.dk / Martin@Hvidberg.net
"""
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "GNDB_update_NIS_run_in_TOC"
self.description = "This tool will update the selected NIS FC, which must be in the TOC"
self.canRunInBackground = True # True = Obey "Background Processing setting" in the Geoprocessing Options dialog.
def getParameterInfo(self):
"""Define parameter definitions"""
# 0. The Feature layer to receive GNDB names
param0 = arcpy.Parameter(
displayName="Input Features",
name="in_features",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
# 1. The point feature class holding the GNDB
param1 = arcpy.Parameter(
displayName="GNDB points",
name="GNDB",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
param1.value = "NamesP"
# 2. The Mode
param2 = arcpy.Parameter(
displayName="The Mode",
name="Mode",
datatype="GPString",
parameterType="Required",
direction="Input")
param2.filter.type = "ValueList"
param2.filter.list = ["Berit", "Test"]
param2.value = param2.filter.list[0]
# 3. Overwrite
param3 = arcpy.Parameter(
displayName="Overwrite Existing OBJNAM and NOBJNM",
name="Overwrite",
datatype="GPBoolean",
parameterType="Optional", # <------ This seems to have no effect ?
direction="Input")
param3.value = "False"
params = [param0, param1, param2, param3]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
# put processing here ...
return
... View more
09-30-2014
01:13 AM
|
0
|
5
|
2885
|
POST
|
In a .pyt I can define parameters as described in : ArcGIS Help (10.2, 10.2.1, and 10.2.2) I have created a boolean parameter, the code snippet is as follow: def getParameterInfo(self): """Define parameter definitions""" ... some other parameters ... # 3. Overwrite param3 = arcpy.Parameter( displayName="Overwrite Existing OBJ", name="Overwrite", datatype="GPBoolean", parameterType="Required", direction="Input") The parameter works, but it anoys me that it defaults to True, I would like it to default to False. v.h. Martin
... View more
09-26-2014
06:42 AM
|
0
|
5
|
4611
|
POST
|
"Python - From Novice to Professional" is my all times favourite ...
... View more
09-08-2014
01:00 PM
|
0
|
0
|
36
|
POST
|
How about generating a 10.3 version - and releasing it with 10.3 ? /M
... View more
06-14-2014
05:45 AM
|
0
|
0
|
15
|
POST
|
Dear Forum I need to make a small tool that will automatically Pan and Zoom around in ArcMap. The overall purpose is to time how long time it takes for the screen to redraw after each Pan/Zoom. First I made a script that jumped from Bookmark to Bookmark, but it didn???t wait for the re-draw to complete, before jumping to the next bookmark ??? I guess this would often be preferable, but in my case it was undesirable behavior. I have now tried the following code, which opens a feature class (arcpy.GetParameterAsText(0)) that holds 5 polygons. It???s intended to jump to the extent of each of the polygons, in turn. But it seems to jump to some enormous extent many times larger than my entire data extent. Can any one suggest a good way to make ArcMap jump from place to place, like if you were jumping from bookmark to bookmark, but using Python, and allowing the re-draw to be timed by Python?
import arcpy
strPolygons = arcpy.GetParameterAsText(0)
# Init
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
xtnInit = df.extent # remember the original extent
# Build list of OIDs
lstOIDs = list()
with arcpy.da.SearchCursor(strPolygons, ['OID@', 'SHAPE@AREA']) as cursor:
for row in cursor:
lstOIDs.append(row[0])
# Run through OIDs
arcpy.MakeFeatureLayer_management (strPolygons, "Boxes")
for ID in lstOIDs:
strSelector = '"OBJECTID" = '+str(ID)
arcpy.SelectLayerByAttribute_management("Boxes", "NEW_SELECTION", strSelector)
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
# closing up ...
df.extent = xtnInit
arcpy.RefreshActiveView()
Best regards Martin
... View more
05-20-2014
05:41 AM
|
0
|
1
|
831
|
POST
|
From the description of this item on ArcGIS Online: "This is a diagram generated automatically by a Python script ..." Could you provide that script, so we can generate an overview for ver. 10.2 /M
... View more
11-19-2013
08:12 AM
|
0
|
0
|
15
|
POST
|
Anyone written python email code that sends an email if the python script fails? I use the email part from this help page with our data base administration, it works well. http://resources.arcgis.com/en/help/main/10.2/index.html#//003n000000v7000000 /M
... View more
11-18-2013
11:39 AM
|
0
|
0
|
52
|
POST
|
Is there a reason why you are not simply copying them from one filegeodatabase to the other in Catalog? Yes - Two reasons. 1) Copying like that would not append features to an existing feature class, it would create a new feature classe with a '_1' name. 2) It would be time consuming. The data bases have 20-30 Feature classes, with potentially hundreds of subtypes (though they are not all populated). I need to do it often, so I would like it to be automatic. I have used the Batch-Copy-Paste tool. But the data base is multi-scale, and batch-copy-paste don't honour that, it puts the default Production Compilation Scale on all output features. /M
... View more
11-18-2013
11:29 AM
|
0
|
0
|
4
|
POST
|
Hi All I'm writing a arcpy script to copy many feature classes from one workspace (file geo database) to another. It's important for me that the script works between existing feature classes, i.e. Not try to create new feature classes, but appends the copied features as new features to the existing feature classes. If you know Batch-Copy-Paste, this is the same, only without messing up the PLTS_Compilation info. Due to the above requirements it seemed out of the question to use either of: arcpy.CopyFeatures_management() arcpy.FeatureClassToGeodatabase_conversion() arcpy.FeatureClassToFeatureClass_conversion() arcpy.Copy_management() even with the 'overwrite output' turned on, as they all aim at creating a new output feature class. I therefore decided to go row-by-row with a Search-cursor and an Insert-cursor. The two .gdb already exist, and have identical structure (schema) but the output.gdb holds no features in the feature classes The script looks like this: import os, arcpy
def inventory_data(workspace, datatypes):
for path, path_names, data_names in arcpy.da.Walk(workspace, datatype=datatypes):
for data_name in data_names:
yield os.path.join(path, data_name)
def match_feature_names(FA,lstFB):
FAName = FA[FA.rfind("\\")+1:]
for FB in lstFB:
if FAName in FB:
return FB
return False
#Main
genWSA = inventory_data(r"C:\data\input.gdb", "FeatureClass")
lstWSA = list(genWSA)
genWSB = inventory_data(r"C:\data\output.gdb", "FeatureClass")
lstWSB = list(genWSB)
for FCA in lstWSA:
print "Copying:"+FCA
lst_field_names = [fldX.name for fldX in arcpy.ListFields(FCA)]
curWrite = arcpy.da.InsertCursor(match_feature_names(FCA,lstWSB),lst_field_names)
with arcpy.da.SearchCursor(FCA,"*") as curRead:
for row in curRead:
curWrite.insertRow(row)
del curRead,curWrite For some reason it only works well for Point feature classes. Any Line or Polygon feature class have the attributes copied correctely, but the 'shape' is empty. Also the length- and area-field holds only 0 (zero) in all output rows Any suggestion are appreciated. Best regards Martin
... View more
11-18-2013
11:04 AM
|
0
|
2
|
112
|
POST
|
Thanks Chris Snyder The "Production Editing Advanced" toolbar was exactely what I needed! "Intersecting lines (Production Mapping)" was the tool I was looking for. http://resources.arcgis.com/en/help/main/10.1/index.html#//01030000026v000000 🙂 Thanks
... View more
08-16-2013
01:37 AM
|
0
|
0
|
30
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|