Results 1 to 3 of 3

Thread: Current space using VB.Net ?

  1. #1
    100 Club KevinBarnett's Avatar
    Join Date
    2001-10
    Location
    Pretoria, South Africa
    Posts
    119
    Login to Give a bone
    0

    Question Current space using VB.Net ?

    Greetings,

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

    Code:
    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:

    Code:
    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... [ Moderator Action = OFF ]
    Last edited by Opie; 2006-01-26 at 02:17 PM. Reason: [quote] and [code] tags added

  2. #2
    100 Club
    Join Date
    2000-11
    Location
    Adelaide, South Australia
    Posts
    116
    Login to Give a bone
    0

    Default Re: Current space using VB.Net ?

    Has DB.CurrentSpaceId got a ToString method?

    Regards - Nathan

  3. #3
    100 Club KevinBarnett's Avatar
    Join Date
    2001-10
    Location
    Pretoria, South Africa
    Posts
    119
    Login to Give a bone
    0

    Default Re: Current space using VB.Net ?

    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?

Similar Threads

  1. Station tic color seems to be dependent on current layer in paper space
    By myork.194843 in forum AutoCAD Civil 3D - Alignments
    Replies: 3
    Last Post: 2009-06-22, 06:49 PM
  2. Edit attribute blocks regardless of current space
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2006-11-08, 12:33 PM
  3. Objects not in current space - what does that mean?
    By neilcheshire in forum AutoCAD LT - General
    Replies: 11
    Last Post: 2006-10-13, 11:38 AM
  4. block count only in current space/layout
    By VBOYAJI in forum AutoLISP
    Replies: 25
    Last Post: 2006-07-07, 05:40 PM
  5. Objects not in current space
    By ronparel in forum AutoCAD General
    Replies: 1
    Last Post: 2004-12-25, 03:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •