.NET

Reply
*perry
Message 1 of 7 (242 Views)

speaking of cui files

242 Views, 6 Replies
08-15-2006 08:10 AM
Is there any way in .Net to enable/disable menu items?
In Arx I used the menucmd function to do this but don's
see anything like that in the .Net api's.
Perry
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 2 of 7 (242 Views)

Re: speaking of cui files

08-15-2006 09:06 AM in reply to: *perry
What about use of acedMenuCmd() with P/Invoke in .NET-application?
*perry
Message 3 of 7 (242 Views)

Re: speaking of cui files

08-15-2006 10:22 AM in reply to: *perry
Alexander Rivilis wrote:
> What about use of acedMenuCmd() with P/Invoke in .NET-application?
I haven't tried that Alexander, I'm not really a COM kinda guy.
May have to though!
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 4 of 7 (242 Views)

Re: speaking of cui files

08-15-2006 02:05 PM in reply to: *perry
Try this code:
[code]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(ClassLibrary.Class))]

namespace ClassLibrary
{
public class Class
{
class MenuCmd
{
static int AcadVersion = Autodesk.AutoCAD.ApplicationServices.Application.Version.Major;
// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "acedMenuCmd")]
extern private static int acedMenuCmd16(string cmd);
// For AutoCAD 2007:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedMenuCmd")]
extern private static int acedMenuCmd17(string cmd);
public static int acedMenuCmd(string cmd)
{
switch (AcadVersion)
{
case 16: return acedMenuCmd16 (cmd);
case 17: return acedMenuCmd17 (cmd);
}
return -1;
}
};

[CommandMethod("TESTMENU")]
static public void test() // This method can have any name
{
MenuCmd.acedMenuCmd("p0=ACAD.OSNAP");
MenuCmd.acedMenuCmd("p0=*");
}
}
}
[/code]
*perry
Message 5 of 7 (242 Views)

Re: speaking of cui files

08-15-2006 04:53 PM in reply to: *perry
Alexander Rivilis wrote:
> Try this code:
> [code]
> using System;
> using System.Runtime.InteropServices;
> using Autodesk.AutoCAD.Runtime;
>
> [assembly: CommandClass(typeof(ClassLibrary.Class))]
>
> namespace ClassLibrary
> {
> public class Class
> {
> class MenuCmd
> {
> static int AcadVersion = Autodesk.AutoCAD.ApplicationServices.Application.Version.Major;
> // For AutoCAD 2006:
> [System.Security.SuppressUnmanagedCodeSecurity]
> [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "acedMenuCmd")]
> extern private static int acedMenuCmd16(string cmd);
> // For AutoCAD 2007:
> [System.Security.SuppressUnmanagedCodeSecurity]
> [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedMenuCmd")]
> extern private static int acedMenuCmd17(string cmd);
> public static int acedMenuCmd(string cmd)
> {
> switch (AcadVersion)
> {
> case 16: return acedMenuCmd16 (cmd);
> case 17: return acedMenuCmd17 (cmd);
> }
> return -1;
> }
> };
>
> [CommandMethod("TESTMENU")]
> static public void test() // This method can have any name
> {
> MenuCmd.acedMenuCmd("p0=ACAD.OSNAP");
> MenuCmd.acedMenuCmd("p0=*");
> }
> }
> }
> [/code]

Hey thanks Alexander :0
I will try this as soon as I can.
Looks like a good example for me to learn from also.
*perry
Message 6 of 7 (242 Views)

Re: speaking of cui files

08-17-2006 05:12 PM in reply to: *perry
Alexander Rivilis wrote:
> Try this code:
> [code]
> using System;
> using System.Runtime.InteropServices;
> using Autodesk.AutoCAD.Runtime;
>
> [assembly: CommandClass(typeof(ClassLibrary.Class))]
>
> namespace ClassLibrary
> {
> public class Class
> {
> class MenuCmd
> {
> static int AcadVersion = Autodesk.AutoCAD.ApplicationServices.Application.Version.Major;
> // For AutoCAD 2006:
> [System.Security.SuppressUnmanagedCodeSecurity]
> [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "acedMenuCmd")]
> extern private static int acedMenuCmd16(string cmd);
> // For AutoCAD 2007:
> [System.Security.SuppressUnmanagedCodeSecurity]
> [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "acedMenuCmd")]
> extern private static int acedMenuCmd17(string cmd);
> public static int acedMenuCmd(string cmd)
> {
> switch (AcadVersion)
> {
> case 16: return acedMenuCmd16 (cmd);
> case 17: return acedMenuCmd17 (cmd);
> }
> return -1;
> }
> };
>
> [CommandMethod("TESTMENU")]
> static public void test() // This method can have any name
> {
> MenuCmd.acedMenuCmd("p0=ACAD.OSNAP");
> MenuCmd.acedMenuCmd("p0=*");
> }
> }
> }
> [/code]

Thanks Alexander
what you provided worked like a charm. Took me awhile though to figure
out how to "grey" a menu item. Not used to cui files yet, was using the
wrong "ID's". Works good now though :smileyhappy:

Can I access any Acad command the same way?
Perry
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 7 of 7 (242 Views)

Re: speaking of cui files

08-18-2006 01:27 AM in reply to: *perry
> Can I access any Acad command the same way?
Yes you can: http://discussion.autodesk.com/thread.jspa?messageID=4852689
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.