如何在C#中调用引用了arcpy的python脚本?

自定义python脚本,脚本中调用了arcpy,如何在C#中调用该脚本?
已邀请:

朱新颖

赞同来自:

【解决办法】:
1.可以将该脚本制作为脚本工具,然后在Engine中直接调用该工具,推荐使用此种方法。
2.如果无法做成脚本工具,可以尝试在.Net中调用该.py文件,参考AO帮助: 
http://resources.arcgis.com/en ... 0000/
下面方式可以调用成功: 
[code]
string strPyScFile = string.Format({0}\\{1}, Application.StartupPath, zxy.py); //.py文件的路径

//Parameters 
string sArguments = string.Format({0}, strPyScFile); 
System.Diagnostics.Process p = new System.Diagnostics.Process(); 

p.StartInfo.FileName = @C:\Python27\ArcGIS10.2\python.exe;//Python程序路径 
p.StartInfo.Arguments = sArguments; 
p.StartInfo.UseShellExecute = false; 
// Do not create the black window. 
p.StartInfo.CreateNoWindow = true; 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.RedirectStandardInput = true; 
p.Start(); 
p.WaitForExit(); 
string result = p.StandardOutput.ReadToEnd(); //获取输出信息

kongfankongfan

赞同来自:

  1. QQ截图20190522084421.png
    我用c#调用arcpy,执行发布mxd到server的操作,此操作执行到print1就停止了好像,如上图代码,server没有发布成功,不知道什么原因?遇到过吗

要回复问题请先登录注册