Author Topic: Using Editor.SelectCrossingWindow in paper space  (Read 1427 times)

0 Members and 1 Guest are viewing this topic.

Randy Richardson

  • Guest
Using Editor.SelectCrossingWindow in paper space
« on: October 05, 2011, 02:18:02 PM »
So what's the secret to using SelectCrossingWindow in paper space?

The current layout is "Layout1."   The entities I want to find are visible on the screen.  When I use SelectCrossingWindow, only entities in model space are found.

When I filter for entities in "Layout1" it doesn't find any entities at all.

So is it possible to use SelectCrossingWindow in paper space?

Thanks,

Randy Richardson
Hattiesburg, MS

Jeff H

  • Needs a day job
  • Posts: 6035
Re: Using Editor.SelectCrossingWindow in paper space
« Reply #1 on: October 05, 2011, 07:54:37 PM »
Works fine for me,
Using a SelectCrossingWindow and change each entity to red.
Code: [Select]
        [CommandMethod("PaperSpaceCrossingWindow")]
        public void PaperSpaceCrossingWindow()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor; 
       
            using (Transaction trx = db.TransactionManager.StartTransaction())
            {
                BlockTable blocktable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord currentSpace = trx.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
             
                if (currentSpace.ObjectId == blocktable[BlockTableRecord.ModelSpace])
                {
                    Application.ShowAlertDialog("Use a paer space layout");
                    return;
                }
                //// Note using db.Extmin & db.Extmax uses extents of model space not current space extents
                PromptSelectionResult psr = ed.SelectCrossingWindow(db.Extmin, db.Extmax);
                ed.WriteMessage("\n" + db.Extmin.ToString() + "  " + db.Extmax.ToString());
                foreach (ObjectId objId in psr.Value.GetObjectIds())
                {
                    Entity ent = (Entity)trx.GetObject(objId, OpenMode.ForWrite);
                    ent.ColorIndex = 1;
                }
                trx.Commit();
            }
        }

In pic below the circles are drawn in ModelSpace and the rest are in paperspace(rectangle is the viewport)
 

Randy Richardson

  • Guest
Re: Using Editor.SelectCrossingWindow in paper space
« Reply #2 on: October 06, 2011, 09:50:58 AM »
Jeff,

Thank you.  Your code works for me too.  Now I'm trying to figure out how yours is different from mine.  If I figure it out, I'll come back here and explain it (provided it's not such a stupid error that I would be too embarrassed to show my face again).

Randy Richardson
Hattiesburg, MS

Randy Richardson

  • Guest
Re: Using Editor.SelectCrossingWindow in paper space
« Reply #3 on: October 06, 2011, 01:37:05 PM »
I'm a little closer to the answer, but I'm not there yet.

At different points in the program, I check two values.

The name of the layout tab I get doing this: acadApp.GetSystemVariable("ctab")

The id number of the the current Space I get doing this: db.CurrentSpaceId

Although I ultimately have the same problem regardless of whether I start the program in model space in paper space, if I start the program in model space I get these results:

layout tab name: "Model"
current space id: 2129362168

After the program changes the tab to Layout1 my results change to:

layout tab name: "Layout1"
current space id: 2129362240

When the program gets to the part where it utilizes SelectCrossingWindow my results are:

layout tab name: "Layout1"
current space id: 2129362168

So now I have to figure out why the current space id reverts back to the model space id without the tab changing.

If anyone knows off the top of their heads why this might happen, I'd appreciate your letting me know.

Randy Richardson

  • Guest
Re: Using Editor.SelectCrossingWindow in paper space
« Reply #4 on: October 06, 2011, 05:18:00 PM »
Well in retrospect it does seem rather stupid.

I'd thought that if the tab was on "Layout1" that meant the environment was paper space.  But there had been a call to the "mspace" command.  Yeesh.  Fixed it with a call to the "pspace" command.  Whew.