.NET

Reply
Mentor
wang890
Posts: 831
Registered: ‎06-08-2007
Message 1 of 5 (711 Views)
Accepted Solution

cursor pick object event

711 Views, 4 Replies
02-08-2012 10:35 AM

i am trying to make a custom palette to display some custom infomation pulled out from selected objects.

 

i can deal with the palette part.

 

i want some code for when you click an object in model space then the property palette updates. i am gonna keep it simple so this custom palette only refresh to the last selected object. but i don't know how to make an event when mouse click the autocad object and then do my things. any codes in c# or vb.net would be nice.

 

so use commandmethod load in a command and there will be a palette there stay open, when user click on an object then it will get populated. what event do i use for the clicking?

 

thank you.

Civil 3D 2014
Work: i7 4770, SSD, 16GB, K2000, Dell PH2414H
Home: i7 3930k, SSD, 16GB, GTX 590, U3011

Hi Bob,

Some initial testing shows that this can work, for the most part. Ran out of time to track down why the AddedObjects ObjectId collection is still populated when the user hits ESC.


///Sample code to trap adding an object to the PickFirstSelectionset.
///Works across multiple drawings. Not sure, yet, how to handle when the user clears
///the PickFirstSS by hitting ESC. Did not test for manual removal by SHIFT+Pick.
///Jeff Mishler, Feb 2012
using System.Linq;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace PaletteTest
{
public class PaletteTest : IExtensionApplication
{
static PaletteTestPalette palette;
static Document doc_palettetest;
static Editor ed_palettetest;
public void Initialize()
{
palette = new PaletteTestPalette();
if (palette.Visible)
palette.ToggleVisibility();
doc_palettetest = Application.DocumentManager.MdiActiveDocument;
ed_palettetest = doc_palettetest.Editor;
ed_palettetest.SelectionAdded += new SelectionAddedEventHandler(ed_SelectionAdded);
}
static void DocumentManager_DocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e)
{
ed_palettetest.SelectionAdded -= new SelectionAddedEventHandler(ed_SelectionAdded);
}
static void DocumentManager_DocumentActivated(object sender, DocumentCollectionEventArgs e)
{
doc_palettetest = Application.DocumentManager.MdiActiveDocument;
ed_palettetest = doc_palettetest.Editor;
ed_palettetest.SelectionAdded += new SelectionAddedEventHandler(ed_SelectionAdded);
}
public void Terminate()
{
}
static void ed_SelectionAdded(object sender, SelectionAddedEventArgs e)
{
if (palette.Visible && e.Flags == SelectionFlags.PickfirstSet)
{
ObjectId id = e.AddedObjects.GetObjectIds().Last();
using (Transaction tr = doc_palettetest.Database.TransactionManager.StartTransaction())
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
palette.thiscontrol.TextValue = "You selected a: " + id.ObjectClass.DxfName;
tr.Commit();
}
}
}
[CommandMethod("PaletteTest", CommandFlags.Session)]
public static void palettetestcommand()
{
Application.DocumentManager.DocumentActivated += new DocumentCollectionEventHandler(DocumentManager_DocumentActivated);
Application.DocumentManager.DocumentToBeDeactivated += new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDeactivated);
palette.ToggleVisibility();
}
}
}

 

 

Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 2 of 5 (708 Views)

Re: cursor pick object event

02-08-2012 10:46 AM in reply to: wang890

I'm gonna take a guess here: 

 

I think it's a Doc Event

I used MdgDgbd.dll Tool to tinker with events that are fired when I click and object. 

 

Document.ImpliedSelectionChanged Event

 

This notification is triggered when the pickfirst selection set has been modified; that is, for all events that add objects to or remove objects from the set. Events that change the geometry or properties of the objects within the selection set (stretching, moving, and so on) do not trigger this callback.

Links
Distinguished Contributor
VB_Autocad_guy
Posts: 136
Registered: ‎07-24-2009
Message 3 of 5 (670 Views)

Re: cursor pick object event

02-14-2012 12:27 PM in reply to: wang890

Did you ever figure it out? I'd be curious to know how you did it? 

Do you mind posting some code? 

*Expert Elite*
Jeff_M
Posts: 4,521
Registered: ‎07-22-2003
Message 4 of 5 (646 Views)

Re: cursor pick object event

02-15-2012 07:19 AM in reply to: wang890

Hi Bob,

Some initial testing shows that this can work, for the most part. Ran out of time to track down why the AddedObjects ObjectId collection is still populated when the user hits ESC.


///Sample code to trap adding an object to the PickFirstSelectionset.
///Works across multiple drawings. Not sure, yet, how to handle when the user clears
///the PickFirstSS by hitting ESC. Did not test for manual removal by SHIFT+Pick.
///Jeff Mishler, Feb 2012

using System.Linq;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace PaletteTest
{
    public class PaletteTest : IExtensionApplication
    {
        static PaletteTestPalette palette;
        static Document doc_palettetest;
        static Editor ed_palettetest;

        public void Initialize()
        {
            palette = new PaletteTestPalette();
            if (palette.Visible)
                palette.ToggleVisibility();
            doc_palettetest = Application.DocumentManager.MdiActiveDocument;
            ed_palettetest = doc_palettetest.Editor;
            ed_palettetest.SelectionAdded += new SelectionAddedEventHandler(ed_SelectionAdded);
        }

        static void DocumentManager_DocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e)
        {
            ed_palettetest.SelectionAdded -= new SelectionAddedEventHandler(ed_SelectionAdded);
        }

        static void DocumentManager_DocumentActivated(object sender, DocumentCollectionEventArgs e)
        {
            doc_palettetest = Application.DocumentManager.MdiActiveDocument;
            ed_palettetest = doc_palettetest.Editor;
            ed_palettetest.SelectionAdded += new SelectionAddedEventHandler(ed_SelectionAdded);
        }

        public void Terminate()
        {
        }

        static void ed_SelectionAdded(object sender, SelectionAddedEventArgs e)
        {
            if (palette.Visible && e.Flags == SelectionFlags.PickfirstSet)
            {
                
                ObjectId id = e.AddedObjects.GetObjectIds().Last();
                using (Transaction tr = doc_palettetest.Database.TransactionManager.StartTransaction())
                {
                    Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
                    palette.thiscontrol.TextValue = "You selected a: " + id.ObjectClass.DxfName;
                    tr.Commit();
                }
            }
        }
        [CommandMethod("PaletteTest", CommandFlags.Session)]
        public static void palettetestcommand()
        {
            Application.DocumentManager.DocumentActivated += new DocumentCollectionEventHandler(DocumentManager_DocumentActivated);
            Application.DocumentManager.DocumentToBeDeactivated += new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDeactivated);
            palette.ToggleVisibility();
        }
    }
}

 

 

Jeff_M, also a frequent Swamper
Mentor
wang890
Posts: 831
Registered: ‎06-08-2007
Message 5 of 5 (627 Views)

Re: cursor pick object event

02-15-2012 10:32 AM in reply to: Jeff_M

thanks jeff

 

i got it working now after finding out this pdf:

 

CP205-2_Mike_Tuersley.pdf

 

pretty good.

 

keeping your code as a future reference.

Civil 3D 2014
Work: i7 4770, SSD, 16GB, K2000, Dell PH2414H
Home: i7 3930k, SSD, 16GB, GTX 590, U3011
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.