fixo, thanks for the response not quite what i was going for, but i had other problems to begin with. So i re-wrote the code and have since solved my original problem, so on to the next problem! so now i want to grab the current layer, set it to something else, insert my blocks and then restore the original layer upon exiting the program (with an exit button) so heres the code i have so far:
Code:
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType(Stall_Counter_Redux.StallCount))>
Namespace Stall_Counter_Redux
Public Class StallCount
<CommandMethod("Staller")> _
Public Sub GUI()
'gets current doc and database
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
'start transaction, access layertable, grab current layer, change to c-vprt.
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim LayTable As LayerTable = tr.GetObject(db.LayerTableId, OpenMode.ForRead)
Dim ltr As LayerTableRecord = CType(tr.GetObject(db.Clayer, OpenMode.ForRead), LayerTableRecord)
Dim curlay As String = "C-VPRT"
If LayTable.Has(curlay) = True Then
db.Clayer = LayTable(curlay)
tr.Commit()
End If
End Using
'initiate form
Dim myform As New StallCounterInterface
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(myform)
End Sub
End Class
End Namespace
and then the actual form/user interface:
Code:
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Public Class StallCounterInterface
Public Sub blocktest(ByVal BlockName As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
'test if block exists
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
If bt.Has(BlockName) Then
ed.WriteMessage(vbLf & "block exists, now inserting!")
Else
MsgBox("not found, insert source file")
Exit Sub
End If
End Using
Dim LoopControl As Boolean = True
Do While LoopControl
doc.LockDocument()
Me.Hide()
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim id As ObjectId = bt(BlockName)
' Get insertion point
Dim ppo As New PromptPointOptions(vbLf & "Specify insertion point, press [ESC] to return:")
Dim ppr As PromptPointResult = ed.GetPoint(ppo)
' Exit if the user presses ESC or cancels the command
If ppr.Status = PromptStatus.Cancel Then Exit Do
If ppr.Status = PromptStatus.OK Then
Dim pt As Point3d = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem)
' Create a block reference
Dim br As New BlockReference(pt, id)
' Get Model space
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
' Add the block reference to Model space
btr.AppendEntity(br)
tr.AddNewlyCreatedDBObject(br, True)
tr.Commit()
End If
End Using
Loop
Me.Show()
BlockName = Nothing
End Sub
Private Sub StdBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StdBtn.Click
Dim BlockName As String = "Standard"
blocktest(BlockName)
End Sub
Private Sub CompBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompBtn.Click
Dim BlockName As String = "Compact"
blocktest(BlockName)
End Sub
Private Sub VanBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VanBtn.Click
Dim BlockName As String = "Van"
blocktest(BlockName)
End Sub
Private Sub HandBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HandBtn.Click
Dim BlockName As String = "Handicap"
blocktest(BlockName)
End Sub
' This where i want to reset the layer to before the app was started.
Private Sub ExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
Me.Close()
End Sub
End Class
so what i need help with is passing "ltr" between classes, finding alot on passing between forms, but not classes.