Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>UPDATE - I've written a more generic example (plus a link to a zip file containing the entire VS2008 project) as entry on my blog <a href="http://oldschooldotnet.blogspot.com/2011/04/scripting-ccli-with-ironpython-visual.html" rel="nofollow" title="here.">here.</a></p> <p>Sorry, I am so late to the game, but here is how I have integrated IronPython into a C++/cli app in Visual Studio 2008 - .net 3.5. (actually mixed mode app with C/C++)</p> <p>I write add-ons for a map making applicaiton written in Assembly. The API is exposed so that C/C++ add-ons can be written. I mix C/C++ with C++/cli. Some of the elements from this example are from the API (such as XPCALL and CmdEnd() - please just ignore them)</p> <pre><code>/////////////////////////////////////////////////////////////////////// void XPCALL PythonCmd2(int Result, int Result1, int Result2) { if(Result==X_OK) { try { String^ filename = gcnew String(txtFileName); String^ path = Assembly::GetExecutingAssembly()-&gt;Location; ScriptEngine^ engine = Python::CreateEngine(); ScriptScope^ scope = engine-&gt;CreateScope(); ScriptSource^ source = engine-&gt;CreateScriptSourceFromFile(String::Concat(Path::GetDirectoryName(path), "\\scripts\\", filename + ".py")); scope-&gt;SetVariable("DrawingList", DynamicHelpers::GetPythonTypeFromType(AddIn::DrawingList::typeid)); scope-&gt;SetVariable("DrawingElement", DynamicHelpers::GetPythonTypeFromType(AddIn::DrawingElement::typeid)); scope-&gt;SetVariable("DrawingPath", DynamicHelpers::GetPythonTypeFromType(AddIn::DrawingPath::typeid)); scope-&gt;SetVariable("Node", DynamicHelpers::GetPythonTypeFromType(AddIn::Node::typeid)); source-&gt;Execute(scope); } catch(Exception ^e) { Console::WriteLine(e-&gt;ToString()); CmdEnd(); } } else { CmdEnd(); } } /////////////////////////////////////////////////////////////////////////////// </code></pre> <p>As you can see, I expose to IronPython some objects (DrawingList, DrawingElement, DrawingPath &amp; Node). These objects are C++/cli objects that I created to expose "things" to IronPython. </p> <p>When the C++/cli source->Execute(scope) line is called, the only python line to run is the DrawingList.RequestData.</p> <p>RequestData takes a delegate and a data type.</p> <p>When the C++/cli code is done, it calls the delegate pointing to the function "diamond"</p> <p>In the function diamond it retrieves the requested data with the call to DrawingList.RequestedValue() The call to DrawingList.AddElement(dp) adds the new element to the Applications visual Database.</p> <p>And lastly the call to DrawingList.EndCommand() tells the FastCAD engine to clean up and end the running of the plugin.</p> <pre><code>import clr def diamond(Result1, Result2, Result3): if(Result1 == 0): dp = DrawingPath() dp.drawingStuff.EntityColor = 2 dp.drawingStuff.SecondEntityColor = 2 n = DrawingList.RequestedValue() dp.Nodes.Add(Node(n.X-50,n.Y+25)) dp.Nodes.Add(Node(n.X-25,n.Y+50)) dp.Nodes.Add(Node(n.X+25,n.Y+50)) dp.Nodes.Add(Node(n.X+50,n.Y+25)) dp.Nodes.Add(Node(n.X,n.Y-40)) DrawingList.AddElement(dp) DrawingList.EndCommand() DrawingList.RequestData(diamond, DrawingList.RequestType.PointType) </code></pre> <p>I hope this is what you were looking for.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload