Pytの進捗


プログレスバーは
SetProgressorでStepさせるだけ、今更書いてみる。

import os.path
import arcpy
from arcpy import env
import time

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "MyToolbox"
        self.alias = ""

        self.tools = [CountFC]

# COUNT
class CountFC(object):
    def __init__(self):
        self.label = "数える"
        self.description = "数える"
        self.canRunInBackground = False

    def isLicensed(self):
        return True

    def getParameterInfo(self):
        param0 = arcpy.Parameter(
        displayName="カウントするワークスペース",
        name="in_workspace",
        datatype="DEWorkspace",
        parameterType="Required",
        direction="Input")

        return [param0]


    def updateParameters(self, parameters):
        return

    def updateMessages(self, parameters):
        return

    def execute(self, parameters, messages):
        try:
            env.workspace = parameters[0].value
            
            fcs = arcpy.ListFeatureClasses() 
            fcCount = len(fcs) 
            arcpy.SetProgressor("step", "FeatureClass数を数えます", 0,fcCount, 1) 

            for fc in fcs: 
                arcpy.SetProgressorLabel("FeatureClass " + arcpy.Describe(fc).name + "...") 
                arcpy.SetProgressorPosition()
                time.sleep(4)

            arcpy.ResetProgressor()
        except Exception as e:
            messages.AddErrorMessage(e.message)
        return
カテゴリー: 開発 タグ: パーマリンク