<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic C# and IronPython Hosting for Revit addins in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10624163#M23720</link>
    <description>&lt;P&gt;I try to run IronPython scripts via IronPython.Hosting in C# inspired by Nick Cosentino&amp;nbsp; in blog “&lt;A href="https://www.codeproject.com/Articles/657698/Python-Visual-Studio-and-Csharp-So-Sweet" target="_blank"&gt;Python, Visual Studio, and C#… So. Sweet&lt;/A&gt;”&lt;/P&gt;&lt;P&gt;The purpose of such effort is to create easy distributable and accessible addins in our company which are developed by small group of non IT experts on IronPython platform due to it’s flexibility and lower demandings for coding skills. Yes I’have heard about RevitPythonShell, but this is not exactly what would make sufficient result.&lt;/P&gt;&lt;P&gt;I was able to run classes from references &lt;EM&gt;RevitAPI&lt;/EM&gt; and &lt;EM&gt;RevitAPIU&lt;/EM&gt; but when it came across &lt;EM&gt;RevitServices&lt;/EM&gt; &amp;gt;:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;from RevitServices.Persistence import DocumentManager&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;doc = DocumentManager.Instance.CurrentDBDocument&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;uiapp = DocumentManager.Instance.CurrentUIApplication&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;the result are empty objects&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if this intention to run such scripts is useless effort due to some restrictions in source code or there is some way how to deal with this issue.&lt;/P&gt;&lt;P&gt;Any idea would be valuable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel Gerčák&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m adding piece of code for better overview.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Sep 2021 13:05:11 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-09-15T13:05:11Z</dc:date>
    <item>
      <title>C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10624163#M23720</link>
      <description>&lt;P&gt;I try to run IronPython scripts via IronPython.Hosting in C# inspired by Nick Cosentino&amp;nbsp; in blog “&lt;A href="https://www.codeproject.com/Articles/657698/Python-Visual-Studio-and-Csharp-So-Sweet" target="_blank"&gt;Python, Visual Studio, and C#… So. Sweet&lt;/A&gt;”&lt;/P&gt;&lt;P&gt;The purpose of such effort is to create easy distributable and accessible addins in our company which are developed by small group of non IT experts on IronPython platform due to it’s flexibility and lower demandings for coding skills. Yes I’have heard about RevitPythonShell, but this is not exactly what would make sufficient result.&lt;/P&gt;&lt;P&gt;I was able to run classes from references &lt;EM&gt;RevitAPI&lt;/EM&gt; and &lt;EM&gt;RevitAPIU&lt;/EM&gt; but when it came across &lt;EM&gt;RevitServices&lt;/EM&gt; &amp;gt;:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;from RevitServices.Persistence import DocumentManager&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;doc = DocumentManager.Instance.CurrentDBDocument&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;uiapp = DocumentManager.Instance.CurrentUIApplication&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;the result are empty objects&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if this intention to run such scripts is useless effort due to some restrictions in source code or there is some way how to deal with this issue.&lt;/P&gt;&lt;P&gt;Any idea would be valuable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel Gerčák&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’m adding piece of code for better overview.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 13:05:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10624163#M23720</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-15T13:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10625047#M23721</link>
      <description>&lt;P&gt;Dear Daniel,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As suggested in our prior personal email correspondence, you can take a look at the open source implementations of RevitPythonShell and pyRevit to discover how they have addressed this same issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck solving your task, and please let us know how you do so. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 17:57:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10625047#M23721</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2021-09-15T17:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10629723#M23722</link>
      <description>&lt;P&gt;Dear Jerremy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after you advised me to look at RevitPythonShell source code I did a little research and I was succesfull.&lt;/P&gt;&lt;P&gt;The point was to create a new variable within IronPython engine with assigned&amp;nbsp;commandData.Application object to it so that you could access to it from python environment. I named it the same way as it is in RPS "__revit__" in order to keep compatibility with scripts developed for RPS. Since I've tested it only by using a simple python code, I don't guarantee it's functionality with more complex scripts. Additional settings might be required.&lt;/P&gt;&lt;P&gt;The execute function looks like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public Result Execute(&lt;BR /&gt;ExternalCommandData commandData,&lt;BR /&gt;ref string message,&lt;BR /&gt;ElementSet elements)&lt;BR /&gt;{&lt;BR /&gt;UIApplication _revit = commandData.Application;&lt;BR /&gt;UIDocument uidoc = _revit.ActiveUIDocument;&lt;BR /&gt;Application app = _revit.Application;&lt;BR /&gt;Document doc = uidoc.Document;&lt;/P&gt;&lt;P&gt;var flags = new Dictionary&amp;lt;string, object&amp;gt;() { { "Frames", true }, { "FullFrames", true } };&lt;BR /&gt;var py = IronPython.Hosting.Python.CreateEngine(flags);&lt;BR /&gt;var scope = IronPython.Hosting.Python.CreateModule(py, "__main__");&lt;BR /&gt;scope.SetVariable("__commandData__", commandData);&lt;/P&gt;&lt;P&gt;// add special variable: __revit__ to be globally visible everywhere:&lt;BR /&gt;var builtin = IronPython.Hosting.Python.GetBuiltinModule(py);&lt;BR /&gt;builtin.SetVariable("__revit__", _revit);&lt;BR /&gt;py.Runtime.LoadAssembly(typeof(Autodesk.Revit.DB.Document).Assembly);&lt;BR /&gt;py.Runtime.LoadAssembly(typeof(Autodesk.Revit.UI.TaskDialog).Assembly);&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;py.ExecuteFile("totalSelectedVolume.py");&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog myDialog = new TaskDialog("IronPython Error");&lt;BR /&gt;myDialog.MainInstruction = "Couldn't execute IronPython script totalSelectedVolume.py: ";&lt;BR /&gt;myDialog.ExpandedContent = ex.Message;&lt;BR /&gt;myDialog.Show();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return Result.Succeeded;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;whole testing project as IExternalCommand see in attachment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 14:13:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10629723#M23722</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-17T14:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10629730#M23723</link>
      <description>&lt;P&gt;Congratulations on solving this and glad I was able to help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy weekend!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 14:15:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/10629730#M23723</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2021-09-17T14:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/11947374#M23724</link>
      <description>&lt;P&gt;Hi @Anonymous ,&lt;BR /&gt;Thank you very much for sharing the source code and the files!&lt;BR /&gt;Do you mind if I ask, how can I compile the attached files? I need to open the &lt;EM&gt;IronPython_engine.csproj&lt;/EM&gt; file in Visual Studio (by double clicking it), and then?&lt;BR /&gt;Do I need to have &lt;EM&gt;Python Tools for Visual Studio&lt;/EM&gt; installed first? Anything else?&lt;BR /&gt;&lt;BR /&gt;I would be grateful for any kind reply from you. Děkuji.&lt;/P&gt;</description>
      <pubDate>Sun, 07 May 2023 15:13:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/11947374#M23724</guid>
      <dc:creator>george1985</dc:creator>
      <dc:date>2023-05-07T15:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/11947583#M23725</link>
      <description>&lt;P&gt;You have two main simple options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Go to the original IronPython web site,&amp;nbsp; learn how to host it from scratch, and embed that in your own Revit add-in:&amp;nbsp;&lt;A href="https://ironpython.net/" target="_blank" rel="noopener"&gt;https://ironpython.net/&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Look at the ready-made RevitPythonShell and either use it as is or modify it to suit your own needs:&amp;nbsp;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://github.com/architecture-building-systems/revitpythonshell" target="_blank" rel="noopener"&gt;https://github.com/architecture-building-systems/revitpythonshell&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 May 2023 18:30:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/11947583#M23725</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2023-05-07T18:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/11947773#M23726</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/824630"&gt;@jeremy_tammik&lt;/a&gt; ,&lt;BR /&gt;Thank you for the reply.&lt;BR /&gt;I not qualified enough to understand how to implement option 1, or modify option 2.&lt;BR /&gt;What makes @Anonymous&amp;nbsp; solution fantastic is that it basically enables making an actual revit addon button which by clicking on it, directly calls a .py file. Unlike RevitPythonShell, which requires user to open the .py file, and then run it.&lt;/P&gt;</description>
      <pubDate>Sun, 07 May 2023 22:04:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/11947773#M23726</guid>
      <dc:creator>george1985</dc:creator>
      <dc:date>2023-05-07T22:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: C# and IronPython Hosting for Revit addins</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/12236568#M23727</link>
      <description>&lt;P&gt;Hey Hi, is it possible to run the code without clicking the addin from&amp;nbsp;addin &amp;gt;&amp;gt;External Tools&amp;nbsp;&amp;gt;&amp;gt; Particular_addin, after opening the revit file?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 06:47:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/c-and-ironpython-hosting-for-revit-addins/m-p/12236568#M23727</guid>
      <dc:creator>guru_s3LAHB</dc:creator>
      <dc:date>2023-09-13T06:47:15Z</dc:date>
    </item>
  </channel>
</rss>

