Author Topic: Objects Outside Rectangular Blockreference--(Stop Drawing Outside Title Block)  (Read 1916 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Are there any gotcha's I am missing,

I did not check rotation----need that added
There is no checking if block is inserted----needs to be added

It is assumed that the outermost entity in block is a rectangle

Basiclly it gets the block's Geometric extents and passes that into Editor.SelectWindow() then compares the number objects selected with the total objects in that space.
If it is in modelspace the counter starts at 0 if it is in paperspace it starts at -1 to count for extra viewport.

Code is for basic testing not production
Code: [Select]
        [CommandMethod("CheckTB")]
        public void CheckTB()
        {

            Document doc = Application.DocumentManager.MdiActiveDocument;//Assign the Current Document to doc
            Database db = doc.Database;// Assign doc's(Current Active Document) database to db
            Editor ed = doc.Editor;// Assign Editor to doc

            Point3d minPoint = Point3d.Origin;
            Point3d maxPoint = Point3d.Origin;


            //number of total objects and set to negative 1 to count for extra viewport
            int numberOfObjects = -1;

            using (Transaction trx = db.TransactionManager.StartTransaction())// Start Transaction
            {
                BlockTable blocktable = trx.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;//Assign BlockTable
                     
                BlockTableRecord currentSpace = trx.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;
               
                // If modelSpace do not need to have extra number for viewport
                if (currentSpace.ObjectId == blocktable[BlockTableRecord.ModelSpace])
                {
                    numberOfObjects++;
                }

                BlockTableRecord titleBlock = blocktable["TB"].GetObject(OpenMode.ForRead) as BlockTableRecord;

                // Iterate all the entites in the current space
                foreach (ObjectId objId in currentSpace)
                {
                    numberOfObjects++;// add 1 to running total
                    if (!(objId.ObjectClass.Name == "AcDbBlockReference"))// If not a BlockReference then skip it 
                    {
                        continue;
                    }

                    BlockReference blockreference = trx.GetObject(objId, OpenMode.ForRead) as BlockReference;

                    if (blockreference.BlockTableRecord == titleBlock.ObjectId)
                    {
                        maxPoint = blockreference.GeometricExtents.MaxPoint;
                        minPoint = blockreference.GeometricExtents.MinPoint;                 
                    }             
                                                             
                }

               
                PromptSelectionResult psr = ed.SelectWindow(minPoint, maxPoint);
               

                if (psr.Value.Count < numberOfObjects)
                {
Application.ShowAlertDialog(@"Why do you keep drawing outside the Title Block area?
I hope you understand I am logging this and when you reach
a certain number, instead of this message box
you will see Outlook open with a e-mail sent to the boss
explaining to him that you are uncapable of following simple directions.");
                }

                else
                {
                    Application.ShowAlertDialog(numberOfObjects.ToString());
                }

                 trx.Commit();

                }

                         
           


        }




n.yuan

  • Bull Frog
  • Posts: 348
One potential gotchya is that if the selecting window is not entirely visible in the current view.

Methods like Editor.SelectWindow()/SelectCorssingWindow()...all require the selecting polygon is defined within visible portion of the screen of current view, just line a user is manually picking the window/polygon. Otherwise the Ediotr may not return the all the entities enclosed by the window. So, you may want to zoom to a winodw which may be a slightly bigger than the selecting window before you call SelectWindow().

Also, the accuracy of the SelectWindows's window depeneds on the pixel of the screen/resolution, if the drawing limits is very big and you have to zoom out a lot, and there are entities very close to the selecting polygon, the returned selectionset may be different according to how far out you zoomed

Jeff H

  • Needs a day job
  • Posts: 6150
Thanks Norman,
Not much expirence with it and thanks for the pointers