Author Topic: Last group in drawing  (Read 9579 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Last group in drawing
« on: September 23, 2009, 04:53:07 PM »
Hello,
This is my first post here at the swamp.
Some of you already know me from the Autodesk discussion groups.

I have about 20 years AutoCAD experience and almost that long at AutoLisp and more lately, Vlisp.
Been playing around with C# for a couple of years but more seriously this last year.
I'm pretty much self taught and have become the head of our CAD dept mostly because I've outlasted everybody else.
My platform is pretty outdated as we are using AcadR16 and while I have WinXP there are still some on Win2K.
This limits me to VS2005 ex and net 2.0. This may change as time goes on.

Right now I have basically one Program in C#, it's a net loadable .dll that displays a modeless form.
It's loaded at startup and stays up all day as my close is overridden to just Visibility status.
When a drawing is opened, the programs fills a listview with the names of existing part groups in the drawing.
If we make a new group, consisiting of lines, circles & arcs, the program adds the current date into the description field.
The listview is single select and the highlighted item causes the program to look for a matching part file of same name.
If found it displays the last date modified of the file and displays that and the dwgpreview bitmap as part of the listview item.
There are other features I haven't mentioned related to finding groups, copying etc.

I would really like to make it so that when you open a drawing in Autocad, the program can find the last group made in the dwg
and show that as the selected item in the listview. We had another program like this that used blocks and that was easy
because blocks are in the order they're made in the block table, but groups seem to be sorted by name in the dictionary that owns them.
I've thought about p/invokeing acdbEntLast() but not sure if that would work.

Any ideas on how to find the last group created in a drawing?









Glenn R

  • Guest
Re: Last group in drawing
« Reply #1 on: September 23, 2009, 05:00:56 PM »
...because blocks are in the order they're made in the block table...

Hmmm...that's news to me. Blocks appear in the block table according to name ie. alphabetical as far as I'm aware...

Having said that, unless you tag a GROUP with creation date/time, I know of no way to find the last one created.

BillZndl

  • Guest
Re: Last group in drawing
« Reply #2 on: September 24, 2009, 06:50:59 AM »
...because blocks are in the order they're made in the block table...
Hmmm...that's news to me. Blocks appear in the block table according to name ie. alphabetical as far as I'm aware...

I shouldn't say "in order of creation" because I haven't checked that theory out completely
but when I iterate the blocktable collection,
the blocktablerecords certainly are not "sorted" (at least not by name) when I print them to the screen:

 BlkNam: 10700

 BlkNam: 10693

 BlkNam: 10627-

 BlkNam: 10765

 BlkNam: 10766

 BlkNam: 86172

 BlkNam: 10608

 BlkNam: 10088

 BlkNam: 10759

 BlkNam: 10761

 BlkNam: 10760

 BlkNam: 10758

 BlkNam: 10776

 BlkNam: 10777

 BlkNam: 10762

 BlkNam: 10751

 BlkNam: 10736

 BlkNam: 10626-

 BlkNam: 10755-

 BlkNam: 10833

 BlkNam: 10832

 BlkNam: uph

 BlkNam: TAG

 BlkNam: ASM

 BlkNam: 10614-10

 BlkNam: 10777-10

Quote from: Glen R
Having said that, unless you tag a GROUP with creation date/time, I know of no way to find the last one created.

Hmm, bummer.
Oh well, probably more work than it's worth,
the users wouldn't necessarily be working on the last group created anyway,
just an idea.

Thanks!





David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Last group in drawing
« Reply #3 on: September 24, 2009, 09:57:28 AM »
welcome to the swamp
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

sinc

  • Guest
Re: Last group in drawing
« Reply #4 on: September 24, 2009, 12:11:44 PM »
You can always just watch for whenever the user creates a new group, then store that name somewhere, such as in the Named Object Dictionary.

BillZndl

  • Guest
Re: Last group in drawing
« Reply #5 on: September 24, 2009, 12:54:40 PM »
You can always just watch for whenever the user creates a new group, then store that name somewhere, such as in the Named Object Dictionary.

That would probably be the easiest.

I already watch for new groups so the date created gets added to the description field.
I suppose If I added a "time" to that field..... be nice if there was another "Tag" field for GROUPS.

I'm up to my ears in alligators right now (no pun intended) so I'll have to look into this more when time permits.
Again, this is my "spare time" project but I'll be checking in on this post now & then for more input.

Thanks to all for the warm welcome!   :-D







BillZndl

  • Guest
Re: Last group in drawing
« Reply #6 on: September 28, 2009, 11:34:33 AM »
Another question, same app.

I have a button that, "onClick", opens the native AutoCAD "Group:" dialog box using a static method.

private void button6_Click(object sender, EventArgs e)
        {
            if (Autodesk.AutoCAD.ApplicationServices.Application.IsQuiescent)
            {
                base.Enabled = false;
                OpenGroupCommandDialog.CallGroupCommand();
            }
        }

As you can see, I am using base.Enabled = false;
this is to prevent the user from interaction with the modeless form,
until they do whatever with the group command dialog.

In my CommandEnded, CommandCancelled and CommandFailed handlers,
I use base.Enabled = true; to bring the modeless form back to life.

void document_CommandEnded(object sender, CommandEventArgs e)
        {
            base.Enabled = true;
        }

For some reason, if I open the group dialog, then just rename a group and hit okay,
the group dialog closes but the main modeless form remains dead.

Is there a better way to prevent working with the modeless form
while another dialog is up or if another command is running?

TIA

Bill


BillZndl

  • Guest
Re: Last group in drawing
« Reply #7 on: September 28, 2009, 12:48:32 PM »
I uploaded an image of my app, thought it might help others visualize what I'm talking about.


BillZndl

  • Guest
Re: Last group in drawing
« Reply #8 on: September 29, 2009, 07:24:26 AM »
Hmm, well wouldn't you know,
This morning, everything works fine.   
I am no longer getting the "lock up" behavior when I use rename inside the group dialog.  8-)

Also I added base.Enabled = true; to the drawing activated handlers in case it happens again,
opening another drawing or reopening the current drawing will reset the form.
I don't like that for a solution but it's better than being "locked up" for the session.

Still undecided on what/if to do for last group in drawing
but everything in this project is working about the way we originally set goals for it,
so we're good to go (until I think of something else  :roll: ).

Thanks all.














hermanm

  • Guest
Re: Last group in drawing
« Reply #9 on: September 30, 2009, 11:19:43 PM »
Bill -

Did you catch Tony T's post on a.a.c.dotnet 9/30?

BillZndl

  • Guest
Re: Last group in drawing
« Reply #10 on: October 01, 2009, 06:47:39 AM »
Bill -
Did you catch Tony T's post on a.a.c.dotnet 9/30?

Yes, my only trouble is, I am still on net 2.0 and don't have "using System.Linq;" in my resources,
so I can't test until something else happens around here. :(




BillZndl

  • Guest
Re: Last group in drawing
« Reply #11 on: October 01, 2009, 07:43:59 AM »
Wait, I found System.Linq under the System core dll.

Stay turned.


BillZndl

  • Guest
Re: Last group in drawing
« Reply #12 on: October 01, 2009, 09:22:54 AM »
Nope, need VS2008.

You can target 2.0 but you have to add an extension attribute for the compiler.

I could try using VS2008 with a 2.0 target and see if it will run on Win2000 machines.
I'll see if I get time.  :|


BillZndl

  • Guest
Re: Last group in drawing
« Reply #13 on: October 01, 2009, 02:03:50 PM »
It's just kind of a hack but it seems to work.
Just using the default comparer for the sort.
Needs more testing:

Code: [Select]
public string GetLastHandle (ObjectIdCollection ids)
       {
          // return the element with the numerically largest handle: ??
           
           List<string> list = new List<string>();

           foreach (ObjectId id in ids)
           {
               list.Add(id.Handle.ToString());               
           }
           
           list.Sort();           

           return list[list.Count - 1];
       }


BillZndl

  • Guest
Re: Last group in drawing
« Reply #14 on: October 05, 2009, 07:25:01 AM »
It's just kind of a hack but it seems to work.
Just using the default comparer for the sort.
Needs more testing:

Nope, didn't work.
Was sorting alpha numerically.

Ended up using a sorted list with the handle Value as the key for sorting.
Limited testing shows success.
FWIW:
Code: [Select]
public string GetLastHandle (ObjectIdCollection ids)
       {           
           // return the element with the numerically largest handle:
                   
           SortedList solst = new SortedList();
           
           foreach (ObjectId id in ids)
           {               
               solst.Add(id.Handle.Value, id.Handle);
               
           }           

           IList Vals = solst.GetValueList();       
           
           return Vals[Vals.Count - 1].ToString();
       }