使用.Net在注册表中保存AutoCAD用户配置信息



Storing custom AutoCAD application settings in the Registry using .NET

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Namespace ApplicationSettings
    Public Class Commands
        ' We're using our Registered Developer Symbol (RDS)
        '  TTIF == Through the Interface
        ' for the section name.
        ' The entries beneath don't need this.
        Const sectionName As String = "TTIFSettings"
        Const intProperty As String = "TestInteger"
        Const doubleProperty As String = "TestDouble"
        Const stringProperty As String = "TestString"
        <CommandMethod("ATR")> _
        Public Shared Sub AddToRegistry()
            Dim con As IConfigurationSection = Application.UserConfigurationManager.OpenCurrentProfile()
            Using con
                Dim sec As IConfigurationSection = con.CreateSubsection(sectionName)
                Using sec
                    sec.WriteProperty(intProperty, 1)
                    sec.WriteProperty(doubleProperty, 2.0)
                    sec.WriteProperty(stringProperty, "Hello")
                End Using
            End Using
        End Sub
        <CommandMethod("RFR")> _
        Public Shared Sub RetrieveFromRegistry()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim prf As IConfigurationSection = Application.UserConfigurationManager.OpenCurrentProfile()
            Using prf
                If prf.ContainsSubsection(sectionName) Then
                    Dim sec As IConfigurationSection = prf.OpenSubsection(sectionName)
                    Using sec
                        Dim doubleValue As Double = CType(sec.ReadProperty(doubleProperty, 0.0), Double)
                        Dim stringValue As String = CType(sec.ReadProperty(stringProperty, ""), String)
                        Dim intValue As Integer = CType(sec.ReadProperty(intProperty, 0), Integer)
                        Dim defValue As Object = sec.ReadProperty("NotThere", 3.142)
                        ed.WriteMessage(vbLf & "Int value: " + intValue)
                        ed.WriteMessage(vbLf & "Double value: " + doubleValue)
                        ed.WriteMessage(vbLf & "String value: " + stringValue)
                        ed.WriteMessage(vbLf & "Non-existent value: " + defValue)
                    End Using
                End If
            End Using
        End Sub
    End Class
End Namespace

http://through-the-interface.typepad.com/thro ... 2008/05/storing-custom.html



How to make the plug-in commands not available



欢迎关注微信公众账号ByCAD