.NET

Reply
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 1 of 6 (103 Views)

Event for changing between modelspace and paperspace in a layout

103 Views, 5 Replies
03-27-2006 11:53 PM
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
Distinguished Contributor
ChrisArps
Posts: 311
Registered: ‎07-29-2004
Message 2 of 6 (103 Views)

Re: Event for changing between modelspace and paperspace in a layout

03-29-2006 06:23 AM in reply to: RolandF
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
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 3 of 6 (103 Views)

Re: Event for changing between modelspace and paperspace in a layout

03-30-2006 12:20 AM in reply to: RolandF
Thank you for your reply, i thought that i have to do it like this :-(

--
Roland Feletic
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 4 of 6 (103 Views)

Re: Event for changing between modelspace and paperspace in a layout

03-30-2006 09:07 AM in reply to: RolandF
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]
*Tony Tanzillo
Message 5 of 6 (103 Views)

Re: Event for changing between modelspace and paperspace in a layout

03-30-2006 10:58 AM in reply to: RolandF
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]
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 6 of 6 (103 Views)

Re: Event for changing between modelspace and paperspace in a layout

03-30-2006 01:21 PM in reply to: RolandF
I knew there must be a better way to check this.

Thanks Tony

C

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community