• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    ChrisBatt
    Posts: 12
    Registered: ‎11-21-2011
    Accepted Solution

    Filter Block Selection By X,Y Coordinates

    378 Views, 2 Replies
    05-17-2012 04:48 AM

    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();
                    }

     

    Please use plain text.
    Moderator
    Alexander.Rivilis
    Posts: 1,168
    Registered: ‎04-09-2008

    Re: Filter Block Selection By X,Y Coordinates

    05-17-2012 05:50 AM in reply to: ChrisBatt

    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),
    // [...]

    Пожалуйста не забывайте про Утвердить в качестве решения!Утвердить в качестве решения и Give Kudos!Баллы
    Please remember to Accept Solution!Accept as Solution and Give Kudos!Kudos

    Please use plain text.
    Contributor
    ChrisBatt
    Posts: 12
    Registered: ‎11-21-2011

    Re: Filter Block Selection By X,Y Coordinates

    05-17-2012 07:33 AM in reply to: Alexander.Rivilis

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

    Please use plain text.