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

Event for changing between modelspace and paperspace in a layout

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
262 Views, 5 Replies

Event for changing between modelspace and paperspace in a layout

Is there an event for changing between mspace and pspace in a layout. I
could find an event for switching layouts but none for switching between
mspace and pspace. Do i have to use CommandEnded to do this?

--
Roland Feletic
5 REPLIES 5
Message 2 of 6
ChrisArps
in reply to: Anonymous

It looks like it, the PSPACE and MSPACE commands.

I have found that using the sample program "EventsWatcher" can be very helpful for chasing down event behavoir.

Chris Arps
Message 3 of 6
Anonymous
in reply to: Anonymous

Thank you for your reply, i thought that i have to do it like this 😞

--
Roland Feletic
Message 4 of 6
cgay
in reply to: Anonymous

The event for switching layouts is your best bet.
When you handle then event,
open the BlockTableRecord defined by the LayoutEventArgs.ID property
If you look at the name of the BlockTable record it will be either *Model_Space or *Paper_Space.
Interestingly enough, BlockTableRecord.ModelSpace is a static string that you could you to compare to, but for some reason, whenever I use it in code, AutoCAD crashes.

Well, I here is some code that was written to be added to the EventsWatcher Sample.

C

[code]
private void callback_LayoutSwitched(object sender, LayoutEventArgs e)
{
WriteLine(String.Format("LayoutSwitched - {0}", e.Name));
Autodesk.AutoCAD.ApplicationServices.TransactionManager tm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager;
Transaction tr = tm.StartTransaction();
try
{
DBObject dbO = tr.GetObject(e.Id, OpenMode.ForRead);
if (dbO is BlockTableRecord)
{
BlockTableRecord btr = (BlockTableRecord)dbO;
bool isModel = false;
isModel =(string.Compare(btr.Name.ToUpper , "*MODEL_SPACE"))==0;
WriteLine(String.Format("IsModelSpace - {0}", isModel));
}
tr.Commit();
}
catch (System.Exception ex)
{
tr.Abort ();
}
finally
{
tm.Dispose();
}


}
[/code]
Message 5 of 6
Anonymous
in reply to: Anonymous

You really don't need to go through all of that.

using Autodesk.AutoCAD.DatabaseServices;

public class MyUtils
{
static public bool IsModelSpaceBTR(ObjectId id)
{
return id == SymbolUtilityServices.GetBlockModelSpaceId(id.Database);
}
}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5127077@discussion.autodesk.com...
The event for switching layouts is your best bet.
When you handle then event,
open the BlockTableRecord defined by the LayoutEventArgs.ID property
If you look at the name of the BlockTable record it will be either *Model_Space or *Paper_Space.
Interestingly enough, BlockTableRecord.ModelSpace is a static string that you could you to compare to, but for some reason, whenever I use it in code, AutoCAD crashes.

Well, I here is some code that was written to be added to the EventsWatcher Sample.

C

[code]
private void callback_LayoutSwitched(object sender, LayoutEventArgs e)
{
WriteLine(String.Format("LayoutSwitched - {0}", e.Name));
Autodesk.AutoCAD.ApplicationServices.TransactionManager tm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager;
Transaction tr = tm.StartTransaction();
try
{
DBObject dbO = tr.GetObject(e.Id, OpenMode.ForRead);
if (dbO is BlockTableRecord)
{
BlockTableRecord btr = (BlockTableRecord)dbO;
bool isModel = false;
isModel =(string.Compare(btr.Name.ToUpper , "*MODEL_SPACE"))==0;
WriteLine(String.Format("IsModelSpace - {0}", isModel));
}
tr.Commit();
}
catch (System.Exception ex)
{
tr.Abort ();
}
finally
{
tm.Dispose();
}


}
[/code]
Message 6 of 6
cgay
in reply to: Anonymous

I knew there must be a better way to check this.

Thanks Tony

C

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