TheSwamp

Code Red => .NET => Topic started by: Andrey Bushman on March 12, 2015, 04:35:11 AM

Title: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Andrey Bushman on March 12, 2015, 04:35:11 AM
AutoCAD 2014x64, 2015x64.

It looks like a bug. For AutoCAD versions older than AutoCAD 2014 all works fine. Write a simple "Hello world":

Code - C#: [Select]
  1. /* © Andrey Bushman, 2015
  2.  * Commands.cs
  3.  */
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9.  
  10. using Rg = System.Text.RegularExpressions;
  11. using Dr = System.Drawing;
  12. using Fr = System.Windows.Forms;
  13. using Wp = System.Windows;
  14. using Wc = System.Windows.Controls;
  15. using Cn = System.Windows.Converters;
  16.  
  17. #if AUTOCAD
  18. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  19. using Ap = Autodesk.AutoCAD.ApplicationServices;
  20. using Db = Autodesk.AutoCAD.DatabaseServices;
  21. using Ed = Autodesk.AutoCAD.EditorInput;
  22. using Rt = Autodesk.AutoCAD.Runtime;
  23. using Gm = Autodesk.AutoCAD.Geometry;
  24. using Br = Autodesk.AutoCAD.BoundaryRepresentation;
  25. using Hs = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices;
  26. using Us = Autodesk.AutoCAD.DatabaseServices.SymbolUtilityServices;
  27. #endif
  28.  
  29. #if AUTOCAD && (PLATFORM_x64 || PLATFORM_x86)
  30. using In = Autodesk.AutoCAD.Interop;
  31. using Ic = Autodesk.AutoCAD.Interop.Common;
  32. #endif
  33.  
  34. using Ex = Bushman.CAD.Extensions.AutoCAD_Net_Extension1;
  35.  
  36. [assembly: Rt.CommandClass(typeof(Ex.Commands))]
  37.  
  38. namespace Bushman.CAD.Extensions.AutoCAD_Net_Extension1 {
  39.   public sealed class Commands {
  40.     const String cmdGroup = "Bushman";
  41.  
  42.     //*******************************************************************
  43.     // This is a CAD-command template. Don't forget to rename the default
  44.     // string values and method name.
  45.    
  46.     [Rt.CommandMethod(cmdGroup, "test", "testx",
  47.       Rt.CommandFlags.Modal)]
  48.     public void RenameMe_Command() {
  49.       Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
  50.       if (null == doc)
  51.         return;
  52.       Db.Database db = doc.Database;
  53.       Ed.Editor ed = doc.Editor;
  54.       using (doc.LockDocument()) {
  55.         using (Db.Transaction tr = db.TransactionManager.StartTransaction()) {
  56.           ed.WriteMessage("Hello, World!");
  57.           tr.Commit();
  58.         }
  59.       }
  60.     }
  61.     //*******************************************************************
  62.   }
  63. }

Compile it and to load into AutoCAD 2014 or 2015. Now I try to call my command through the some ways... AutoCAD displays not full list of existing commands (the global name of my command is not exists), and sometime calls not the same what I want. Look my attached ordered screens. Exists limitation of the attached files count. Therefore I do it through the two my messages.
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Andrey Bushman on March 12, 2015, 04:36:32 AM
The next attached files.
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Andrey Bushman on March 12, 2015, 05:01:48 AM
Additional info: when I use this:
Code - C#: [Select]
  1. [Rt.CommandMethod("test", Rt.CommandFlags.Modal)]
all works fine.

I.e. this problem is exists when I define the command group and try to call the global name of command without its group name. If in the _inputsearchoptions I uncheck the "AutoComplete" option - all works fine and for global name too (even it was called without the command group).
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Kerry on March 12, 2015, 05:23:26 AM

Andrey,
I think that one should go to ADN
Stephen Preston or Kean may be able to pass it on.
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Andrey Bushman on March 12, 2015, 05:25:25 AM
I am not ADN member.
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Kerry on March 12, 2015, 05:29:14 AM
http://www.theswamp.org/index.php?action=profile;u=12242
http://www.theswamp.org/index.php?action=profile;u=2050


Send a PM and point to this post.




Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Andrey Bushman on March 12, 2015, 05:40:03 AM
Send a PM and point to this post.
I did it. Thank you.
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Kean on March 12, 2015, 12:16:06 PM
Try removing the localizedNameId parameter to see if that helps:

[Rt.CommandMethod(cmdGroup, "test", Rt.CommandFlags.Modal)]

I suspect the loader is failing to find a resource with the ID of "testx" and so the DLL isn't being loaded at all.

It might not be that, of course, but that's where I'd start.

Kean
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Andrey Bushman on March 12, 2015, 02:10:12 PM
I suspect the loader is failing to find a resource with the ID of "testx" and so the DLL isn't being loaded at all.
You are not right. Localized command works fine. I find this info (http://through-the-interface.typepad.com/through_the_interface/2015/02/enabling-global-commands-on-localized-autocad-versions-using-net.html) also.
Title: Re: AutoCAD 2014,2015: Incorrect custom commands detecting
Post by: Kean on March 13, 2015, 05:06:54 AM
Yes... that's a blog post I wrote fairly recently, so I remember it. Why is it relevant, exactly?

I only have a snippet of your code to go on: I can't tell whether you have a string resource in your project with "testx" as an ID. In my code I didn't, and found everything to work perfectly when I removed the localized version, even with the group defined. If I'm going to reproduce the problem (without second-guessing your choices), it would help to see a reproducible sample project.

Kean