コード例 #1
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      ObjRef[] obj_refs;
      var rc = RhinoGet.GetMultipleObjects("Select hatches to replace", false, ObjectType.Hatch, out obj_refs);
      if (rc != Result.Success || obj_refs == null)
        return rc;

      var gs = new GetString();
      gs.SetCommandPrompt("Name of replacement hatch pattern");
      gs.AcceptNothing(false);
      gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();
      var hatch_name = gs.StringResult();

      var pattern_index = doc.HatchPatterns.Find(hatch_name, true);

      if (pattern_index < 0)
      {
        RhinoApp.WriteLine("The hatch pattern \"{0}\" not found  in the document.", hatch_name);
        return Result.Nothing;
      }

      foreach (var obj_ref in obj_refs)
      {
        var hatch_object = obj_ref.Object() as HatchObject;
        if (hatch_object.HatchGeometry.PatternIndex != pattern_index)
        {
          hatch_object.HatchGeometry.PatternIndex = pattern_index;
          hatch_object.CommitChanges();
        }
      }
      doc.Views.Redraw();
      return Result.Success;
    }
コード例 #2
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // view and view names
      var active_view_name = doc.Views.ActiveView.ActiveViewport.Name;

      var non_active_views = 
        doc.Views
        .Where(v => v.ActiveViewport.Name != active_view_name)
        .ToDictionary(v => v.ActiveViewport.Name, v => v);

      // get name of view to set active
      var gs = new GetString();
      gs.SetCommandPrompt("Name of view to set active");
      gs.AcceptNothing(true);
      gs.SetDefaultString(active_view_name);
      foreach (var view_name in non_active_views.Keys)
        gs.AddOption(view_name);
      var result = gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();

      var selected_view_name = 
        result == GetResult.Option ? gs.Option().EnglishName : gs.StringResult();

      if (selected_view_name != active_view_name)
        if (non_active_views.ContainsKey(selected_view_name))
          doc.Views.ActiveView = non_active_views[selected_view_name];
        else
          RhinoApp.WriteLine("\"{0}\" is not a view name", selected_view_name);

      return Rhino.Commands.Result.Success;
    }
コード例 #3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            String destLayerName;

            /*
            foreach (Rhino.DocObjects.Layer layer in doc.Layers)
            {
                RhinoApp.WriteLine(layer.LayerIndex.ToString() + ")(" + layer.Name + ":" + layer.ToString());
            }
             */
            using (GetString getString = new GetString())
            {
                getString.SetCommandPrompt("Enter new default Layer name");
                if (getString.Get() != GetResult.String)
                {
                    RhinoApp.WriteLine("No layer name recieved.");
                    return Result.Failure;
                }
                destLayerName = getString.StringResult().Trim();
            }

            foreach (Rhino.DocObjects.Layer layer in doc.Layers)
            {
                //RhinoApp.WriteLine(layer.LayerIndex.ToString() + ")(" + layer.Name + ":" + layer.ToString());
                if (layer.Name.Trim() == destLayerName)
                {
                    doc.Layers.SetCurrentLayerIndex(layer.LayerIndex, false);
                    return Result.Success;
                }
            }

            return Result.Failure;
        }
コード例 #4
0
ファイル: ex_addlayer.cs プロジェクト: austinlaw/rhinocommon
  public static Rhino.Commands.Result AddLayer(Rhino.RhinoDoc doc)
  {
    // Cook up an unused layer name
    string unused_name = doc.Layers.GetUnusedLayerName(false);

    // Prompt the user to enter a layer name
    Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString();
    gs.SetCommandPrompt("Name of layer to add");
    gs.SetDefaultString(unused_name);
    gs.AcceptNothing(true);
    gs.Get();
    if (gs.CommandResult() != Rhino.Commands.Result.Success)
      return gs.CommandResult();

    // Was a layer named entered?
    string layer_name = gs.StringResult().Trim();
    if (string.IsNullOrEmpty(layer_name))
    {
      Rhino.RhinoApp.WriteLine("Layer name cannot be blank.");
      return Rhino.Commands.Result.Cancel;
    }

    // Is the layer name valid?
    if (!Rhino.DocObjects.Layer.IsValidName(layer_name))
    {
      Rhino.RhinoApp.WriteLine(layer_name + " is not a valid layer name.");
      return Rhino.Commands.Result.Cancel;
    }

    // Does a layer with the same name already exist?
    int layer_index = doc.Layers.Find(layer_name, true);
    if (layer_index >= 0)
    {
      Rhino.RhinoApp.WriteLine("A layer with the name {0} already exists.", layer_name);
      return Rhino.Commands.Result.Cancel;
    }

    // Add a new layer to the document
    layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black);
    if (layer_index < 0)
    {
      Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", layer_name);
      return Rhino.Commands.Result.Failure;
    }
    return Rhino.Commands.Result.Success;
  }
コード例 #5
0
ファイル: setLogPrefix.cs プロジェクト: pragun/rhino5plugin
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString();
            gs.SetCommandPrompt("Enter log prefix name (or the name of the user)");
            gs.SetDefaultString("");
            gs.AcceptNothing(true);
            gs.Get();
            if (gs.CommandResult() != Rhino.Commands.Result.Success)
                return gs.CommandResult();

            string logPrefix = gs.StringResult().Trim();
            gs.SetCommandPrompt(" ");

            RhinoApp.WriteLine("You said " + logPrefix + " right?");
            System.Threading.Thread.Sleep(500);
            ((nishanchiPlugin)this.PlugIn).logPrefix = logPrefix;
            ((nishanchiPlugin)this.PlugIn).fileCounter = 0;
            return Result.Success;
        }
コード例 #6
0
ファイル: connectTracker.cs プロジェクト: pragun/rhino5plugin
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString();
            gs.SetCommandPrompt("Enter serial port name (COMx)");
            gs.SetDefaultString("COM4");
            gs.AcceptNothing(true);
            gs.Get();
            if (gs.CommandResult() != Rhino.Commands.Result.Success)
                return gs.CommandResult();

            string portName = gs.StringResult().Trim();
            gs.SetCommandPrompt(" ");

            RhinoApp.WriteLine("You said " + portName + " right?");
            System.Threading.Thread.Sleep(500);

            ((nishanchiPlugin)this.PlugIn).connectTracker(portName);

            return Result.Success;
        }
コード例 #7
0
  public static Rhino.Commands.Result AddChildLayer(Rhino.RhinoDoc doc)
  {
    // Get an existing layer
    string default_name = doc.Layers.CurrentLayer.Name;

    // Prompt the user to enter a layer name
    Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString();
    gs.SetCommandPrompt("Name of existing layer");
    gs.SetDefaultString(default_name);
    gs.AcceptNothing(true);
    gs.Get();
    if (gs.CommandResult() != Rhino.Commands.Result.Success)
      return gs.CommandResult();

    // Was a layer named entered?
    string layer_name = gs.StringResult().Trim();
    int index = doc.Layers.Find(layer_name, true);
    if (index<0)
      return Rhino.Commands.Result.Cancel;

    Rhino.DocObjects.Layer parent_layer = doc.Layers[index];

    // Create a child layer
    string child_name = parent_layer.Name + "_child";
    Rhino.DocObjects.Layer childlayer = new Rhino.DocObjects.Layer();
    childlayer.ParentLayerId = parent_layer.Id;
    childlayer.Name = child_name;
    childlayer.Color = System.Drawing.Color.Red;

    index = doc.Layers.Add(childlayer);
    if (index < 0)
    {
      Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", child_name);
      return Rhino.Commands.Result.Failure;
    }
    return Rhino.Commands.Result.Success;
  }
コード例 #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Check the selected curve
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

            GetResult result = go.Get();

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            if (go.ObjectCount != 1)
            {
                RhinoApp.WriteLine("Error: {0} curve is selected.", go.ObjectCount);
                return(Rhino.Commands.Result.Failure);
            }

            RhinoApp.WriteLine("{0} curve is selected.", go.ObjectCount);

            Curve curve = go.Object(0).Curve();

            // If curve is null
            if (curve == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // If curve is Closed Curve Orientation
            if (curve.IsClosed == false)
            {
                RhinoApp.WriteLine("The curve is open");
                return(Rhino.Commands.Result.Failure);
            }

            PerforationForm perforationForm = new PerforationForm(curve);

            //  perforationForm.ShowDialog(RhinoApp.MainWindow());
            // Prompt the user to enter a layer name
            Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString();
            gs.SetCommandPrompt("Name of the Design: e.g. 60 degrees - Round 2.4 @ 3.6");
            gs.AcceptNothing(false);
            gs.Get();
            if (gs.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gs.CommandResult());
            }

            perforationForm.drawPerforationDesign(gs.StringResult().Trim(), true);

            return(Result.Success);
        }