TheSwamp

Code Red => .NET => Topic started by: huangc on February 22, 2012, 11:36:10 PM

Title: How to make the entity will not be selected ?
Post by: huangc on February 22, 2012, 11:36:10 PM
hi,
    How to make the entity will not be selected ?
   
Title: Re: How to make the entity will not be selected ?
Post by: Kerry on February 23, 2012, 12:36:22 AM

Putting it on a locked layer will partly solve your issue ... untill the layer is unlocked, or the selection mechanism is told to ignore locked layers.
Title: Re: How to make the entity will not be selected ?
Post by: Kerry on February 23, 2012, 12:37:02 AM

... and welcome to theSwamp :)
Title: Re: How to make the entity will not be selected ?
Post by: huangc on February 23, 2012, 01:34:23 AM
Thanks for your advice, but I want to do is to prohibit the user to choose, now i have an object, but I do not want the user to modify it manually, but only by loading the program to modify
Title: Re: How to make the entity will not be selected ?
Post by: Kerry on February 23, 2012, 04:25:05 AM

The only thing I know that will reliably do what you want is to write custom objects in ARX.
Title: Re: How to make the entity will not be selected ?
Post by: mohnston on February 23, 2012, 12:19:51 PM
Thanks for your advice, but I want to do is to prohibit the user to choose, now i have an object, but I do not want the user to modify it manually, but only by loading the program to modify

I agree with Kerry.
Since AutoCAD has so many ways to manipulate objects it makes it tough to lock anything up.

A couple of strategies that I've used are:
1. If the environment is contained (in-house project) you can work with the CAD department to explain the benefits of using your program to modify the objects. Then set a company policy.
2. Create tools that modify the object that are better, easier, smarter than the AutoCAD tools. This way you entice the user to use your program rather than force them.

Both of these strategies leave many technical holes for users to work around.
You could try plugging those holes as they are discovered. You might get to 80% and for some environments that may be enough.
Title: Re: How to make the entity will not be selected ?
Post by: cincir on February 23, 2012, 02:07:38 PM
you can overrule. if you throw an exception in ObjectOverrule's Open method the object cannot be selected.
Title: Re: How to make the entity will not be selected ?
Post by: Kerry on February 23, 2012, 05:43:26 PM
you can overrule. if you throw an exception in ObjectOverrule's Open method the object cannot be selected.

have you tried that ??
What happens if the user tries a commandLine MOVE command and selects the object along with others ??

... and what happens if the Overrule code is not loaded into the current session.

Regards,
Title: Re: How to make the entity will not be selected ?
Post by: huangc on February 23, 2012, 11:26:59 PM
SELECTION event can prevent the user selected, but that did not reach my goal, I think that the Custom the Object is an ideal choice.The following is to disable the object selection by selecting events 
Code - C#: [Select]
  1. void OnSelectionAdded(object sender, SelectionAddedEventArgs e)
  2.         {
  3.              
  4.             ObjectId[] addedIds = e.AddedObjects.GetObjectIds();
  5.             for (int i = 0; i < addedIds.Length; i++)
  6.             {
  7.                 ObjectId oid = addedIds[i];
  8.                 if (disObjectId.Contains(oid))
  9.                 {
  10.                     e.Remove(i);
  11.                 }
  12.             }
  13.         }
  14.  
  15.         static List<ObjectId> disObjectId = new List<ObjectId>();
  16.  
  17.         public void Initialize()
  18.         {
  19.             Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  20.             if (doc == null)
  21.                 return;
  22.             Editor ed = doc.Editor;
  23.             ed.SelectionAdded += new SelectionAddedEventHandler(OnSelectionAdded);
  24.         }
  25.  
  26.         public void Terminate()
  27.         {
  28.             Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  29.             if (doc == null)
  30.                 return;
  31.             Editor ed = doc.Editor;
  32.             ed.SelectionAdded -= new SelectionAddedEventHandler(OnSelectionAdded);
  33.         }
  34.  
  35.         [CommandMethod("DisEntity")]
  36.         public void SelectDisplayEntity()
  37.         {
  38.             Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  39.             if (doc == null)
  40.                 return;
  41.             SelectionSet selects = GetSelectionSet();
  42.             foreach (SelectedObject sel in selects)
  43.             {
  44.                 disObjectId.Add(sel.ObjectId);
  45.             }
  46.         }
  47.  
  48.         SelectionSet GetSelectionSet()
  49.         {
  50.             Editor ed = null;
  51.             if (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument != null)
  52.             {
  53.                 ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  54.                 PromptSelectionResult ents = ed.SelectImplied();
  55.                 if (ents.Value != null && ents.Value.Count == 1)
  56.                     return ents.Value;
  57.                 else if (ents.Value == null)
  58.                 {
  59.                     PromptSelectionOptions pso = new PromptSelectionOptions();
  60.                     pso.AllowDuplicates = false;
  61.                     pso.SingleOnly = false;
  62.                     return ed.GetSelection(pso).Value;
  63.                 }
  64.                 else
  65.                     return ents.Value;
  66.             }
  67.             return null;
  68.         }
  69.  

 edit.kdub Code formatting code=csharp (http://www.theswamp.org/index.php?topic=4429.msg456896#msg456896)
Title: Re: How to make the entity will not be selected ?
Post by: cincir on February 25, 2012, 07:36:10 PM
you can overrule. if you throw an exception in ObjectOverrule's Open method the object cannot be selected.

have you tried that ??
What happens if the user tries a commandLine MOVE command and selects the object along with others ??

... and what happens if the Overrule code is not loaded into the current session.

Regards,

if the code is not loaded ofcourse that code will not work as the other approaches.
in one of my project i used this method but not in a command ,used to provide a pickfirstset.
Title: Re: How to make the entity will not be selected ?
Post by: Kerry on February 25, 2012, 10:20:39 PM



if the code is not loaded ofcourse that code will not work as the other approaches.


that's correct

and ...


What happens if the user tries a commandLine MOVE command and selects the object along with others ??

Regards,
Title: Re: How to make the entity will not be selected ?
Post by: cincir on February 26, 2012, 07:53:04 AM



if the code is not loaded ofcourse that code will not work as the other approaches.


that's correct

and ...


What happens if the user tries a commandLine MOVE command and selects the object along with others ??

Regards,

Kerry i tried it for you and the result is just what i wrote. beacause the objects cannot be opened, command you give just ignores them.