예제 #1
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Object name to select");
            gs.GetString();
            if (gs.CommandResult() != IRhinoCommand.result.success)
            {
                return(gs.CommandResult());
            }

            string name = gs.String().Trim();

            if (string.IsNullOrEmpty(name))
            {
                return(IRhinoCommand.result.nothing);
            }

            MRhinoObjectIterator it = new MRhinoObjectIterator(
                IRhinoObjectIterator.object_state.normal_objects,
                IRhinoObjectIterator.object_category.active_and_reference_objects
                );

            int          num_selected = 0;
            IRhinoObject obj          = null;

            for (obj = it.First(); null != obj; obj = it.Next())
            {
                if (name.Equals(obj.Attributes().m_name, StringComparison.OrdinalIgnoreCase))
                {
                    obj.Select(true, true, true);
                    num_selected++;
                }
            }

            if (0 == num_selected)
            {
                RhUtil.RhinoApp().Print("0 objects selected\n");
            }
            else if (1 == num_selected)
            {
                RhUtil.RhinoApp().Print("1 object selected\n");
            }
            else
            {
                RhUtil.RhinoApp().Print(string.Format("{0} objects selected\n", num_selected));
            }

            if (0 < num_selected)
            {
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            string path  = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            int    count = 0;

            context.m_doc.UnselectAll();

            MRhinoObjectIterator it = new MRhinoObjectIterator(
                IRhinoObjectIterator.object_state.normal_objects,
                IRhinoObjectIterator.object_category.active_objects
                );

            IRhinoObject obj = null;

            for (obj = it.First(); null != obj; obj = it.Next())
            {
                if (obj.IsSolid())
                {
                    IOn.object_type type = obj.ObjectType();
                    if (type == IOn.object_type.surface_object || type == IOn.object_type.brep_object)
                    {
                        obj.Select(true);

                        string fname  = string.Format("{0}\\rhino_sat_export_{1}.sat", path, count++);
                        string script = string.Format("_-Export \"{0}\" Inventor _Enter", fname);
                        RhUtil.RhinoApp().RunScript(script, 1);

                        obj.Select(false);
                    }
                }
            }

            context.m_doc.Redraw();


            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            int    nValue = _nValue;
            double dValue = _dValue;

            MRhinoGetObject go = new MRhinoGetObject();

            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.EnableGroupSelect(true);
            go.EnableSubObjectSelect(false);
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.EnableDeselectAllBeforePostSelect(false);

            bool bHavePreselectedObjects = false;

            for (; ;)
            {
                go.ClearCommandOptions();

                int dOptionIndex = go.AddCommandOptionNumber(
                    new MRhinoCommandOptionName("Double"),
                    new MRhinoGet.DoubleOption(dValue),
                    "Double value", false, 0.1, 99.9
                    );

                int nOptionIndex = go.AddCommandOptionInteger(
                    new MRhinoCommandOptionName("Integer"),
                    new MRhinoGet.IntegerOption(nValue),
                    "Integer value", 1, 99
                    );

                IRhinoGet.result res = go.GetObjects(1, 0);

                if (res == IRhinoGet.result.option)
                {
                    IRhinoCommandOption commandOption = go.Option();
                    if (null != commandOption)
                    {
                        int optionIndex = commandOption.m_option_index;
                        if (optionIndex == nOptionIndex)
                        {
                            nValue = (int)commandOption.m_number_option_value;
                        }
                        else if (optionIndex == dOptionIndex)
                        {
                            dValue = commandOption.m_number_option_value;
                        }
                    }

                    go.EnablePreSelect(false);
                    continue;
                }

                else if (res != IRhinoGet.result.@object)
                {
                    return(IRhinoCommand.result.cancel);
                }

                if (go.ObjectsWerePreSelected())
                {
                    bHavePreselectedObjects = true;
                    go.EnablePreSelect(false);
                    continue;
                }

                break;
            }

            if (bHavePreselectedObjects)
            {
                // Normally, pre-selected objects will remain selected, when a
                // command finishes, and post-selected objects will be unselected.
                // This this way of picking, it is possible to have a combination
                // of pre-selected and post-selected. So, to make sure everything
                // "looks the same", lets unselect everything before finishing
                // the command.
                for (int i = 0; i < go.ObjectCount(); i++)
                {
                    IRhinoObject rhinoObject = go.Object(i).Object();
                    if (null != rhinoObject)
                    {
                        rhinoObject.Select(false);
                    }
                }
                context.m_doc.Redraw();
            }

            int objectCount = go.ObjectCount();

            _dValue = dValue;
            _nValue = nValue;

            RhUtil.RhinoApp().Print(string.Format("Select object count = {0}\n", objectCount));
            RhUtil.RhinoApp().Print(string.Format("Value of double = {0}\n", _dValue));
            RhUtil.RhinoApp().Print(string.Format("Value of integer = {0}\n", _nValue));

            return(IRhinoCommand.result.success);
        }