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 ]
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 ]