<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accessing Options/Preferences in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8767881#M22559</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/90084"&gt;@dennis&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...And haven't tried this yet, but can I set the value using dynamic?&amp;nbsp; Example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;files.QNewTemplateFile = @"C:\Templates\SomeTemplateName.dwt";&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try it! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 19:15:47 GMT</pubDate>
    <dc:creator>Alexander.Rivilis</dc:creator>
    <dc:date>2019-05-02T19:15:47Z</dc:date>
    <item>
      <title>Accessing Options/Preferences</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8765426#M22553</link>
      <description>&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Customization;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Runtime;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace MyClass.AutoCAD.EST
{
    public class PreferenceClass
    {
        public void SupportDriveFolder()
        {
            Document acDoc = acApp.DocumentManager.MdiActiveDocument;
            Database acDb = acDoc.Database;
            Editor acEd = acDoc.Editor;
            //object AcadApp = acApp.AcadApplication;
            //object acPref = AcadApp.GetType().InvokeMember("Preferences", BindingFlags.GetProperty, null, AcadApp, null);
            //object tabFiles = acPref.GetType().InvokeMember("Files", BindingFlags.GetProperty, null, acPref, null);
            //string searchpaths = (string)tabFiles.GetType().InvokeMember("SupportPath", BindingFlags.GetProperty, null, tabFiles, null);
            //var tempdwt = (string)tabFiles.GetType().InvokeMember("QNewTemplateFile", BindingFlags.GetProperty, null, tabFiles, null);
            AcadPreferences ap = (AcadPreferences)Application.Preferences;
            var files = ap.Files;
            var dwtfile = files.QNewTemplateFile;            
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;I get the following error when my code hits the line:&lt;/P&gt;
&lt;P&gt;AcadPreferences ap = (AcadPreferences)Application.Preferences;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;System.InvalidCastException&lt;BR /&gt;HResult=0x80004002&lt;BR /&gt;Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.AcadPreferences'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{E208B0FB-C9E4-4EEC-83A5-9BE18F2526FA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I have been working on accessing the Options, first off just to read, but then to make changes as well.&amp;nbsp; You can see in the posted code I have the "InvokeMemeber" part and it tests out fine.&amp;nbsp; So I then opted to try out "the other way" as shown at the page:&amp;nbsp;&amp;nbsp;&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUID-7E1AC51A-CDD6-4CD5-8703-3D3A472BFFC5-htm.html" target="_blank" rel="noopener"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUID-7E1AC51A-CDD6-4CD5-8703-3D3A472BFFC5-htm.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My entry code is as follows:&lt;/P&gt;
&lt;P&gt;[CommandMethod("PREFS")]&lt;BR /&gt;public static void prefs()&lt;BR /&gt;{&lt;BR /&gt;var pc = new PreferenceClass();&lt;BR /&gt;pc.SupportDriveFolder();&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help will be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 19:58:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8765426#M22553</guid>
      <dc:creator>dennis</dc:creator>
      <dc:date>2019-05-01T19:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Options/Preferences</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8765531#M22554</link>
      <description>&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace MyClass.AutoCAD.EST
{
  public class PreferenceClass
  {
    public string QNewTemplateFile()
    {
      dynamic app = acApp.AcadApplication;
      dynamic pref = app.Preferences;
      dynamic files = pref.Files;
      dynamic dwtfile = files.QNewTemplateFile;
      return dwtfile;
    }
  }
  public class Command
  {
    [CommandMethod("PREFS")]
    public static void prefs()
    {
      Document acDoc = acApp.DocumentManager.MdiActiveDocument;
      Database acDb = acDoc.Database;
      Editor acEd = acDoc.Editor;
      var pc = new PreferenceClass();
      var dwtfile = pc.QNewTemplateFile();
      acEd.WriteMessage($"\nQNewTemplateFile={dwtfile}");
    }
  }
}&lt;/PRE&gt;
&lt;P&gt;Also remove references to&amp;nbsp;Autodesk.AutoCAD.Interop.dll and&amp;nbsp;Autodesk.AutoCAD.Interop.Common.dll as far as it is look like you use wrong files (version or x86/x64)&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 20:51:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8765531#M22554</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2019-05-01T20:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Options/Preferences</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8765548#M22555</link>
      <description>&lt;P&gt;Other way:&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace MyClass.AutoCAD.EST
{
  public class PreferenceClass
  {
    public string TemplateFile()
    {
      string dwtfile = HostApplicationServices.Current
        .GetEnvironmentVariable("QnewTemplate");
      if (dwtfile.Length == 0)
      {
        dwtfile = HostApplicationServices.Current
        .GetEnvironmentVariable("LastTemplate");
      }
      return dwtfile;
    }
  }
  public class Command
  {
    [CommandMethod("PREFS")]
    public static void prefs()
    {
      Document acDoc = acApp.DocumentManager.MdiActiveDocument;
      Database acDb = acDoc.Database;
      Editor acEd = acDoc.Editor;
      var pc = new PreferenceClass();
      var dwtfile = pc.TemplateFile();
      acEd.WriteMessage($"\nTemplateFile={dwtfile}");
    }
  }
}&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 May 2019 21:04:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8765548#M22555</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2019-05-01T21:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Options/Preferences</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8766704#M22556</link>
      <description>&lt;P&gt;This is one of those "OMG that is so much easier".&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 12:17:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8766704#M22556</guid>
      <dc:creator>dennis</dc:creator>
      <dc:date>2019-05-02T12:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Options/Preferences</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8767871#M22557</link>
      <description>&lt;P&gt;I just discovered, by using Dynamic rather than defining the object AcadPreferences, I don't have the ability to "find" the name of the property i am after, like needing QNewTemplateFile rather than TemplateForQNEW.&amp;nbsp; Any ideas on that?&lt;/P&gt;
&lt;P&gt;And haven't tried this yet, but can I set the value using dynamic?&amp;nbsp; Example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;files.QNewTemplateFile = @"C:\Templates\SomeTemplateName.dwt";&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 19:14:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8767871#M22557</guid>
      <dc:creator>dennis</dc:creator>
      <dc:date>2019-05-02T19:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Options/Preferences</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8767880#M22558</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/90084"&gt;@dennis&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I just discovered, by using Dynamic rather than defining the object AcadPreferences, I don't have the ability to "find" the name of the property i am after, like needing QNewTemplateFile rather than TemplateForQNEW.&amp;nbsp; Any ideas on that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What about reading ActiveX Developer's Guide and Reference Guide (ActiveX/VBA):&amp;nbsp;&lt;A href="http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-5D302758-ED3F-4062-A254-FB57BAB01C44" target="_blank"&gt;http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-5D302758-ED3F-4062-A254-FB57BAB01C44&lt;/A&gt; ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 19:19:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8767880#M22558</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2019-05-02T19:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing Options/Preferences</title>
      <link>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8767881#M22559</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/90084"&gt;@dennis&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...And haven't tried this yet, but can I set the value using dynamic?&amp;nbsp; Example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;files.QNewTemplateFile = @"C:\Templates\SomeTemplateName.dwt";&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try it! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 19:15:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/accessing-options-preferences/m-p/8767881#M22559</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2019-05-02T19:15:47Z</dc:date>
    </item>
  </channel>
</rss>

