'//////////////////////////////////////////////////////////////////////////////
'//
'//  Copyright 2025 Autodesk, Inc.  All rights reserved.
'//
'//  Use of this software is subject to the terms of the Autodesk license 
'//  agreement provided at the time of installation or download, or which 
'//  otherwise accompanies this software in either electronic or hard copy form.   
'//
'//////////////////////////////////////////////////////////////////////////////
'

Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Type

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices

Imports SymBBAuto.McadOrientation
Imports SymBBAuto.McadWeldSymbolType
Imports AcadmAuto.McadObjectType
Imports AcadmAuto
Imports SymBBAuto
Imports GEAuto
Imports Autodesk.AutoCAD.Interop

<Assembly: ExtensionApplication(GetType(netRevisionList.netRevisionList))>
<Assembly: CommandClass(GetType(netRevisionList.CreateCommand))>

Namespace netRevisionList

    Public Class netRevisionList
        Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
        Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize

        End Sub
        Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate

        End Sub
    End Class

    Public Class CreateCommand
        ' Define command 'netRevisionList'
        <Autodesk.AutoCAD.Runtime.CommandMethod("CREATEREVLIST")>
        Public Sub createRevList()
            Dim acadApp As AcadApplication = Library.COM.getActiveObject("AutoCAD.Application.26")
            Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument
            Dim symbb As McadSymbolBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr.27")
            Dim revListMgr As McadRevisionMgr = symbb.RevisionListMgr

            'create a new descriptor object
            Dim revListDescriptor As McadRevisionListDescriptor = revListMgr.NewDescriptor()

            'specify settings which will be used for creating new revision list object
            Dim pos(2) As Double
            pos(0) = 3.0 : pos(1) = 3.0 : pos(2) = 0.0
            revListDescriptor.Position = pos
            Dim attributesMap As Object = revListDescriptor.Attributes
            For i = LBound(attributesMap) To UBound(attributesMap)
                If (attributesMap(i, 0) = "GEN-REV-NR") Then
                    attributesMap(i, 1) = "1"
                End If
                If (attributesMap(i, 0) = "GEN-REV-NAME") Then
                    attributesMap(i, 1) = "Autodesk"
                End If
            Next i

            'create a new revision list object
            revListMgr.CreateRevisionList(revListDescriptor)

            'update the drawing
            ThisDrawing.Application.Update()
        End Sub

        <Autodesk.AutoCAD.Runtime.CommandMethod("DELETEREVLIST")>
        Public Sub deleteRevList()
            Dim acadApp As AcadApplication = Library.COM.getActiveObject("AutoCAD.Application.26")
            Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument
            Dim symbb As McadSymbolBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr.27")
            Dim revListMgr As McadRevisionMgr = symbb.RevisionListMgr

            'retrieve the revision list collection object
            Dim revLists As McadRevisionLists = revListMgr.RevisionLists
            If revLists.Count = 0 Then
                Exit Sub
            End If

            'retrieve the particular revision list which is the first one in the collection object
            Dim revList As McadRevisionList = revLists.Item(0)

            'delete the revision list
            revListMgr.DeleteRevisionList(revList)
        End Sub

        <Autodesk.AutoCAD.Runtime.CommandMethod("MODIFYREVLINE")>
        Public Sub modifyRevLine()
            Dim acadApp As AcadApplication = Library.COM.getActiveObject("AutoCAD.Application.26")
            Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument
            Dim symbb As McadSymbolBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr.27")
            Dim revListMgr As McadRevisionMgr = symbb.RevisionListMgr

            'retrieve the revision list collection object
            Dim revLists As McadRevisionLists = revListMgr.RevisionLists
            If revLists.Count = 0 Then
                Exit Sub
            End If

            'retrieve the particular revision list which is the first one in the collection object
            Dim revList As McadRevisionList = revLists.Item(0)
            If revList.Count = 0 Then
                Exit Sub
            End If

            'retrieve the attributes of the first item in the revision list
            Dim attributesMap As Object = revList.Item(0)
            For i = LBound(attributesMap) To UBound(attributesMap)
                If (attributesMap(i, 0) = "GEN-REV-NAME") Then
                    attributesMap(i, 1) = "YourName"
                End If
            Next i

            'update the attributes of the item in the revision list
            Call revList.Set(0, attributesMap)
        End Sub
    End Class
End Namespace