PDA

View Full Version : Current space using VB.Net ?



KevinBarnett
2006-01-26, 05:39 AM
Greetings,

How do I re-write this VBA code in VB.Net? :


If ThisDrawing.ActiveSpace = acModelSpace Then
MsgBox("currently in the Model tab")
Else
If ThisDrawing.MSpace = True Then
MsgBox("currently in the model space of a paper space viewport")
Else
MsgBox("currently in paper space")
End If
End If

A recommendation I received looks like this:


Imports System
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.GraphicsInterface

Public Class Class1
<CommandMethod("DNUS")> _
Public Sub DNUS()
Dim DB As Autodesk.AutoCAD.DatabaseServices.Database
Dim TM As Autodesk.AutoCAD.DatabaseServices.TransactionManager
Dim CT As Autodesk.AutoCAD.DatabaseServices.Transaction
DB = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
TM = DB.TransactionManager
CT = TM.StartTransaction
Dim BT As Autodesk.AutoCAD.DatabaseServices.BlockTable
BT = CT.GetObject(DB.BlockTableId, OpenMode.ForRead)
Dim CurrentSpace As Autodesk.AutoCAD.DatabaseServices.BlockTableRecord
Try
CurrentSpace = CT.GetObject(BT(DB.CurrentSpaceId), OpenMode.ForRead)
MsgBox(CurrentSpace.Name)

Catch ex As Exception
MsgBox("Error: " & ex.Message)
CT.Dispose()
End Try
End Sub
End Class

But this produces an error on line:

CurrentSpace = CT.GetObject(BT(DB.CurrentSpaceId), OpenMode.ForRead)

Error: Value of type '... ObjectID' cannot be converted to string

Thanks for the help,
Kevin.

[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]

ntaylor
2006-01-26, 09:38 PM
Has DB.CurrentSpaceId got a ToString method?

Regards - Nathan

KevinBarnett
2006-01-27, 06:13 AM
Yes it does, but when you use it you get another error message:

eKey not found

I'm hoping that 2007 is released soon and is distributed with lots of VB.Net samples like supplied with the VBA help files. At the moment I'm just lost in acad's dotnet - anybody know of any really good books?