Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Arcmap脚本不会在Arcmap控制台中打印消息_Python_Arcgis_Python Idle_Arcpy_Arcmap - Fatal编程技术网

Python Arcmap脚本不会在Arcmap控制台中打印消息

Python Arcmap脚本不会在Arcmap控制台中打印消息,python,arcgis,python-idle,arcpy,arcmap,Python,Arcgis,Python Idle,Arcpy,Arcmap,我为Arcmap编写了一个Python脚本。我试图创建一个工具,将工作区中的所有要素类重新投影到指定的要素类 我遇到的问题是,我无法让Arcmap打印“已完成”的消息。当我硬编码变量并将其作为脚本运行时,我希望显示的消息将打印出来,但它们不会在Arcmap中打印。你可以在下面的代码中看到,我有一些我想要打印的特定打印消息,但它们就是不会出现 代码: 当我将脚本上载到Arcmap工具箱时,将不会打印以下行(来自上述代码): print“+str(fc)+”的“投影”是“+desc.spatialR

我为Arcmap编写了一个Python脚本。我试图创建一个工具,将工作区中的所有要素类重新投影到指定的要素类

我遇到的问题是,我无法让Arcmap打印“已完成”的消息。当我硬编码变量并将其作为脚本运行时,我希望显示的消息将打印出来,但它们不会在Arcmap中打印。你可以在下面的代码中看到,我有一些我想要打印的特定打印消息,但它们就是不会出现

代码:

当我将脚本上载到Arcmap工具箱时,将不会打印以下行(来自上述代码):

print“+str(fc)+”的“投影”是“+desc.spatialReference.name+”,因此现在重新定义投影:\n“

打印“+str(newFeat.baseName)+”+arcpy.GetMessage(count-1)+”\n”的重投影

print“重新投影的新文件名为“+name+”\n”


如何修复此问题?

print
仅在脚本在Python解释器中运行时打印消息。要在ArcGIS工具箱中运行脚本时打印日志,需要使用


我怀疑IDLE与此有关,但为了确保这一点,请直接使用python运行脚本,而不涉及IDLE。
#Import modules
import arcpy, os

#Set workspace directory
from arcpy import env

#Define workspace
inWorkspace = arcpy.GetParameterAsText(0)
env.workspace = inWorkspace
env.overwriteOutput = True

try:
    #Define local feature class to reproject to:
    targetFeature = arcpy.GetParameterAsText(1)

    #Describe the input feature class
    inFc = arcpy.Describe(targetFeature)
    sRef = inFc.spatialReference

    #Describe input feature class
    fcList = arcpy.ListFeatureClasses()

    #Loop to re-define the feature classes and print the messages:
    for fc in fcList:
        desc = arcpy.Describe(fc)
        if desc.spatialReference.name != sRef.name:
            print "Projection of " + str(fc) + " is " + desc.spatialReference.name + ", so re-defining projection now:\n"
            newFc = arcpy.Project_management(fc, "projected_" + fc, sRef)
            newFeat = arcpy.Describe(newFc)
            count = arcpy.GetMessageCount()
            print "The reprojection of " + str(newFeat.baseName) + " " + arcpy.GetMessage(count-1) + "\n"

    #Find out which feature classes have been reprojected
    outFc = arcpy.ListFeatureClasses("projected_*")

    #Print a custom messagae describing which feature classes were reprojected
    for fc in outFc:
        desc = arcpy.Describe(fc)
        name = desc.name
        name = name[:name.find(".")]
    name = name.split("_")
    name = name[1] + "_" + name[0]
    print "The new file that has been reprojected is named " + name + "\n"

except arcpy.ExecuteError:
    pass

severity = arcpy.GetMaxSeverity()

if severity == 2:
    print "Error occurred:\n{0}".format(arcpy.GetMessage(2))
elif severity == 1:
    print "Warning raised:\n{1}".format(arcpy.GetMessage(1))
else:
    print "Script complete"
arcpy.AddMessage("Projection of {0} is {1}, so re-defining projection now: ".format(str(fc), desc.spatialReference.name)