- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
}
}
}
I get the following error when my code hits the line:
AcadPreferences ap = (AcadPreferences)Application.Preferences;
System.InvalidCastException
HResult=0x80004002
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)).
I have been working on accessing the Options, first off just to read, but then to make changes as well. You can see in the posted code I have the "InvokeMemeber" part and it tests out fine. So I then opted to try out "the other way" as shown at the page: https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-NET/files/GUI...
My entry code is as follows:
[CommandMethod("PREFS")]
public static void prefs()
{
var pc = new PreferenceClass();
pc.SupportDriveFolder();
}
Any help will be greatly appreciated.
Solved! Go to Solution.

