Accessing And Changing The AutoCAD Preferences
问题:How to access and change the AutoCAD preferences?
解答:
This could be done by manipulating the AutoCAD registry directly, or by using
the AutoCAD Preferences ActiveX object. Note that if you make a change in the
registry directly, those changes will not affect the current running AutoCAD
session. However, the ActiveX Preferences object exports all the AutoCAD
preferences properties through an interface that you can use in VBA / VB or
C++ / MFC applications. Attached below is a sample code snippet (in VB and C++)
which appends a new path to the existing AutoCAD support path.
Sample code for VB
Public acadApp As Object
Public acadPref As Object
Sub f_preferences()
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set acadApp = CreateObject("AutoCAD.Application")
If Err Then
MsgBox Err.Description & "" & Err.Number
Exit Sub
End If
End If
acadApp.Visible = True
Set acadPref = acadApp.Preferences
Dim strCurrentSuppPath As String
strCurrentSuppPath = acadPref.SupportPath 'set the current path to temporary
variable
'example: You want to add this "c:\test" path to the support path
acadPref.SupportPath = strCurrentSuppPath & ";" & "c:\test"
End Sub
Sample code for VC
#import "acad.tlb" no_namespace
void fSetSupportPath()
{
try
{
IAcadApplicationPtr pApp = NULL;
IAcadPreferencesPtr pPref = NULL;
IAcadPreferencesFilesPtr pPrefFiles = NULL;
pApp = acedGetAcadWinApp()->GetIDispatch(TRUE);
pPref = pApp->Preferences;
pPrefFiles = pPref->Files;
_bstr_t strOldPath;
strOldPath = pPrefFiles->GetSupportPath();
//print old support path
acutPrintf("\nOld Support path: %s",(char *)(_bstr_t)pPrefFiles->GetSupportPath());
//set the new support path
pPrefFiles->PutSupportPath(strOldPath + _bstr_t(";c:\\test"));
}
catch(_com_error &es)
{
}
}
页:
[1]