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