Author Topic: Finding support path in 2014 vs 2015  (Read 8491 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
Finding support path in 2014 vs 2015
« on: July 31, 2014, 05:03:42 PM »
I have some code that works fine in 2014 but not in 2015.  I know it was probably because of the changes to the API in 2015 but its been a long day and i have been unable to find an answer on the net.  I know it is something very simple but it is just escaping me right now.  Here is the code.


Code - C#: [Select]
  1. private static void SupportPath(string path)
  2. {
  3.         var preferences = Application.Preferences as AcadPreferences;
  4.         if (preferences != null)
  5.         {
  6.                 string supportPath = preferences.Files.SupportPath;
  7.                 if (!supportPath.ToLower().Contains(path))
  8.                 {
  9.                         preferences.Files.SupportPath = preferences.Files.SupportPath + path;
  10.                 }
  11.         }
  12.         else
  13.         {
  14.                 MessageBox.Show("Unable to verify support path for drawing templates is valid.");
  15.         }
  16. }


in 2015 it always brings up the message box indicating that my preferences is equal to null.  So what changed in 2015?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding support path in 2014 vs 2015
« Reply #1 on: July 31, 2014, 05:54:11 PM »
Hi Keith,
Do you have a reference to Autodesk.AutoCAD.Interop.dll ??

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.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Finding support path in 2014 vs 2015
« Reply #2 on: July 31, 2014, 06:17:26 PM »
I do Kerry.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

n.yuan

  • Bull Frog
  • Posts: 348
Re: Finding support path in 2014 vs 2015
« Reply #3 on: July 31, 2014, 06:28:40 PM »
Maybe, you referenced wrong version (older version, that is) of COM interop assembly?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding support path in 2014 vs 2015
« Reply #4 on: July 31, 2014, 06:33:38 PM »
Keith, I just tried this :

Code - C#: [Select]
  1. namespace AutoCAD_CSharp_2015_4
  2. {
  3.     public class MyCommands
  4.     {
  5.         // Modal Command with localized name
  6.         [CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Modal)]
  7.         public void MyCommand() // This method can have any name
  8.         {
  9.  
  10.             getSupportPath();
  11.  
  12.         }
  13.         private static void getSupportPath()
  14.         {
  15.             var preferences = Application.Preferences as AcadPreferences;
  16.             if (preferences != null)
  17.             {
  18.                 string supportPath = preferences.Files.SupportPath;
  19.                 Document doc = Application.DocumentManager.MdiActiveDocument;
  20.                 doc.Editor.WriteMessage(supportPath);
  21.             }
  22.             else
  23.             {
  24.                 MessageBox.Show("Unable to verify support path for drawing templates is valid.");
  25.             }
  26.         }
  27. }
  28.  

I got the result I expected.


Maybe, you referenced wrong version (older version, that is) of COM interop assembly?

I'd like a beer for each time I've done that :-)
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.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Finding support path in 2014 vs 2015
« Reply #5 on: July 31, 2014, 06:46:01 PM »
Select the interop dll in solution explorer then in properites palette set Embed Interop Types to False

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Finding support path in 2014 vs 2015
« Reply #6 on: July 31, 2014, 06:51:07 PM »
Or you can remove the Interop references from the project and

change
Code - C#: [Select]
  1.           var preferences = Application.Preferences as AcadPreferences;
  2.  

to

Code - C#: [Select]
  1.           dynamic preferences = Application.Preferences;
  2.  

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding support path in 2014 vs 2015
« Reply #7 on: July 31, 2014, 06:53:26 PM »
I do Kerry.

Duh Me!
It wouldn't compile without the reference would it. I'll go back to the peanut gallery. :-)
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Finding support path in 2014 vs 2015
« Reply #8 on: July 31, 2014, 07:02:11 PM »
Or you can remove the Interop references from the project and

change
Code - C#: [Select]
  1.           var preferences = Application.Preferences as AcadPreferences;
  2.  

to

Code - C#: [Select]
  1.           dynamic preferences = Application.Preferences;
  2.  

I like Intellisense too much :-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.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Finding support path in 2014 vs 2015
« Reply #9 on: July 31, 2014, 07:11:43 PM »
Or you can remove the Interop references from the project and

change
Code - C#: [Select]
  1.           var preferences = Application.Preferences as AcadPreferences;
  2.  

to

Code - C#: [Select]
  1.           dynamic preferences = Application.Preferences;
  2.  

I like Intellisense too much :-D

Thats why I like the recent list for references so I can add them for Intellisense then remove them for build. :-D

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Finding support path in 2014 vs 2015
« Reply #10 on: August 01, 2014, 08:53:34 AM »
Thanks for the help guys. 


At this point what I think I will do is create a separate project and just build two different dlls.  That way i can add the correct reference for each project and use the same code.  I am using the AutoLoader so it will only have to setup the PackageContents.xml file once.  Plus I will create a batch file to move my newly built dlls into my build directory for the AutoLoader.  It will take a few minutes to setup but when done will be easy to maintain.


Out of curiosity, is there any way to manipulate the support path using pure .net that does not involve using the registry?  I was really trying to avoid going down that path.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Finding support path in 2014 vs 2015
« Reply #11 on: August 01, 2014, 09:25:05 AM »
I also just figured out that I can use the AutoLoader to set a support path for each version also which would eliminate the code altogether.  DOH!
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Finding support path in 2014 vs 2015
« Reply #12 on: August 04, 2014, 04:11:32 PM »
Select the interop dll in solution explorer then in properites palette set Embed Interop Types to False




I missed this post somehow when coming up with a solution.  This is much better than creating a project for each release.  Now that I once again have a single project for 2014 and 2015 might I ask why you would set this to true?  What is the advantage to embedding vs not embedding?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Finding support path in 2014 vs 2015
« Reply #13 on: August 07, 2014, 12:09:02 PM »
I understand the general concept or idea enough that its safe when used with AutoCAD's COM interop Assemblies but for advice on other situations these links might help

http://msdn.microsoft.com/en-us/library/dd997297(v=vs.110).aspx
http://blogs.msdn.com/b/samng/archive/2010/01/24/the-pain-of-deploying-primary-interop-assemblies.aspx

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Finding support path in 2014 vs 2015
« Reply #14 on: August 07, 2014, 01:42:18 PM »
Thanks for the info Jeff.  It does help with the overall picture of what is happening..
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013