Coming from the same background as the original poster in this thread, I wonder if anyone has had any success creating an Arc10 Add-In using IronPython.
I have been able to access ArcObjects via IronPython using the info in the linked thread, assorted blog postings, and a few posts on the ESRI forums. These neophyte attempts have all been run from the command line and I would to be able to gain access through either a toolbar or a button.
One thought that I had was to create the add-in using the .Net 3.5 template, add a python file, and then call a function in the python file from the button's C# file. It appears though that add-ins are not yet supported in .Net4?
Here is the code from the .cs file which controls button functionality.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
//I need to then add references to IronPython
using IronPython;
using IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
namespace PyButtonTest
{
public class ZoomToLayer : ESRI.ArcGIS.Desktop.AddIns.Button
{
public ZoomToLayer()
{
}
protected override void OnClick()
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("ZoomToLayer.py");
test.ZoomToActiveLayerInTOC(); //Call this function in the py file
ArcMap.Application.CurrentTool = null;
}
protected override void OnUpdate()
{
Enabled = ArcMap.Application != null;
}
}
}
As far as I can tell the Add-in format takes care of getting the application hook. I should then be able to, in the python file, after referencing and importing all of the necessary libraries get the map document with (I think?)
mxDoc = ArcMapUI.IMxDocument.ActiveView
From here I am stumped. Google has not turned up anything helpful. Has anyone else tried this? Got something to work? Do I need to wait until add-ins are supported in .Net4 to go this route?