Author Topic: How to use editor.SelectCrossingWindow?  (Read 8293 times)

0 Members and 1 Guest are viewing this topic.

teslaxx

  • Guest
How to use editor.SelectCrossingWindow?
« on: January 12, 2011, 02:26:31 AM »
If I select entity, how can I define those 2 points in order to get the entity using SelectCrossingWindow?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to use editor.SelectCrossingWindow?
« Reply #1 on: January 12, 2011, 02:59:00 AM »
I don't really understand your meaning with
Quote
If I select entity .. < snip >


perhaps something like :
Code: [Select]
       [CommandMethod("sel23")]
        public void SelectCrossingWindow_23()
        {
            Document doc = acApp.DocumentManager.MdiActiveDocument;
            Point3d p1 = new Point3d(0.0, 0.0, 0.0);
            Point3d p2 = new Point3d(5.0, 5.0, 0.0);
            PromptSelectionResult psr = doc.Editor.SelectCrossingWindow(p1, p2);
            if (psr.Status == PromptStatus.OK)
            {
                MessageBox.Show(psr.ToString(), "SelectCrossingWindow");              
            }
        }
« Last Edit: January 12, 2011, 03:37:08 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

kaefer

  • Guest
Re: How to use editor.SelectCrossingWindow?
« Reply #2 on: January 12, 2011, 03:02:22 AM »
If I select entity, how can I define those 2 points in order to get the entity using SelectCrossingWindow?

The official example based on two fixed points is found here, second from top: http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/files/WS1a9193826455f5ff-3859b43c1209703a838778b.htm

If that's not what you mean, please clarify your question.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to use editor.SelectCrossingWindow?
« Reply #3 on: January 12, 2011, 03:02:42 AM »
Returns this  ( 3 objects in crossing zone )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to use editor.SelectCrossingWindow?
« Reply #4 on: January 12, 2011, 03:36:39 AM »

and iterating the selection Set
Code: [Select]

        [CommandMethod("sel24")]
        public void SelectCrossingWindow_24()
        {
            Document doc = acApp.DocumentManager.MdiActiveDocument;
            Point3d p1 = new Point3d(0.0, 0.0, 0.0);
            Point3d p2 = new Point3d(50.0, 50.0, 0.0);
            PromptSelectionResult psr = doc.Editor.SelectCrossingWindow(p1, p2);
            if(psr.Status == PromptStatus.OK) {
                int cnt = 0;
                using(doc.TransactionManager.StartTransaction()) {
                    foreach(ObjectId oID in psr.Value.GetObjectIds()) {
                        Entity ent = (Entity)oID.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);
                        cnt += 1;
                        MessageBox.Show(ent.ToString(), "SelectCrossingWindow Entity  " + cnt.ToString());
                    }
                }
            }
        }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

teslaxx

  • Guest
Re: How to use editor.SelectCrossingWindow?
« Reply #5 on: January 12, 2011, 03:44:06 AM »
I select a block, I explode the block and after that I want to use the SelectCrossingWindow() method for every element of the block, in order to get the entities which intersect the current entity, by using IntersectWith() method.
The other way in which I did this routine, it was by simpling getting all the objects in my drawing and see if those entities intersect by block elements. The problems in this situation is that I must stay at least 5 min for every running of the routine.


Code: [Select]
[CommandMethod("mymeth")]
        public static void KLM()
        {

            // Get the current document and database

            Document document = Application.DocumentManager.MdiActiveDocument;
            Database database = document.Database;
            
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {

                // Open the Block table for read
                BlockTable blockTable = transaction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord blockTableRecord = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                PromptSelectionResult promptSelectionResult = Helper.chooseEntities("choose", document);
                DBObjectCollection dBObjectCollection = new DBObjectCollection();


                // If the prompt status is OK, objects were selected
                Entity axDesen;

                if (promptSelectionResult.Status == PromptStatus.OK)
                {
                    SelectionSet selectionSet = promptSelectionResult.Value;

                    // Step through the objects in the selection set
                    //DBDictionary databaseDictionary = database.LayoutDictionaryId.GetObject(OpenMode.ForRead) as DBDictionary;

                    axDesen = transaction.GetObject(selectionSet[0].ObjectId, OpenMode.ForWrite) as Entity;
                    if (axDesen is BlockReference)
                    {
                        axDesen.Explode(dBObjectCollection);
                        foreach (Entity elementAx in dBObjectCollection)
                        {
                            if (!elementAx.GetType().Name.Equals("Circle"))
                            {
                                structuraAx.Add(elementAx);
                            }
                        }
                    }
                    else
                    {
                        Application.ShowAlertDialog("Bye!");
                        return;
                    }
                }
                else
                {
                    return;
                }

// here, using a foreach loop I want to use the SelectCrossingWindow for every element of structuraAx


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to use editor.SelectCrossingWindow?
« Reply #6 on: January 12, 2011, 03:48:49 AM »
Is there a question to go with that code?

What is this ??
Helper.chooseEntities( )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

teslaxx

  • Guest
Re: How to use editor.SelectCrossingWindow?
« Reply #7 on: January 12, 2011, 04:12:44 AM »
I select a block, I explode the block and after that I want to use the SelectCrossingWindow() method for every element of the block, in order to get the entities which intersect the current entity, by using IntersectWith() method. In my original form I was simpling getting all the objects in my drawing and see if those entities intersect the block elements. The problems in this situation is that I must stay at least 5 min for every running of the routine.


By using Helper.chooseEntities("choose", document);
Code: [Select]
public static PromptSelectionResult chooseEntities(string mesaj, Document document)
        {
            PromptSelectionOptions promptSelectionOptions = new PromptSelectionOptions();
            promptSelectionOptions.MessageForAdding = mesaj;
            PromptSelectionResult promptSelectionResult = document.Editor.GetSelection(promptSelectionOptions);
            return promptSelectionResult;
            /*if (promptSelectionResult.Status == PromptStatus.OK)
            {
                return promptSelectionResult;
            }
            else
            {
                return null;
            }*/
        }

So, I want to use the SelectCrossingWindow() method for every element of the block, in order to get the entities which intersect the current entity, by using IntersectWith() method.
« Last Edit: January 12, 2011, 04:23:28 AM by teslaxx »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to use editor.SelectCrossingWindow?
« Reply #8 on: January 12, 2011, 04:23:31 AM »

I don't understand this statement

Quote
I want to use the SelectCrossingWindow() method for every element of the block

care to explain why and how you propose using this method.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to use editor.SelectCrossingWindow?
« Reply #9 on: January 12, 2011, 04:39:38 AM »
Kerry,

I think the OP is trying to use your example from http://www.theswamp.org/index.php?topic=36317.0

teslaxx,

Instead of trying to force a certain way to work, explain what you are trying to accomplish and someone will be happy to help you.

teslaxx

  • Guest
Re: How to use editor.SelectCrossingWindow?
« Reply #10 on: January 12, 2011, 04:55:01 AM »
AHHHHHH

Maybe, should I explain this way:
I have an entity. For that entity, there is an rectangle, in which I could put my entity. The boundaries of my entity is limited by the shape of this rectangle. How can I get those 2 points which could define this rectangle.



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to use editor.SelectCrossingWindow?
« Reply #11 on: January 12, 2011, 04:59:22 AM »
So to translate that, * I'm guessing )

You want to find the  corners of a rectangular that encloses your block??

If that is correct, why do you want to do that ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to use editor.SelectCrossingWindow?
« Reply #12 on: January 12, 2011, 05:07:44 AM »
This should draw a rectangle around an entity
Never mind the com objects I was being lazy

GeometricExtents.MinPoint
GeometricExtents.MaxPoint


Code: [Select]
           
            [CommandMethod("BoundBox")]
        public void BoundBox()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityResult per = ed.GetEntity("Select a Entity\n");
            if (per.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {     
                    Entity ent = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Entity;
                    Point3d min = ent.GeometricExtents.MinPoint;
                    Point3d max = ent.GeometricExtents.MaxPoint;

                    AcadDocument acadDoc = (AcadDocument)doc.AcadDocument;
                    acadDoc.SendCommand("rec " + min.X + "," + min.Y + " " + max.X + "," + max.Y + " ");
                    ed.WriteMessage("\n Min: " + min.ToString() + "\n Max: " + max.ToString());
                     
                       
                    tr.Commit();
                }
            }           
        }   

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to use editor.SelectCrossingWindow?
« Reply #13 on: January 12, 2011, 05:21:27 AM »
Jeff ,
Yes, that will provide the corners that bound the selected entity.


...  are we sure of that is what the OP thinks he wants wants. ?

... and more importantly, is that what he needs ??

//---------------------


These are the reasons why I'm trying to get the OP to define his problem in terms that are complete and understandable.

for instance, if the intent is to determine the rectangle bounding a block,
then explode the block,
then do a crossing window using the rectangle to determine the entities in the block,

.. it won't work as the OP expects because ALL entities inside the rectangle will be selected,
not just the entities from the block.


//---------------

further.

Is the intent to leave the block exploded ?
what further action will be required with the entities ?
plus several other questions depending on the answers.
//---------------

In short.
The best way to get the  most suitable answer to questions is to ask the the correct questions.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to use editor.SelectCrossingWindow?
« Reply #14 on: January 12, 2011, 05:45:55 AM »

...  are we sure of that is what the OP thinks he wants wants. ?

... and more importantly, is that what he needs ??

No Sir

The best way to get the  most suitable answer to questions is to ask the the correct questions.


Yes Sir