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

Public Class Form1

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Hide()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim oDb As Database = HostApplicationServices.WorkingDatabase
        Dim oTr As Transaction = oDb.TransactionManager.StartTransaction

        Try

            Dim oLt As LayerTable = oTr.GetObject(oDb.LayerTableId, OpenMode.ForWrite)
            Dim oLtr As LayerTableRecord
            If Not oLt.Has(TextBox1.Text) Then
                oLtr = New LayerTableRecord
                oLtr.Name = TextBox1.Text
                oLt.Add(oLtr)
                oTr.AddNewlyCreatedDBObject(oLtr, True)
            Else
                MsgBox("既に画層が存在しています")
            End If

            oTr.Commit()

        Catch oEx As Exception
            MsgBox(oEx.ToString())
        Finally
            oTr.Dispose()
        End Try

        Me.Hide()

    End Sub
End Class