.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Current space?

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
408 Views, 3 Replies

Current space?

How do you determine th current space using dotnet?
I'm looking for the equivalent VB dotnet code to this VBA code:

'VBA:
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

Thx.

Kevin.
3 REPLIES 3
Message 2 of 4
RonnieWilkins
in reply to: Anonymous

Autodesk.AutoCAD.DatabaseServices.Database.CurrentSpaceId

Rough outline:

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,ForRead)
Dim CurrentSpace as Autodesk.AutoCAD.DatabaseServices.BlockTableRecord

CurrentSpace = CT.GetObject(bt(DB.CurrentSpaceID),ForRead)
Ronnie Wilkins, Jr.
Message 3 of 4
Anonymous
in reply to: Anonymous

Thanks, but...

When I try to build the code you sent I get an error on this line:
CurrentSpace = CT.GetObject(bt(DB.CurrentSpaceID,ForRead)

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

db.currentspaceid being underlined in the code

Also, will this get to the property I am looking for? The program I am about to write needs to know which space is active in the current drawing - is it model space, paper space (a layout) or model space within a paper space viewport. That was achieved via properties of the current document in VBA.

Thanks for your help.
Message 4 of 4
kwecker
in reply to: Anonymous

For anyone else that stumbles upon this page looking for inserting on the current layout, this worked for me in any layout or model space. I use C# for my apps.

BlockTableRecord btr = (BlockTableRecord)tm.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost