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

ObjectID from Dbl-Click on Block is Insane

12 REPLIES 12
Reply
Message 1 of 13
LialAtArnold
1125 Views, 12 Replies

ObjectID from Dbl-Click on Block is Insane

I have added an Event Handler to the Document Editor that contains the code below.

If I go to any block inserted in the drawing and double-click on it, the EATTEDIT command is launched (as defined in the CUI for the Double Click Action on an Attribute Block) but the ObjectId returned is always the same. It never changes when a different object is selected.

If I hilight the block first, then right-click(select the right mouse button) the code returns the correct ObjectID every time.

How do I get it to return the correct ObjectID in all cases?
I really cannot redefine the EATTEDIT command and its dbl-click action.

[Code]
private void callback_CommandEnded(Object o, CommandEventArgs e)
{
//Set up a reference to the AutoCAD editor
Autodesk.AutoCAD.EditorInput.Editor Ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

//Case out the current AutoCAD command
switch (e.GlobalCommandName)
{
case "EATTEDIT":
PromptSelectionResult lastRes = Ed.SelectLast();
if (lastRes.Value != null && lastRes.Value.Count == 1)
{
Ed.WriteMessage("\nEntity is: " + lastRes.Value);

}
break;
}
}

Output:

Double-Click on Block A:
Select a block: 47.246932,11.307365,0.000000
Entity is: (((2129775720),NonGraphical,0,))

Double-Click on Block B:
Select a block: 40.840972,13.998628,0.000000
Entity is: (((2129775720),NonGraphical,0,))


Select block A, then Right-click:
Select a block: 47.246932,11.307365,0.000000
Entity is: (((2129775720),NonGraphical,0,))

Select block B, then Right-click:
Select a block: 40.840972,13.998628,0.000000
Entity is: (((2129775176),PickPoint,0,)) Edited by: lial.williams@arnold.af.mil on Oct 12, 2009 4:20 PM
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: LialAtArnold

Perhaps you've been bitten by the horrible documentation.

The docs for SelectLast says it 'Selects last result from the prompt', which
is complete nonsense.

SelectLast returns the last object created in the current space, which has
nothing to do with the object that was edited by a command.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6270178@discussion.autodesk.com...
I have added an Event Handler to the Document Editor that contains the code
below.

If I go to any block inserted in the drawing and double-click on it, the
EATTEDIT command is launched (as defined in the CUI for the Double Click
Action on an Attribute Block) but the ObjectId returned is always the same.
It never changes when a different object is selected.

If I hilight the block first, then right-click(select the right mouse
button) the code returns the correct ObjectID every time.

How do I get it to return the correct ObjectID in all cases?
I really cannot redefine the EATTEDIT command and its dbl-click action.

[Code]
private void callback_CommandEnded(Object o, CommandEventArgs e)
{
//Set up a reference to the AutoCAD editor
Autodesk.AutoCAD.EditorInput.Editor Ed =
AcadApp.DocumentManager.MdiActiveDocument.Editor;

//Case out the current AutoCAD command
switch (e.GlobalCommandName)
{
case "EATTEDIT":
PromptSelectionResult lastRes = Ed.SelectLast();
if (lastRes.Value != null && lastRes.Value.Count ==
1)
{
Ed.WriteMessage("\nEntity is: " +
lastRes.Value);

}
break;
}
}

Output:

Double-Click on Block A:
Select a block: 47.246932,11.307365,0.000000
Entity is: (((2129775720),NonGraphical,0,))

Double-Click on Block B:
Select a block: 40.840972,13.998628,0.000000
Entity is: (((2129775720),NonGraphical,0,))


Select block A, then Right-click:
Select a block: 47.246932,11.307365,0.000000
Entity is: (((2129775720),NonGraphical,0,))

Select block B, then Right-click:
Select a block: 40.840972,13.998628,0.000000
Entity is: (((2129775176),PickPoint,0,))

Edited by: lial.williams@arnold.af.mil on Oct 12, 2009 4:20 PM
Message 3 of 13
LialAtArnold
in reply to: LialAtArnold

Tony,
I have also tried SelectImplied(), but that doesn't work either.

Actually, I had placed an event handler for CommandWillStart which looked for EATTEDIT and then it planted an:

Ed.PromptedForEntity += new PromptEntityResultEventHandler(callback_promptEntityResult);

in which I was getting the ObjectID out of and placing in a List for processing when the CommandEnded event came around.

But, for reasons unknown that setup was throwing FATAL ERRORs and crashing AutoCAD at what seemed to be totally random intervals. So I have backed all that out again.

How on earth do I capture the ObjectID of the Block that EATTEDIT was run against???
Message 4 of 13
Anonymous
in reply to: LialAtArnold

{quote}

But, for reasons unknown that setup was throwing FATAL ERRORs and crashing
AutoCAD at what seemed to be totally random intervals. So I have backed all
that out again.

{quote}

That's a problem with your code.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6270718@discussion.autodesk.com...
Tony,
I have also tried SelectImplied(), but that doesn't work either.

Actually, I had placed an event handler for CommandWillStart which looked
for EATTEDIT and then it planted an:

Ed.PromptedForEntity += new
PromptEntityResultEventHandler(callback_promptEntityResult);

in which I was getting the ObjectID out of and placing in a List
for processing when the CommandEnded event came around.

But, for reasons unknown that setup was throwing FATAL ERRORs and crashing
AutoCAD at what seemed to be totally random intervals. So I have backed all
that out again.

How on earth do I capture the ObjectID of the Block that EATTEDIT was run
against???
Message 5 of 13
LialAtArnold
in reply to: LialAtArnold

I agree.

I want to simplify things and only deal with the CommandEnded Event.

That is why I want to aquire the ObjectId of the Block EATTEDIT was just run against.

Is there no way to obtain the ObjectId when the Double-Click action is set?
Message 6 of 13
NathTay
in reply to: LialAtArnold

Can you use the object modified event?
Message 7 of 13
LialAtArnold
in reply to: LialAtArnold

Nath Tay,
I already have an Objectmodified Event set on the database which is looking for BlockReferences along with an ObjectAppended Event.

The problem with that is it only fires when the BlockRefernce itself is changed ( ie, the layer is changed), when an EATTEDIT is performed, a block attribute modification is made which means I would have to filter for all block attribute changes and then work back to the block reference each is attached to.

I am only interested in blocks that are on a specific layer and have a specific set of attributes attached to them.
Message 8 of 13
NathTay
in reply to: LialAtArnold

So you have a solution then?
Message 9 of 13
Anonymous
in reply to: LialAtArnold

First, EATTEDIT can edit multiple objects, so you're really not thinking the
problem out very well to start with. Second, I can't imagine why one would
want to intercept editing of attributes made via EATTEDIT, but not via any
other means that are available to edit attributes (like the Properties
Palette).

You haven't said much about what your ultimate goal is, and only have asked
how to get your own take on how to solve the problem working, which is not
really a solution, if you ask me.

What is it that you need to do to attributes that are edited?


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6270725@discussion.autodesk.com...
I agree.

I want to simplify things and only deal with the CommandEnded Event.

That is why I want to aquire the ObjectId of the Block EATTEDIT was just run
against.

Is there no way to obtain the ObjectId when the Double-Click action is set?
Message 10 of 13
LialAtArnold
in reply to: LialAtArnold

How do you run EATTEDIT on more than one block reference at a time?
It is possible to select multiple blocks and then update the attributes using the Properties Pallette, but that is not EATTEDIT.

The issue I have is that every block inserted on a specific layer has an attribute on it that has to have a unique value in it. I track these values in an Oracle database because they have to be unique across all drawings created by any user. When a user changes this attribute using EATTEDIT, I have to intercept it, check the value to see if it has been changed and if so then query Oracle and make sure it is unique. If it is then I insert the new record, and if not then I give them the option of taking the unique value I have generated for them, or inputting a new value of their own, or cancelling the whole operation and putting everything back to its pre-EATTEDIT value.

The simplest way to do all this would be to monitor the CommandEnded event and check the objectId or Handle of the blockreference selected for EATTEDIT for any changes, but it appears that it is not possible to retrieve the ObjectId reliably that way.
Message 11 of 13
Anonymous
in reply to: LialAtArnold

Do you see the button at the upper right corner of the dialog?

Try clicking it.

With the properties palette, multiple blocks can be selected, and attributes
with the same tag in each can be changed to a single value.

The problem with your design is mostly related to the fact that it relies on
attributes to start with. There are too many ways for a user to modify them
outside of your control, and trying to validate the value they enter is
damn-near impossible.

I would never use attributes to store a key that needs to be unique, to
begin with. I would use xdata or an extension dictionary, and provide my own
user interface for editing it.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6271347@discussion.autodesk.com...
How do you run EATTEDIT on more than one block reference at a time?
It is possible to select multiple blocks and then update the attributes
using the Properties Pallette, but that is not EATTEDIT.

The issue I have is that every block inserted on a specific layer has an
attribute on it that has to have a unique value in it. I track these values
in an Oracle database because they have to be unique across all drawings
created by any user. When a user changes this attribute using EATTEDIT, I
have to intercept it, check the value to see if it has been changed and if
so then query Oracle and make sure it is unique. If it is then I insert the
new record, and if not then I give them the option of taking the unique
value I have generated for them, or inputting a new value of their own, or
cancelling the whole operation and putting everything back to its
pre-EATTEDIT value.

The simplest way to do all this would be to monitor the CommandEnded event
and check the objectId or Handle of the blockreference selected for EATTEDIT
for any changes, but it appears that it is not possible to retrieve the
ObjectId reliably that way.
Message 12 of 13
LialAtArnold
in reply to: LialAtArnold

Aha! I see the select block icon you are referring to.
I will have to investigate it and it's effect on my app some more.

I have made it clear to the end users that they can change things with the properties pallette, but if they do they are on their own. As you say there are a number of different ways to accomplish any given action in AutoCAD. I am not attempting to cover all possible scenarios, just the ones the users use regularly.

As for the attributes, well this is the setup I inherited and there are a large number of legacy drawings with corresponding records in the Oracle tables that I have to deal with.

I have had this app up and running in VBA for over a year. I converted it to C# so that the dialog windows used to display the block attribute data could be open concurrently with the AutoCAD editor and the users could switch between the two instead of having to exit out and reopen whenever anything was changed.
Message 13 of 13
Bryco
in reply to: LialAtArnold

It's interesting to note that if a user doubleclicks to enter the command, the sysvar lastpoint will give a point that you can put into a selection that will give you the blockref, this all works from the endcommand. If the user types the command, lastpoint isn't updated and so you will get a false reading. If you could determine that the command was initiated by a doubleclick, you would have a reliable method.

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