'
'  (C) Copyright 2008 by Autodesk, Inc.  All rights reserved.
'
' Permission to use, copy, modify, and distribute this software in
' object code form for any purpose and without fee is hereby granted, 
' provided that the above copyright notice appears in all copies and 
' that both that copyright notice and the limited warranty and
' restricted rights notice below appear in all supporting 
' documentation.
'
' AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
' AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
' MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
' UNINTERRUPTED OR ERROR FREE.
'
' Use, duplication, or disclosure by the U.S. Government is subject to 
' restrictions set forth in FAR 52.227-19 (Commercial Computer
' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
' (Rights in Technical Data and Computer Software), as applicable.
'
' This sample application shows how to create Revision List using COM API in SymBBAuto.
' To start the application, run CREATEREVLIST command.
'

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

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common.AcRegenType
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Interop.Common

Imports SymBBAuto.McadOrientation
Imports SymBBAuto.McadWeldSymbolType
Imports AcadmAuto.McadObjectType
Imports AcadmAuto
Imports SymBBAuto
Imports GEAuto

<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 = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application.18")
      Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument
      Dim symbb As McadSymbolBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
      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 = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application.18")
      Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument
      Dim symbb As McadSymbolBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
      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 = System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application.18")
      Dim ThisDrawing As AcadDocument = acadApp.ActiveDocument
      Dim symbb As McadSymbolBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
      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
