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

Filter Block Selection By X,Y Coordinates

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
ChrisBatt
2117 Views, 4 Replies

Filter Block Selection By X,Y Coordinates

Hello,

 

I'm trying to select two specific types of blocks from a drawing so that I can create layouts for each one of the pairs of blocks in my drawing.  Basically, one block is the outline of the piece of the drawing and the second contains information about the drawing.  I would like to select all of the outline blocks and then create a selection to get the second block which is inside the bounds of the first block.  I'm not sure how to create a set of typed values to do this.  Here is my code so far which sets up a filter to get the first block and then for each of the blocks that it finds, it would select the block with all of the information which is where I am having problems.  I don't know how to create a filter based upon location of the block.  Is this possible and does someone have an example?  Thanks for your help.

 

using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                {
                    filList = new TypedValue[] {
                        new TypedValue((int)DxfCode.Operator,"<and"),
                        new TypedValue((int)DxfCode.Start,"INSERT"),
                        new TypedValue((int)DxfCode.BlockName,"D-1*"),
                        new TypedValue((int)DxfCode.Operator,"and>")};

                    // Build a filter list so that only block references are selected
                    filter = new SelectionFilter(filList);
                    //Select all
                    res = ed.SelectAll(filter);
                    // Do nothing if selection is unsuccessful
                    if (res.Status != PromptStatus.OK)
                        return;
                    //pull information from the selected objects
                    idArray = res.Value.GetObjectIds();
                    //Create the block reference array
                    blkRef = new BlockReference[idArray.Length];
                    //Loop through each selected object and store its block reference
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        blkRef[i] = (BlockReference)tr.GetObject(idArray[i].ConvertToRedirectedId(), OpenMode.ForRead);
                    }


                    //LayoutManager lm = LayoutManager.Current;
                    for (int i = 0; i < blkRef.Length; i++)
                    {
                        filList = new TypedValue[] {
                        new TypedValue((int)DxfCode.Operator,"<and"),
                        new TypedValue((int)DxfCode.Start,"INSERT"),
                        new TypedValue((int)DxfCode.BlockName,"D-1*"),
                        //new TypedValue((int)DxfCode.XCoordinate),
                        //new TypedValue((int)DxfCode.Operator, ">="),
                        //new TypedValue((int)DxfCode.Real, blkRef[i].Bounds.Value.MinPoint.X),
                        //new TypedValue((int)DxfCode.XCoordinate),
                        //new TypedValue((int)DxfCode.Operator, "<="),
                        //new TypedValue((int)DxfCode.Real, blkRef[i].Bounds.Value.MaxPoint.X),
                        //new TypedValue((int)DxfCode.YCoordinate),
                        //new TypedValue((int)DxfCode.Operator, ">="),
                        //new TypedValue((int)DxfCode.Real, blkRef[i].Bounds.Value.MinPoint.Y),
                        //new TypedValue((int)DxfCode.YCoordinate),
                        //new TypedValue((int)DxfCode.Operator, "<="),
                        //new TypedValue((int)DxfCode.Real, blkRef[i].Bounds.Value.MaxPoint.Y),
                        new TypedValue((int)DxfCode.Operator,"and>")};

                        // Build a filter list so that only block references are selected
                        filter = new SelectionFilter(filList);
                        //Select all
                        res = ed.SelectAll(filter);
                        // Do nothing if selection is unsuccessful
                        if (res.Status != PromptStatus.OK)
                            return;
                        //pull information from the selected objects
                        idArray = res.Value.GetObjectIds();
                        //Create the block reference array
                        blkRefTB = new BlockReference[idArray.Length];
                        //Loop through each selected object and store its block reference
                        for (int j = 0; j < idArray.Length; j++)
                        {
                            blkRefTB[j] = (BlockReference)tr.GetObject(idArray[j].ConvertToRedirectedId(), OpenMode.ForRead);
                        }

                        
                    }

                    tr.Commit();
                }

 

4 REPLIES 4
Message 2 of 5

From ObjectARX Doc:

  • For point groups, the X, Y, and Z tests can be combined into a single string, with each separated by commas--for example, ">,>,*". If you omit an from the string (for example, "=,<>" leaves out the Z test), the "anything goes" "*" is assumed.
// [...]
new TypedValue((int)DxfCode.Operator,"<=,<=,*"),
new TypedValue((int)DxfCode.XCoordinate, MaxPoint,
new TypedValue((int)DxfCode.Operator,">=,>=,*"),
new TypedValue((int)DxfCode.XCoordinate, MinPoint),
// [...]

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 5

Thanks, this is exactly what I was looking for as a solution.  I just couldn't find something like this anywhere.  I appreciate it.

Message 4 of 5

This is very intersting. I learned something new here.

 

Would anyone know what exactly the below code is doing?

 

new TypedValue((int)DxfCode.Operator,"<=,<=,*"),
new TypedValue((int)DxfCode.XCoordinate, MaxPoint,
new TypedValue((int)DxfCode.Operator,">=,>=,*"),
new TypedValue((int)DxfCode.XCoordinate, MinPoint),
// [...]

 

My guess is as follows: it basically is used to help create a selection filter such that:

  • X values are less than the maxpoint, and greater than the minpoint.
  • Y values are less than the max point, and greater than the minpoint.
  • Z values can be anything 

Am i interpreting the above correctly?

 

 

chrs for your help.

Message 5 of 5

Yes.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

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