How to receive selected object data from AutoCAD with mouse wheel enabled (PromptSelection / SendStringToExecute)

How to receive selected object data from AutoCAD with mouse wheel enabled (PromptSelection / SendStringToExecute)

Soojung_Kim
Enthusiast Enthusiast
986 Views
6 Replies
Message 1 of 7

How to receive selected object data from AutoCAD with mouse wheel enabled (PromptSelection / SendStringToExecute)

Soojung_Kim
Enthusiast
Enthusiast

 

Hi, I'm fairly new to writing an add-in with .NET for AutoCAD.

In this tool, I want to ask the user to select objects in the drawing and receive that object data back to my code.

 

I know the PromptSelection method allows that, but when I use that, I can't use the mouse wheel to move or pan. I can only zoom in and out and select. Is there a way to 'unlock' the mouse wheel function?

 

// Request for objects to be selected in the drawing area
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.MessageForAdding = "Select Pipes";                    
PromptSelectionResult acSSPrompt = ed.GetSelection(pso);

// Allows to bring back the selected objects, but mouse wheel doesn't work for pan, only works for zoom

 

 

 

So I've tried SendStringToExecute method because that allows me to use the mouse wheel , but then I don't know how to get the selected data back to my code.

 

private void GetObject_Click(object sender, RoutedEventArgs e)
{
   try
   {
      _document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
      _document.SendStringToExecute("GETOBJECT ", false, false, true);
    }

    finally
    {
    }
            
}


[CommandMethod("GETOBJECT")]
public void GetObject()
{
   Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
   DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
   var ed = doc.Editor;
   using (Transaction ts = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
   {
      try
      {
        // Request for objects to be selected in the drawing area
        PromptSelectionOptions pso = new PromptSelectionOptions();
        pso.MessageForAdding = "Select Pipes";
        PromptSelectionResult acSSPrompt = ed.GetSelection(pso);
        // how do I use this data back in my code?

      }
    }
}

 

 

Can someone please share some ideas? 

 

Thanks! 

 

0 Likes
Accepted solutions (1)
987 Views
6 Replies
Replies (6)
Message 2 of 7

quangpt.tric
Advocate
Advocate

Hi @Soojung_Kim ,

you can add list<Entity> of your selection, and use this code:

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.SetImpliedSelection(lstEnts.Select(ent => ent.ObjectId).ToArray());
0 Likes
Message 3 of 7

essam-salah
Collaborator
Collaborator
Accepted solution

hi @Soojung_Kim 

 

public class SomeClass
    {
        ObjectId[] _currentSelection;

        private void GetObject_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                _document.SendStringToExecute("GETOBJECT ", false, false, true);

                if (_currentSelection == null)
                    return;

                //// TO DO
                //using (var tr = _document.Database.TransactionManager.StartTransaction())
                //{
                //    foreach (var id in _currentSelection)
                //    {
                //        var obj = id.GetObject(OpenMode.ForWrite) as Line;


                //    }

                //    tr.Commit();
                //}
            }

            finally
            {
            }
        }
        [CommandMethod("GETOBJECT")]
        public void GetObject()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
            var ed = doc.Editor;
            using (Transaction ts = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
            {
                
                // Request for objects to be selected in the drawing area
                PromptSelectionOptions pso = new PromptSelectionOptions();
                pso.MessageForAdding = "Select Pipes";
                PromptSelectionResult acSSPrompt = ed.GetSelection(pso);

                // how do I use this data back in my code?

                _currentSelection = null;
                if (acSSPrompt.Status != PromptStatus.OK) 
                    return;

                _currentSelection = acSSPrompt.Value.GetObjectIds();
            }
        }


    }
0 Likes
Message 4 of 7

Soojung_Kim
Enthusiast
Enthusiast

Thanks for the reply. I get the part where you stored the selected objects to _currentSelection. 

Now I'm having trouble with the SendStringToCommand occurring after the TO DO part. I found this thread so trying to figure out how to implement it.. https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/td-p/3882929

 

Haven't succeeded yet, but thanks for the advice on setting the variable outside the method! 

0 Likes
Message 5 of 7

Soojung_Kim
Enthusiast
Enthusiast
Sorry, I don't understand what you mean. Do you mean save the promptSelection output to lstEnts in your example?
0 Likes
Message 6 of 7

essam-salah
Collaborator
Collaborator
Haven't succeeded yet, but thanks for the advice on setting the variable outside the method! 

you can make a new post with the specific problem part you have. 

0 Likes
Message 7 of 7

Soojung_Kim
Enthusiast
Enthusiast
0 Likes