Author Topic: Tool palette, Object selection and Event  (Read 23879 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5241
Tool palette, Object selection and Event
« on: June 04, 2007, 02:32:21 PM »
I have written a tool palette that gets populated when the user invokes the command, and then selects a block.  It will update the block with the new information typed into its combo boxes.  What I'm looking to do is have it floating around, and then if I select a block (no command invoked) it will populate the tool palette without having to invoke the command again.  I can't seem to find how to do this in the help files or on the net, so any guidance is appreciated.

Thanks in advance.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #1 on: June 04, 2007, 02:49:54 PM »
This looks like the class I need to use
Quote
AcEdSSGetFilter Class
Now to see how to use it.  :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Tool palette, Object selection and Event
« Reply #2 on: June 04, 2007, 03:12:56 PM »
SelectionAddedEventHandler ?

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #3 on: June 04, 2007, 03:31:24 PM »
SelectionAddedEventHandler ?
Yes.  But there seems to be a problem.  It calls the event before it adds the objects, so I need to see about another way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #4 on: June 04, 2007, 03:36:48 PM »
My code seems to be crashing Acad with the second selection made.  I'm just drawing lines right now to test, as the code shouldn't do anything when selecting them.  I select a few, it shows the correct number of blocks (0).  Then I select again and get a fatal error.  Here is the code.
Code: [Select]
public void SelectionMade(object sender, SelectionAddedEventArgs e) {
ObjectId BlockId = ObjectId.Null;
BlockReference BlkRef = null;
int BlkCnt = 0;
SelectionSet ss = e.Selection;
using (Transaction Trans = AcadApp.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) {
for (int i = 0; i < ss.Count; ++i) {
BlkRef = Trans.GetObject(ss[i].ObjectId, OpenMode.ForRead) as BlockReference;
if (BlkRef != null) {
++BlkCnt;
BlockId = BlkRef.ObjectId;
}
}
}
MessageBox.Show(BlkCnt.ToString());
if (BlkCnt == 1) CreateControls(BlockId);
}
Any help is appreciated.  I'm off to see if I can find the answer.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Tool palette, Object selection and Event
« Reply #5 on: June 04, 2007, 03:54:20 PM »
i wrap the function with try{} catch{}

then, if i just want to select one

ObjectId[] ids = e.AddedObjects.GetObjectIds();
if (e.AddedObjects.Count == 1)
{
ObjectId objid = ids[0];               
Entity ename = (Entity)tr.GetObject(objid, OpenMode.ForRead);
BlockReference br = (BlockReference)ename;
if (ename is BlockReference)
{
 MessageBox.Show("Is one BLOCK...", "Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
e.Remove(0);
}
e.Remove(0);
tr.Commit();

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #6 on: June 04, 2007, 04:28:04 PM »
I put it in a try/catch, but it still doesn't work.  It seems like the objects, when being selected, are opened so that I can't do anything to them.  So I guess I have to have the selection event, put an object modified event on each object, and then after that object closed event (which I don't see one) will modify my tool palette.

Now to go back and look at how I did it in lisp.  :|
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Tool palette, Object selection and Event
« Reply #7 on: June 04, 2007, 04:33:22 PM »
I put it in a try/catch, but it still doesn't work.  It seems like the objects, when being selected, are opened so that I can't do anything to them.  So I guess I have to have the selection event, put an object modified event on each object, and then after that object closed event (which I don't see one) will modify my tool palette.

Now to go back and look at how I did it in lisp.  :|

i only have done very little with events in c#, and basically just to read data from blocks(doors) and pass it to a dialog, nothing about to modify...

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #8 on: June 04, 2007, 04:35:35 PM »
This is very frustrating.  I tried using the CommandEnded event (like I did in Lisp) didn't work.  Then I tried using the ObjectModified event, didn't work.

Maybe after lunch an idea that will work will pop into my head.  Thanks for trying Luis.  It is appreciated.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Tool palette, Object selection and Event
« Reply #9 on: June 04, 2007, 04:42:20 PM »
This is very frustrating.  I tried using the CommandEnded event (like I did in Lisp) didn't work.  Then I tried using the ObjectModified event, didn't work.

Maybe after lunch an idea that will work will pop into my head.  Thanks for trying Luis.  It is appreciated.

i know...

are you always using: OpenMode.ForRead

on your tests?.... how about ForWrite?

:)

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #10 on: June 04, 2007, 05:25:09 PM »
This is very frustrating.  I tried using the CommandEnded event (like I did in Lisp) didn't work.  Then I tried using the ObjectModified event, didn't work.

Maybe after lunch an idea that will work will pop into my head.  Thanks for trying Luis.  It is appreciated.

i know...

are you always using: OpenMode.ForRead

on your tests?.... how about ForWrite?

:)
I use OpenMode.ForRead on all objects but the attributes, thos I use OpenMode.ForWrite.  I didn't think I had to open the block with OpenMode.ForWrite also.

Nothing came to me during lunch.  Oh well.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Tool palette, Object selection and Event
« Reply #11 on: June 04, 2007, 05:51:50 PM »
I use OpenMode.ForRead on all objects but the attributes, thos I use OpenMode.ForWrite.  I didn't think I had to open the block with OpenMode.ForWrite also.

Nothing came to me during lunch.  Oh well.  :-)

if an object is going to be modified, you have to opened for write... (now, if you modify the attributes from a block, you do not open.write the block, and your routine works?)

to bad, i can played with code right now....  :-(

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #12 on: June 04, 2007, 06:00:51 PM »
if an object is going to be modified, you have to opened for write... (now, if you modify the attributes from a block, you do not open.write the block, and your routine works?)
Yes.  It will work fine with picking the block through the routine, but not with the event.

to bad, i can played with code right now....  :-(
Yes.  :-)  If you want I can post the whole routine so you can test when you want, if you want.  Let me know.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: Tool palette, Object selection and Event
« Reply #13 on: June 04, 2007, 06:03:53 PM »
to bad, i can played with code right now....  :-(

that should said:

"To bad, I do not have time right now to play with code..."

T.Willey

  • Needs a day job
  • Posts: 5241
Re: Tool palette, Object selection and Event
« Reply #14 on: June 04, 2007, 06:05:54 PM »
to bad, i can played with code right now....  :-(

that should said:

"To bad, I do not have time right now to play with code..."
I knew what you meant.  :wink:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.