Skip to main content

控制 Python 工具箱中的许可行为

isLicensed 方法是一种可选验证方法,用于检查 Python 工具箱中的工具是否具有运行许可。 如果运行其他地理处理工具(由 Python 工具箱工具使用)所需的相应许可和扩展模块不可用,那么可使用该方法限制工具的运行。

如果 isLicensed 方法返回 False,则工具无法运行。 如果该方法返回 True 或者未使用该方法,则工具可以运行。

def isLicensed(self):
 """Allow the tool to run, only if the ArcGIS 3D Analyst extension
 is available."""
 try:
     if arcpy.CheckExtension("3D") != "Available":
         raise Exception
 except Exception:
     return False  # The tool cannot be run
 return True  # The tool can be run