0

我正在为 ArcGis 10.0 使用 Visual Studio 2010 AddIn 模板。由于我已经为 ArcGIS 处理编写了 python 代码。我想在运行此 python 代码的 ArcMap 桌面命令栏中插入一个按钮。以下是我的简化c#代码和python代码开头供大家参考:

c#代码:

using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.VisualBasic;

namespace CallPython
{
    public class CallPython : ESRI.ArcGIS.Desktop.AddIns.Button
    {
        public CallPython()
        {
        }
        public string inputName()
        {
            string inputNames;
            inputNames = "cavert.shp";
            return inputNames;
        }
        protected override void OnClick()
        {
            inputName();
            System.Diagnostics.Process.Start(
                   "D:\\From2\\BCAP\\python\\scripts\\trans5.py");
        }
        protected override void OnUpdate()
        {
            Enabled = ArcMap.Application != null;
        }
    }

}

Python代码:

import arcpy
import os, win32com.client
from arcpy import env

arcpy.env.overwriteOutput = True
# Set environment settings
env.workspace = "D:/BCAP/trans/tempt/"

# Set local variables

vs_method_source = os.path.abspath("D:/Users/mar/CallPython/CallPython.cs")
vs_file_name = os.path.abspath("D:/Users/mar/CallPython/CallPython.sln")
vs = win32com.client.Dispatch("VisualStudio.DTE.7.1")
doc_template = vs.Documents.Open(vs_file_name)
mm = doc_template.CallPython.inputName() #CallPython is namespace, inputName is method

最后一行python代码就是问题所在。我知道这绝对不对,但不知道如何从 python 访问 C# 命名空间、类和方法。

4

0 回答 0