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

0 Members and 1 Guest are viewing this topic.

JONTHEPOPE

  • Guest
Re: Finding support path in 2014 vs 2015
« Reply #15 on: August 18, 2014, 11:42:26 PM »
I can't seem to get my  .dll to auto load .
Am I missing a line?
I'm using ACAD2015.

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApplication]
"DESCRIPTION"="test application"
"LOADCTRLS"=dword:0000000e
"MANAGED"=dword:00000001
"LOADER"="C:\\My Path\\MyTestApp.dll"

I expect the program to run when when I open Cad and type the command???

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Finding support path in 2014 vs 2015
« Reply #16 on: August 19, 2014, 12:59:39 AM »
Hi,

Quote
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\MyTestApplication]
R17.0 stands for AutoCAD 2007. use R20.0 for AutoCAD 2015.

Quote
"LOADCTRLS" = 14
12 have to be used to load the application at a command invocation. In this case, you have to create two sub keys for the Command and the Group names.
To load the application at AutoCAD startup, use "LOADCTRLS" = 2.
See here and there.
« Last Edit: August 19, 2014, 01:17:11 AM by gile »
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
« Last Edit: August 19, 2014, 01:16:19 AM by Kerry »
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 #18 on: August 21, 2014, 11:56:29 AM »
Just out of curiosity.  Do you find the old way better than using the AutoLoader?  I didnt really start developing before the autoloader so i never used any of the old methods.  The autoloader is pretty easy to setup and integrating it into an install program such as Advanced Installer is very simple.  Just my 2 cents.
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 #19 on: August 21, 2014, 04:50:22 PM »
Just out of curiosity.  Do you find the old way better than using the AutoLoader?  I didnt really start developing before the autoloader so i never used any of the old methods.  The autoloader is pretty easy to setup and integrating it into an install program such as Advanced Installer is very simple.  Just my 2 cents.

Hi Keith,
If you mean the .bundle paradigm, I've never tried it.
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 #20 on: August 22, 2014, 09:00:39 AM »
Yup, that is what I meant.  Works well for me and saves me the trouble of coding alot of items that I really don't want to code.
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 #21 on: September 03, 2014, 09:35:05 AM »
Looks like you got it Keith but updating code for 2015 and thought I would through some different ways to modify PreferenceFiles.
 
Here is one way and as is requires .NET 4.5 but could be modified for earlier versions.
It uses the name of the properties for the variable name with CallerMemberNameAttribute  , and just add a property for each and make sure property names match environment variable names.
Code - C#: [Select]
  1.         [CommandMethod("EnviroTest1")]
  2.         public void EnviroTest1()
  3.         {
  4.             Ed.WriteLine(EnviromentVariables.QnewTemplate);
  5.         }
  6.         [CommandMethod("EnviroTest2")]
  7.         public void EnviroTest2()
  8.         {
  9.             EnviromentVariables.QnewTemplate = @"J:\CadManaged\AutoCAD\Hgce\Templates\HgceBase.dwt";
  10.             Ed.WriteLine(EnviromentVariables.QnewTemplate);
  11.         }  
  12.  

Code - C#: [Select]
  1.  public static class EnviromentVariables
  2.    {
  3.        [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl,
  4.        CharSet = CharSet.Auto, EntryPoint = "acedSetEnv")]
  5.        extern static private Int32 acedSetEnv(string var, string val);
  6.  
  7.        private static string GetEnviromentVariable([CallerMemberName] string name = "")
  8.        {
  9.            return HostApplicationServices.Current.GetEnvironmentVariable(name);
  10.        }
  11.        private static void SetEnviromentVariable(string value, [CallerMemberName] string name = "")
  12.         {
  13.             acedSetEnv(name, value);
  14.         }
  15.        public static string ACAD
  16.        {
  17.            get { return GetEnviromentVariable(); }
  18.            set { SetEnviromentVariable(value); }
  19.        }
  20.        public static string QnewTemplate
  21.        {
  22.            get { return GetEnviromentVariable(); }
  23.            set { SetEnviromentVariable(value); }
  24.        }
  25.        
  26.     }
  27.  
  28.  

 

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Finding support path in 2014 vs 2015
« Reply #22 on: September 03, 2014, 09:40:04 AM »
This is another way going COM route but uses DLR so no need to reference interop dlls.
Code - C#: [Select]
  1.         [CommandMethod("SFTest1")]
  2.         public void SFTest1()
  3.         {
  4.            
  5.             Ed.WriteLine(Preferences.SupportPaths.GetPaths());
  6.         }
  7.         [CommandMethod("SFTest2")]
  8.         public void SFTest2()
  9.         {
  10.             SupportPath sp = Preferences.SupportPaths;
  11.             Ed.WriteLine();
  12.             Ed.WriteLine(sp.Contains(@"C:\Users\Jeff\appdata\roaming\autodesk\applicationplugins"));
  13.             Ed.WriteLine(sp.Contains(@"%AppData%\Autodesk\ApplicationPlugins"));
  14.             sp.Remove(@"C:\Users\Jeff\appdata\roaming\autodesk\applicationplugins");
  15.             sp.SaveChanges();
  16.             Ed.WriteLine(Preferences.SupportPaths.GetPaths());
  17.            
  18.         }
  19.  

Code - C#: [Select]
  1.     interface IAcadPathRepository
  2.     {
  3.         IEnumerable<string> GetPaths();
  4.         void Add(string path);
  5.         void Insert(int index, string path);
  6.         bool Remove(string path);
  7.         void SaveChanges();
  8.         bool Contains(string path);
  9.     }
  10.  

 
Code - C#: [Select]
  1.      public static class Preferences
  2.     {
  3.          static dynamic AcadPreferences { get { return Application.Preferences; } }
  4.          static dynamic AcadPreferencesFiles { get { return AcadPreferences.Files; } }
  5.         public static SupportPath SupportPaths { get { return new SupportPath(AcadPreferencesFiles); } }
  6.     }
  7.  

Code - C#: [Select]
  1.      public class SupportPath : IAcadPathRepository
  2.     {
  3.         private static char[] seperator = new char[] { ';' };
  4.         private List<string> paths = new List<string>();
  5.  
  6.         private dynamic _acadPreferencesFiles;
  7.         private dynamic PreferencesFile
  8.         {
  9.             get { return _acadPreferencesFiles.SupportPath; }
  10.             set{_acadPreferencesFiles.SupportPath = value;}
  11.         }
  12.         public SupportPath(dynamic acadPreferencesFiles)
  13.         {
  14.             _acadPreferencesFiles = acadPreferencesFiles;
  15.             paths = CreatepathList(PreferencesFile);
  16.         }
  17.         public IEnumerable<string> GetPaths()
  18.         {
  19.             return paths.AsReadOnly();
  20.         }
  21.         public void Add(string path)
  22.         {
  23.             path = Expand(path);
  24.             paths.Add(path);
  25.            
  26.            
  27.         }
  28.         public void Insert(int index, string path)
  29.         {
  30.             path = Expand(path);
  31.             paths.Insert(index, path);
  32.         }
  33.         public bool Remove(string path)
  34.         {
  35.             path = Expand(path);
  36.             return paths.Remove(path);
  37.         }
  38.        
  39.        
  40.         public bool Contains(string path)
  41.         {
  42.             return paths.Contains(Expand(path), StringComparer.OrdinalIgnoreCase);
  43.         }
  44.  
  45.         public void SaveChanges()
  46.         {
  47.             PreferencesFile = CreatePathsString(paths);
  48.             paths = CreatepathList(PreferencesFile);
  49.            
  50.         }
  51.        
  52.         private static List<string> CreatepathList(string pathString)
  53.         {
  54.             return pathString.Split(seperator).ToList();
  55.         }
  56.         private static string CreatePathsString(IEnumerable<string> pathList)
  57.         {
  58.             return String.Join(";", pathList);
  59.         }
  60.         private static string Expand(string path)
  61.         {
  62.            return path.StartsWith("%") ? Environment.ExpandEnvironmentVariables(path) : path;
  63.         }
  64.     }
  65.  

 
If your were wanting to make it more like a DirectoryInfo object than a string and quickly slapped together
Code - C#: [Select]
  1.     public class AcadDirectory : IEquatable<AcadDirectory>
  2.     {
  3.  
  4.         private readonly DirectoryInfo _directoryInfo;
  5.         public AcadDirectory(string path)
  6.         {
  7.             _directoryInfo = path.StartsWith("%") ? new DirectoryInfo(Environment.ExpandEnvironmentVariables(path)) : new DirectoryInfo(path);
  8.         }
  9.         public bool Exists { get { return _directoryInfo.Exists; } }
  10.         public string Path { get { return _directoryInfo.FullName; } }
  11.         public string Name { get { return _directoryInfo.Name; } }
  12.  
  13.         public bool Equals(AcadDirectory other)
  14.         {
  15.             if (other == null)
  16.                 return false;
  17.             return this.Name == other.Name;
  18.         }
  19.         public override bool Equals(object obj)
  20.         {
  21.             if (obj == null) return false;
  22.             var acadDir = obj as AcadDirectory;
  23.             return acadDir != null && Equals(acadDir);
  24.         }
  25.         public override int GetHashCode()
  26.         {
  27.             return (String.IsNullOrEmpty(Name) ? Name.GetHashCode() : 0);
  28.         }
  29.         public static bool operator ==(AcadDirectory acadDir1, AcadDirectory acadDir2)
  30.         {
  31.             if ((object)acadDir1 == null || ((object)acadDir2) == null)
  32.                 return Equals(acadDir1, acadDir2);
  33.             return acadDir1.Equals(acadDir2);
  34.         }
  35.         public static bool operator !=(AcadDirectory acadDir1, AcadDirectory acadDir2)
  36.         {
  37.             if (acadDir1 == null || acadDir2 == null)
  38.                 return !Equals(acadDir1, acadDir2);
  39.             return !(acadDir1.Equals(acadDir2));
  40.         }
  41.     }
  42.  

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Finding support path in 2014 vs 2015
« Reply #23 on: September 05, 2014, 09:16:32 AM »
Thanks for the information Jeff.  I will circle back around this and digest it when work lets up a little bit.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013