public static Result SetActiveView(RhinoDoc doc)
    {
        // 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;
    }
    public static Result ReplaceHatchPattern(RhinoDoc doc)
    {
        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;
    }
Beispiel #3
0
        protected Result AddOption()
        {
            var gs = new GetString();

            gs.SetCommandPrompt("String to add");
            gs.AcceptNothing(true);
            switch (gs.Get())
            {
            case GetResult.String:
                break;

            case GetResult.Nothing:
                return(Result.Nothing);

            default:
                return(Result.Cancel);
            }

            var str = gs.StringResult().Trim();

            if (string.IsNullOrEmpty(str))
            {
                return(Result.Nothing);
            }

            var plugin = SampleCsUserDataPlugIn.Instance;

            if (plugin.StringDocumentDataTable.Add(str) < 0)
            {
                RhinoApp.WriteLine("Unable to add string.");
            }

            return(Result.Success);
        }
Beispiel #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var conduit = new SampleCsDrawRightAlignedTextConduit();

            conduit.Enabled = true;
            doc.Views.Redraw();

            var gs = new GetString();

            gs.SetCommandPrompt("Press <Enter> to continue");
            gs.AcceptNothing(true);
            gs.Get();

            conduit.Enabled = false;
            doc.Views.Redraw();

            return(Result.Success);
        }
Beispiel #5
0
    public static Result SetActiveView(RhinoDoc doc)
    {
        // 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);
    }
Beispiel #6
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);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select curves for direction display");
            go.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
            go.SubObjectSelect = false;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            doc.Objects.UnselectAll();

            SampleCsCurveDirectionConduit conduit = new SampleCsCurveDirectionConduit(go);

            conduit.Enabled = true;
            doc.Views.Redraw();

            GetString gs = new GetString();

            gs.SetCommandPrompt("Press <Enter> to continue");
            gs.AcceptNothing(true);
            gs.Get();

            conduit.Enabled = false;

            if (go.ObjectsWerePreselected)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    go.Object(i).Object().Select(true);
                }
            }

            doc.Views.Redraw();

            return(Result.Success);
        }