Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:prepostpick [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Pre-Pick and Post-Pick Objects =====
 +
 +===== C# =====
 +<code c#>
 +public class PrePostPickCommand : Command
 +{
 +  public override string EnglishName { get { return "​csPrePostPick";​ } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    var go = new Rhino.Input.Custom.GetObject();​
 +    go.SetCommandPrompt("​Select objects"​);​
 +    go.EnablePreSelect(true,​ true);
 +    go.EnablePostSelect(true);​
 +    go.GetMultiple(0,​ 0);
 +    if (go.CommandResult() != Result.Success)
 +      return go.CommandResult();​
 +
 +    var selected_objects = go.Objects().ToList();​
 +
 +    if (go.ObjectsWerePreselected)
 +    {
 +      go.EnablePreSelect(false,​ true);
 +      go.DeselectAllBeforePostSelect = false;
 +      go.EnableUnselectObjectsOnExit(false);​
 +      go.GetMultiple(0,​ 0);
 +      if (go.CommandResult() == Result.Success)
 +      {
 +        foreach (var obj in go.Objects())
 +        {
 +          selected_objects.Add(obj);​
 +          // The normal behavior of commands is that when they finish,
 +          // objects that were pre-selected remain selected and objects
 +          // that were post-selected will not be selected. Because we
 +          // potentially could have both, we'll try to do something
 +          // consistent and make sure post-selected objects also stay selected
 +          obj.Object().Select(true);​
 +        }
 +      }
 +    }
 +    return selected_objects.Count > 0 ? Result.Success : Result.Nothing;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class PrePostPickCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbPrePostPick"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim go = New Rhino.Input.Custom.GetObject()
 +    go.SetCommandPrompt("​Select objects"​)
 +    go.EnablePreSelect(True,​ True)
 +    go.EnablePostSelect(True)
 +    go.GetMultiple(0,​ 0)
 +    If go.CommandResult() <> Result.Success Then
 +      Return go.CommandResult()
 +    End If
 +
 +    Dim selected_objects = go.Objects().ToList()
 +
 +    If go.ObjectsWerePreselected Then
 +      go.EnablePreSelect(False,​ True)
 +      go.DeselectAllBeforePostSelect = False
 +      go.EnableUnselectObjectsOnExit(False)
 +      go.GetMultiple(0,​ 0)
 +      If go.CommandResult() = Result.Success Then
 +        For Each obj As ObjRef In go.Objects()
 +          selected_objects.Add(obj)
 +          ' The normal behavior of commands is that when they finish,
 +          ' objects that were pre-selected remain selected and objects
 +          ' that were post-selected will not be selected. Because we
 +          ' potentially could have both, we'll try to do something
 +          ' consistent and make sure post-selected objects also stay selected
 +          obj.[Object]().[Select](True)
 +        Next
 +      End If
 +    End If
 +    Return If(selected_objects.Count > 0, Result.Success,​ Result.[Nothing])
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.Commands import *
 +from Rhino.Input.Custom import *
 +
 +def RunCommand():​
 +  go = GetObject()
 +  go.SetCommandPrompt("​Select objects"​)
 +  go.EnablePreSelect(True,​ True)
 +  go.EnablePostSelect(True)
 +  go.GetMultiple(0,​ 0)
 +  if go.CommandResult() != Result.Success:​
 +    return go.CommandResult()
 +
 +  selected_objects = []
 +  for obj in go.Objects():​
 +    selected_objects.Add(obj)
 +
 +  if go.ObjectsWerePreselected:​
 +    go.EnablePreSelect(False,​ True)
 +    go.DeselectAllBeforePostSelect = False
 +    go.EnableUnselectObjectsOnExit(False)
 +    go.GetMultiple(0,​ 0)
 +    if go.CommandResult() == Result.Success:​
 +      for obj in go.Objects():​
 +        selected_objects.Add(obj)
 +        # The normal behavior of commands is that when they finish,
 +        # objects that were pre-selected remain selected and objects
 +        # that were post-selected will not be selected. Because we
 +        # potentially could have both, we'll try to do something
 +        # consistent and make sure post-selected objects also stay selected
 +        obj.Object().Select(True)
 +  return Result.Success if selected_objects.Count > 0 else Result.Nothing
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/prepostpick.txt ยท Last modified: 2015/09/14 (external edit)