02-05 控制AutoCAD环境(五) 设置AutoCAD选项

本文介绍如何使用.NET API和ActiveX Automation库访问AutoCAD的各种偏好设置,包括显示设置、绘图设置等,并提供了VB.NET、C# 和 VBA 的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Set AutoCAD Preferences设置AutoCAD选项

The .NET API does not contain any classes or methods to access the options in which are accessed through the AutoCAD Options dialog box. Access to these options is done through the ActiveX® Automation library. You use the COM object returned from the Preferences property of the Application object.

AutoCAD .NET API没有提供那些通过AutoCAD选项对话框访问选项的类和方法。要访问这些选项,必须使用ActiveX® Automation库。我们使用从Application对象的Preferences属性返回的COM对象(来访问这些选项)。

Once you have the Preferences COM object, you can then access the nine objects pertaining to the options, each representing a tab in the Options dialog box. These objects provide access to all of the registry-stored options in the Options dialog box. You can customize many of the AutoCAD settings by using properties found on these objects. These objects are:

一旦拥有COM对象Preferences,我们就可以访问附属于选项的九个对象,每个对象代表选项对话框的一个选项页。这些对象提供来了访问选项对话框中全部注册表存储选项的功能。通过使用这些对象的属性,我们可以自定义AutoCAD的许多设置。这些对象是:

(这九个对象统称为Perferences对象译者注)

·         PreferencesDisplay

·         PreferencesDrafting

·         PreferencesFiles

·         PreferencesOpenSave

·         PreferencesOutput

·         PreferencesProfiles

·         PreferencesSelection

·         PreferencesSystem

·         PreferencesUser

Access the Preferences object 访问Perferences对象

The following example shows how to access the Preferences object through COM interop.

下面示例演示怎样通过COM交互操作访问Perferences对象。

VB.NET

Dim acPrefComObj As AcadPreferences = Application.Preferences

C#

AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;

VBA/ActiveX Code Reference

Dim acadPref as AcadPreferences

Set acadPref = ThisDrawing.Application.Preferences

After you reference the Preferences object, you can then access any of the specific Preferences objects using the Display, Drafting, Files, OpenSave, Output, Profile, Selection, System, and User properties.

完成对Perferences对象的引用,我们就可以使用Display属性、 Drafting属性、 Files属性、 OpenSave属性、 Output属性、 Profile属性、 Selection属性、 System属性及User属性来访问指定的Perferences对象。

Set the crosshairs to full screen 设置十字光标为全屏幕

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.Interop

<CommandMethod("PrefsSetCursor")> _

Public Sub PrefsSetCursor()

  '' This example sets the crosshairs of the AutoCAD drawing cursor

  '' to full screen.

  '' Access the Preferences object

  Dim acPrefComObj As AcadPreferences = Application.Preferences

   '' Use the CursorSize property to set the size of the crosshairs

  acPrefComObj.Display.CursorSize = 100

End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Interop;

 [CommandMethod("PrefsSetCursor")]

public static void PrefsSetCursor()

{

  // This example sets the crosshairs for the drawing window

  // to full screen.

   // Access the Preferences object

  AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;

   // Use the CursorSize property to set the size of the crosshairs

  acPrefComObj.Display.CursorSize = 100;

}

VBA/ActiveX Code Reference

Sub PrefsSetCursor()

    ' This example sets the crosshairs of the AutoCAD drawing cursor

    ' to full screen

     ' Access the Preferences object

    Dim acadPref As AcadPreferences

    Set acadPref = ThisDrawing.Application.Preferences

     ' Use the CursorSize property to set the size of the crosshairs

    acadPref.Display.CursorSize = 100

End Sub

 

Hide the scroll bars 隐藏滚动条

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.Interop

 <CommandMethod("PrefsSetDisplay")> _

Public Sub PrefsSetDisplay()

  '' This example disables the scroll bars

   '' Access the Preferences object

  Dim acPrefComObj As AcadPreferences = Application.Preferences

   '' Disable the scroll bars

  acPrefComObj.Display.DisplayScrollBars = False

End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Interop;

 [CommandMethod("PrefsSetDisplay")]

public static void PrefsSetDisplay()

{

  // This example disables the scroll bars

   // Access the Preferences object

  AcadPreferences acPrefComObj = (AcadPreferences)Application.Preferences;

   // Disable the scroll bars

  acPrefComObj.Display.DisplayScrollBars = false;

}

VBA/ActiveX Code Reference

Sub PrefsSetDisplay()

    ' This example disables the scroll bars

     ' Access the Preferences object

    Dim acadPref As AcadPreferences

    Set acadPref = ThisDrawing.Application.Preferences

     ' Disable the scroll bars

    acadPref.Display.DisplayScrollBars = False

End Sub

 

Topics in this section本节主题

·  Database Preferences 数据库选项

1、Database Preferences数据库选项

Along with application level preferences, there are drawing based preferences that are accessed with the Options dialog box that are stored in a drawing file. To access these stored settings, use the appropriate property on the Database object or use the GetSystemVariable and SetSystemVariable methods of the Application object.

除了应用程序级的选项设置外,还有基于图形的选项设置,这些选项设置使用选项对话框访问并存储在图形文件里。要访问这些存储设置,使用Database对象的相应属性,或使用Application对象的GetSystemVariable方法和SetSystemVariable方法。

VBA/ActiveX Cross Reference

VBA/ActiveX交叉参考

VBA/ActiveX Class

.NET API Class

DatabasePreferences

Database and drawing based system variables

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值