TheSwamp
Code Red => .NET => Topic started by: autogis on November 19, 2013, 11:14:44 PM
-
When you extract the profile info (Options>>Profile>>Export) the "DefaultConfig" is a setting found in the ...\General] section of the arg file. How would you programmatically change that setting in AutoCAD. For example:
...DefaultConfig="Microsoft XPS Document Writer"
Does anyone know if this is possible in .NET/Interop?
Thank You
-
All done! :-D
Here is the code to set the Default Output Device ("DefaultConfig" in the ARG file) from .NET:
private void setupDefaultOutputDevice()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
//Cast the current autocad application from .net to COM interop
Autodesk.AutoCAD.Interop.AcadApplication oApp;
oApp = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
//Get the user preferences on the current profile
AcadPreferences profile = oApp.Preferences;
//Configure the default preferences
try
{
// Setup New Default Output Device (Must Exist)
string proposedDefaultOutputDevice = "Microsoft XPS Document Writer";
// Get DefaultConfig (From Autocad)
string currentDefaultOutputDevice = profile.Output.DefaultOutputDevice;
// Update Autocad if it does not match requested setting
if (proposedDefaultOutputDevice != currentDefaultOutputDevice)
{
// Write new Default Output Device
profile.Output.DefaultOutputDevice = proposedDefaultOutputDevice;
// Log
ed.WriteMessage("Default Output Device was incorrect. Setting new ...\n");
ed.WriteMessage("Old Output Device: " + currentDefaultOutputDevice + "\n");
ed.WriteMessage("New Output Device: " + proposedDefaultOutputDevice + "\n");
}
}
catch (System.Exception ex)
{
ed.WriteMessage("ERROR: setupDefaultOutputDevice: " + ex.Message + "\n");
ed.WriteMessage("ERROR: setupDefaultOutputDevice: " + ex.StackTrace + "\n");
}
}