Author Topic: Regular Expressions  (Read 5350 times)

0 Members and 1 Guest are viewing this topic.

HD

  • Guest
Regular Expressions
« on: December 21, 2007, 10:12:09 AM »
Hello,

Does anyone know of a regular expression or wildcard technique that could be used in the snippet below? Where, X is: A, B, C, D, E, or E1

Code: [Select]
BlockTableRecord btr =
     tr.GetObject(bt["BORDER-X"],
     OpenMode.ForRead, false) as BlockTableRecord;


sinc

  • Guest
Re: Regular Expressions
« Reply #1 on: December 21, 2007, 10:15:19 AM »
I don't think you can do that.

I think you need to walk the entire Block table, and compare the name of each block in the table to your regex, keeping a collection of the blocks that match.

Glenn R

  • Guest
Re: Regular Expressions
« Reply #2 on: December 21, 2007, 10:16:59 AM »
Yep - what sinc said because of AutoCAD's transactional nature (open/close).

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8764
  • AKA Daniel
Re: Regular Expressions
« Reply #3 on: December 21, 2007, 10:25:41 AM »
What about a selection set? Or maybe you should ignore me  :oops:

sinc

  • Guest
Re: Regular Expressions
« Reply #4 on: December 21, 2007, 09:12:28 PM »
What about a selection set? Or maybe you should ignore me  :oops:

I don't think there's any way of using a selection set to search a block table.

If you want to use something like Editor.SelectAll(), then a selection filter would work for that.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8764
  • AKA Daniel
Re: Regular Expressions
« Reply #5 on: December 21, 2007, 10:37:11 PM »
What about a selection set? Or maybe you should ignore me  :oops:

I don't think there's any way of using a selection set to search a block table.

If you want to use something like Editor.SelectAll(), then a selection filter would work for that.


Yes, that’s what I had in mind. Maybe something like this

Code: [Select]
     [CommandMethod("test")]
      static public void test()
      {
        Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

        //filter
        TypedValue[] values = new TypedValue[]
                     {
                        new TypedValue((short)DxfCode.BlockName, "BORDER-*") ,
                     };

        SelectionFilter filter = new SelectionFilter(values);
        PromptSelectionResult result = ed.SelectAll(filter);

        if (result.Status == PromptStatus.OK)
        {

          ObjectId[] idarray = result.Value.GetObjectIds();
          DBObjectCollection dbobjects = new DBObjectCollection();

          AcDb.TransactionManager tm =
          Application.DocumentManager.MdiActiveDocument.Database.TransactionManager;

          Transaction tr = tm.StartTransaction();
          try
          {

            //do something
            foreach (ObjectId id1 in idarray)
            {
              dbobjects.Add(tr.GetObject(id1, OpenMode.ForRead, true));
            }

            tr.Commit();

            ed.WriteMessage(dbobjects.Count.ToString());
          }
          catch (System.Exception ex)
          {
            ed.WriteMessage(ex.Message);
          }
          finally
          {
            tr.Dispose();
          }
        }
      }
    }

Fatty

  • Guest
Re: Regular Expressions
« Reply #6 on: December 22, 2007, 05:45:10 AM »
Just a thoughts..
Keep in mind the dynamicblocks,
they will be use now very often  ;-)

~'J'~

sinc

  • Guest
Re: Regular Expressions
« Reply #7 on: December 22, 2007, 09:44:26 AM »
Just a thoughts..
Keep in mind the dynamicblocks,
they will be use now very often  ;-)

What about them?

sinc

  • Guest
Re: Regular Expressions
« Reply #8 on: December 22, 2007, 09:46:04 AM »
What about a selection set? Or maybe you should ignore me  :oops:

I don't think there's any way of using a selection set to search a block table.

If you want to use something like Editor.SelectAll(), then a selection filter would work for that.


Yes, that’s what I had in mind. Maybe something like this


Just keep in mind that when you use things like Editor.SelectAll(), the selection set is automatically filtered on the current space (modelspace or paperspace).  So it is not necessarily the same thing as searching a block table.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8764
  • AKA Daniel
Re: Regular Expressions
« Reply #9 on: December 22, 2007, 10:00:07 AM »
Hi Sinc,

According to the docs, it searches the whole database, as in
acedSSGet("_X",NULL,NULL,NULL,ss) but Maybe I missed somthing.

sinc

  • Guest
Re: Regular Expressions
« Reply #10 on: December 22, 2007, 10:32:31 AM »
Where did you see that?

All I saw was that it "selects all items from the screen", which implies that it filters on the currently-active space.

It's a simple enough thing to test, though, by writing a little test program.  I actually find myself doing that a lot, because the developer documentation is so sparse in so many areas.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8764
  • AKA Daniel
Re: Regular Expressions
« Reply #11 on: December 22, 2007, 10:45:28 AM »
Where did you see that?

All I saw was that it "selects all items from the screen", which implies that it filters on the currently-active space.

It's a simple enough thing to test, though, by writing a little test program.  I actually find myself doing that a lot, because the developer documentation is so sparse in so many areas.

It’s in the Arx (07) docs; specifically, AutoCAD managed class reference.
I do agree the docs are sparse. I have found it very useful to looks at the unmanaged docs just to see if there’s more info.
« Last Edit: December 22, 2007, 11:01:57 AM by Daniel »

Fatty

  • Guest
Re: Regular Expressions
« Reply #12 on: December 22, 2007, 04:19:37 PM »
Just a thoughts..
Keep in mind the dynamicblocks,
they will be use now very often  ;-)

What about them?

Here is a part of one of my programm
that is not finished yet
Give this a try

~'J'~

Fatty

  • Guest
Re: Regular Expressions
« Reply #13 on: December 23, 2007, 02:45:30 PM »
Hello,

Does anyone know of a regular expression or wildcard technique that could be used in the snippet below? Where, X is: A, B, C, D, E, or E1

Code: [Select]
BlockTableRecord btr =
     tr.GetObject(bt["BORDER-X"],
     OpenMode.ForRead, false) as BlockTableRecord;



You can try this filter for selection:

Code: [Select]
"BORDER-[A-E],BORDER-[E#]*"
or this one:

Code: [Select]
"BORDER-[A-E],BORDER-E1"
~'J'~