Friday, 21 July 2017

arcpy - Python Tool Not Opening



I know that this is definitely an ambiguous question. However, I initially had my Python toolbox working great. I then wanted to have additional functionality with it and added some more coding. Unfortunately, I ran into some indentation errors and ultimately redid the indents from scratch (tried multiple tools).


Now when I run a syntax check in ArcMap, it passes fine. However, when I double click on my tool, called Apply_LayerFeatures, then nothing happens. I get absolutely no feedback from ArcMap.


Does anyone have any idea why this may be happening? The purpose of the tool is to be able to apply the same symbology to multiple layers. The additional feature I was trying to implement was to check if the input is a set of points, then to enable labels using the same font format.


The code I have been working on is shown below:


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 = "Toolbox"
self.alias = ""

# List of tool classes associated with this toolbox
self.tools = [Apply_LayerFeatures]

class Apply_LayerFeatures(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Apply_LayerFeatures"

self.description = "Applies feautures to multiple layers. Customize a single layer and use it as a source layer in the tool then select layers to be modified by the tool"
self.canRunInBackground = False

def getParameterInfo(self):
"""Define parameter definitions"""

# First parameter = layer with customized features
source = arcpy.Parameter(
displayName = "Source layer with customized features",
name = "source",

datatype = "Feature Layer",
parameterType = "Required",
direction = "Input")

# Second parameter = layers to which customized features will be applied
updlayers = arcpy.Parameter(
displayName = "Layers with features to be updated",
name = "updlayers",
datatype = "GPValueTable",
parameterType = "Required",

direction = "Input")

labelFontSize = arcpy.Parameter(
displayName = "Label Font Size",
name = "labelFontSize",
datatype = "GPDouble",
parameterType = "Required",
direction = "Input")

updlayers.columns = [['Feature Layer', 'Features']]


params = [source,updlayers,labelFontSize]
return params

def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True

def execute(self, parameters, messages):
"""The source code of the tool."""


#Get Inputs
updlayers = parameters[1].values
labelFontSize = parameters[2].values

#labelFontSize = parameters[2].values

for layers in updlayers:
for labels in layers:
labels.showLabels = True

for a in labels.labelClasses:
a.expression = '"%s" + [Name] + "%s"' % ("","")

source = parameters[0].valueAsText
updlayers = parameters[1].valueAsText.split(";")

for app in updlayers:
arcpy.ApplySymbologyFromLayer_management(app.strip("'"),source)

arcpy.RefreshTOC

arcpy.RefreshActiveView
return


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...