Author Topic: Expose ARX Function to .NET  (Read 36891 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Expose ARX Function to .NET
« Reply #60 on: August 27, 2007, 11:56:12 PM »
ues a reactor to fire your method

here is en example in C#

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Expose ARX Function to .NET
« Reply #61 on: August 28, 2007, 12:02:19 AM »

I haven't had a chance to follow this conversation ...

putting IronPython aside for a sec' ..
Have you guys posted a solution for MSc# with an arx function ??

Is this what you're after Kerry?
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

TR

  • Guest
Re: Expose ARX Function to .NET
« Reply #62 on: August 28, 2007, 12:03:45 AM »
Thanks a lot Dan. I will look over this tomorrow. I think this is exactly what I needed.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Expose ARX Function to .NET
« Reply #63 on: August 28, 2007, 12:24:36 AM »
Just for completeness I have cleaned up the code to be used in a C# class lib that could be imported into another class lib or Iron Python script. The function to use in arx will remain the same, it would be worth checking the signature if compiled into another dll for different versions though.

Code: [Select]
// Created By: Mick Duprez, 27th August 2007
// Used to register commands using a C wrapper for the acedRegCmds() macro

using System ;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.EditorInput;

namespace ClassLibrary
{
/// <summary>
/// PyAcadCmd Class:
/// Used to register commands on the AutoCAD command stack.
/// </summary>
public class PyAcadCmd
{
public PyAcadCmd()
{
}
public delegate void CmdDelegate();

/// <summary>
/// RegPyAcadCmd:
/// Registers a delegate (callback) with the AutoCAD command string
/// on the command stack.
/// </summary>
[DllImport("IronPyCmdReg.dll",
CallingConvention=CallingConvention.Cdecl,
EntryPoint = "?RegPyCmd@@YAXPBD0HP6AXXZ@Z")]
public static extern void RegPyAcadCmd(
string cmd_group,
string cmd_name,
Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags,
[MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate);
}
}
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Expose ARX Function to .NET
« Reply #64 on: August 28, 2007, 12:36:23 AM »
Nice work Mick!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Expose ARX Function to .NET
« Reply #65 on: August 28, 2007, 02:19:19 AM »

I haven't had a chance to follow this conversation ...

putting IronPython aside for a sec' ..
Have you guys posted a solution for MSc# with an arx function ??

Is >?>>> this <<<?< what you're after Kerry?

You trying to trick me Mick ?  :D



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Expose ARX Function to .NET
« Reply #66 on: August 28, 2007, 02:31:38 AM »
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Expose ARX Function to .NET
« Reply #67 on: August 28, 2007, 03:04:39 AM »

Mick, Isn't that link using Python stuff ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Expose ARX Function to .NET
« Reply #68 on: August 28, 2007, 05:39:06 AM »
I might have to get more involved with these types of projects
http://www.codeplex.com/IronLisp

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Expose ARX Function to .NET
« Reply #69 on: August 28, 2007, 08:06:26 AM »

Mick, Isn't that link using Python stuff ??


No, not at all Kerry, there is 2 vs2002 sln's, 1 arx which is an arx/dll which wraps the acedRegCmds and one C# class lib that PInvokes the plain C wrapper expoted from that dll/arx.
This will work for any case at all where you don't want to use attributes like the .net arx wrappers do as I did in the examples that followed that post.
It basically does what Tim wanted, makes a C function (in this case a  macro which needs a little more work) available to .net. What Daniel has done from what I can tell from a brief look is make the reg'ing of the command a bit easier by using reactors instead of having to register them at 'netload' (I think :roll:, I haven't looked that hard).
At the heart of it there is no 'real' Python code involved, while IronPython's syntax is Python, it is definitely not python 'binary' say, to put it another way, it's like comparing vb.net to vb, same lingo, different runtime environment.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

TR

  • Guest
Re: Expose ARX Function to .NET
« Reply #70 on: August 28, 2007, 09:31:58 AM »
Dan:

Since you are the man for compiling the 2008 C++ files (I still can't compile) could you compile Mick's code in with yours under a single dll file? This way I could test both ways of registering commands side by side and figure out which way will end up working best.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Expose ARX Function to .NET
« Reply #71 on: August 28, 2007, 11:21:27 AM »
Try this one, you may need to verify the new entry point
?RegPyCmd@@YAXPB_W0HP6AXXZ@Z

One more thing that you might look into
http://msdn2.microsoft.com/en-us/library/7esfatk4(VS.80).aspx

Quote
A reference to the function pointer to a managed delegate held by unmanaged code does not prevent the common language runtime from performing garbage collection on the managed object. 

TR

  • Guest
Re: Expose ARX Function to .NET
« Reply #72 on: August 28, 2007, 12:05:06 PM »
Thanks. I'll try to digest this all later on tonight after work.

TR

  • Guest
Re: Expose ARX Function to .NET
« Reply #73 on: August 28, 2007, 03:59:11 PM »
Dan:
I'm trying to call the code from C# in the same fashion Mick does in in reply 33, and I am unable to. After looking at the source code of the latest file you posted I can't find to find code that looks like Mick's and takes the same arguments? Am I mistaken?

TR

  • Guest
Re: Expose ARX Function to .NET
« Reply #74 on: August 28, 2007, 04:10:18 PM »
Nevermind, I'm an idiot and the code was there. I am still getting an overflow and my command isn't registered. I'll keep digging.