///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select solid meshes for volume calculation");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
            go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh);
            go.EnableSubObjectSelect(false);
            go.EnableGroupSelect();
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            List <IOnMesh> meshes = new List <IOnMesh>();

            for (int i = 0; i < go.ObjectCount(); i++)
            {
                IOnMesh mesh = go.Object(i).Mesh();
                if (mesh != null)
                {
                    meshes.Add(mesh);
                }
            }
            if (meshes.Count == 0)
            {
                return(IRhinoCommand.result.nothing);
            }

            OnBoundingBox bbox = new OnBoundingBox();

            for (int i = 0; i < meshes.Count; i++)
            {
                meshes[i].GetBoundingBox(ref bbox, 1);
            }
            On3dPoint base_point = bbox.Center();

            double total_volume         = 0.0;
            double total_error_estimate = 0.0;
            string msg;

            for (int i = 0; i < meshes.Count; i++)
            {
                double error_estimate = 0.0;
                double volume         = meshes[i].Volume(base_point, ref error_estimate);
                msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate);
                RhUtil.RhinoApp().Print(msg);
                total_volume         += volume;
                total_error_estimate += error_estimate;
            }

            msg = string.Format("Total volume = {0:f} (+/- {1:f})\n",
                                total_volume,
                                total_error_estimate);
            RhUtil.RhinoApp().Print(msg);

            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select solid meshes for volume calculation");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
              go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh);
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect();
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              List<IOnMesh> meshes = new List<IOnMesh>();
              for (int i = 0; i < go.ObjectCount(); i++)
              {
            IOnMesh mesh = go.Object(i).Mesh();
            if (mesh != null)
              meshes.Add(mesh);
              }
              if (meshes.Count == 0)
            return IRhinoCommand.result.nothing;

              OnBoundingBox bbox = new OnBoundingBox();
              for (int i = 0; i < meshes.Count; i++)
            meshes[i].GetBoundingBox(ref bbox, 1);
              On3dPoint base_point = bbox.Center();

              double total_volume = 0.0;
              double total_error_estimate = 0.0;
              string msg;
              for (int i = 0; i < meshes.Count; i++)
              {
            double error_estimate = 0.0;
            double volume = meshes[i].Volume(base_point, ref error_estimate);
            msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate);
            RhUtil.RhinoApp().Print(msg);
            total_volume += volume;
            total_error_estimate += error_estimate;
              }

              msg = string.Format("Total volume = {0:f} (+/- {1:f})\n",
                          total_volume,
                          total_error_estimate);
              RhUtil.RhinoApp().Print(msg);

              return IRhinoCommand.result.success;
        }
예제 #3
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            Model.globalContext = context;

            // get file info after it has been loaded into memory.
            Model.txtFilename = context.m_doc.GetPathName();
            Model.txtTitle = context.m_doc.GetTitle();
            //  http://wiki.mcneel.com/developer/sdksamples/meshvolume
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt( "Select solid meshes for volume calculation" );
              go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object );
              go.SetGeometryAttributeFilter( IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh );
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect();
              go.GetObjects( 1, 0 );
              if( go.CommandResult() != IRhinoCommand.result.success )
            return go.CommandResult();

              List<IOnMesh> meshes = new List<IOnMesh>();
              for( int i = 0; i < go.ObjectCount(); i++ )
              {
            IOnMesh mesh = go.Object(i).Mesh();
            if( mesh != null )
              meshes.Add( mesh );
              }
              if( meshes.Count == 0 )
            return IRhinoCommand.result.nothing;

              OnBoundingBox bbox = new OnBoundingBox();
              for( int i = 0; i < meshes.Count; i++ )
            meshes[i].GetBoundingBox( ref bbox, 1 );
              On3dPoint base_point = bbox.Center();

              double total_volume = 0.0;
              double total_error_estimate = 0.0;
              string msg;
              for( int i = 0; i < meshes.Count; i++ )
              {
            double error_estimate = 0.0;
            double volume = meshes[i].Volume( base_point, ref error_estimate );
            msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n",i,volume,error_estimate);
            RhUtil.RhinoApp().Print( msg );
            total_volume += volume;
            total_error_estimate += error_estimate;
              }
              msg = string.Format("Total volume = {0:f} (+/- {1:f})\n",
                      total_volume,
                      total_error_estimate);
              RhUtil.RhinoApp().Print( msg );
              return IRhinoCommand.result.success;

            /*
            System.Guid id = CsDockingDialogDockBar.ID();
              bool bVisible = RMA.UI.MRhinoDockBarManager.IsDockBarVisible(id);

              string prompt;
              if (bVisible)
            prompt = string.Format("{0} window is visible. New value", EnglishCommandName());
              else
            prompt = string.Format("{0} window is hidden. New value", EnglishCommandName());

              MRhinoGetOption go = new MRhinoGetOption();
              go.SetCommandPrompt(prompt);
              int h_option = go.AddCommandOption(new MRhinoCommandOptionName("Hide"));
              int s_option = go.AddCommandOption(new MRhinoCommandOptionName("Show"));
              int t_option = go.AddCommandOption(new MRhinoCommandOptionName("Toggle"));
              go.GetOption();
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoCommandOption opt = go.Option();
              if (opt == null)
            return IRhinoCommand.result.failure;

              int option_index = opt.m_option_index;
              if (h_option == option_index)
              {
            if (bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false);
              }
              else if (s_option == option_index)
              {
            if (!bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false);
              }
              else if (t_option == option_index)
              {
            if (bVisible)
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false);
            else
              RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false);
              }

              return IRhinoCommand.result.success;*/
        }
예제 #4
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to define block");
            go.EnableReferenceObjectSelect(false);
            go.EnableSubObjectSelect(false);
            go.EnableGroupSelect(true);
            // Phantoms, grips, lights, etc., cannot be in instance definitions.
            uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                                    );
            uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;

            go.SetGeometryFilter(geometry_filter);
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Step 2, select base point
            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Block base point");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint base_point = gp.Point();

            // Step 3, get instance definition name
            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Block definition name");
            gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
            gs.GetString();
            if (gs.CommandResult() != IRhinoCommand.result.success)
            {
                return(gs.CommandResult());
            }

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

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

            // Step 4, verify objects
            int found_index             = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
            List <IRhinoObject> objects = new List <IRhinoObject>();

            bool bQuietly = context.IsInteractive() ? false : true;

            for (int i = 0; i < go.ObjectCount(); i++)
            {
                IRhinoObject obj = go.Object(i).Object();
                if (obj == null)
                {
                    continue;
                }

                // Probably don't need to do this...
                if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
                {
                    continue;
                }

                if (obj.ObjectType() == IOn.object_type.instance_reference)
                {
                    IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
                    if (iref_obj != null)
                    {
                        if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
                        {
                            if (!bQuietly)
                            {
                                RhUtil.RhinoApp().Print("Unable to create block.\n");
                            }
                            return(IRhinoCommand.result.failure);
                        }
                    }
                }
                objects.Add(obj);
            }

            // Step 5, create instance definition
            OnInstanceDefinition idef = new OnInstanceDefinition();

            idef.SetName(idef_name);

            int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);

            if (idef_index < 0)
            {
                return(IRhinoCommand.result.failure);
            }

            // Step 6, create the instance reference
            OnXform xform = new OnXform();

            xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
            IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);

            if (inst_obj != null)
            {
                inst_obj.Select(true);
            }
            else
            {
                if (!bQuietly)
                {
                    RhUtil.RhinoApp().Print("Error creating block.\n");
                }
                return(IRhinoCommand.result.failure);
            }

            // Step 7, delete existing geometry
            for (int i = 0; i < objects.Count; i++)
            {
                context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
예제 #5
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects to define block");
              go.EnableReferenceObjectSelect(false);
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect(true);
              // Phantoms, grips, lights, etc., cannot be in instance definitions.
              uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                              );
              uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;
              go.SetGeometryFilter(geometry_filter);
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Step 2, select base point
              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Block base point");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint base_point = gp.Point();

              // Step 3, get instance definition name
              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Block definition name");
              gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
              gs.GetString();
              if (gs.CommandResult() != IRhinoCommand.result.success)
            return gs.CommandResult();

              string idef_name = gs.String().Trim();
              if (string.IsNullOrEmpty(idef_name))
            return IRhinoCommand.result.nothing;

              // Step 4, verify objects
              int found_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
              List<IRhinoObject> objects = new List<IRhinoObject>();

              bool bQuietly = context.IsInteractive() ? false : true;

              for (int i = 0; i < go.ObjectCount(); i++)
              {
            IRhinoObject obj = go.Object(i).Object();
            if (obj == null)
              continue;

            // Probably don't need to do this...
            if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
              continue;

            if (obj.ObjectType() == IOn.object_type.instance_reference)
            {
              IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
              if (iref_obj != null)
              {
            if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
            {
              if (!bQuietly)
                RhUtil.RhinoApp().Print("Unable to create block.\n");
              return IRhinoCommand.result.failure;
            }
              }
            }
            objects.Add(obj);
              }

              // Step 5, create instance definition
              OnInstanceDefinition idef = new OnInstanceDefinition();
              idef.SetName(idef_name);

              int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);
              if (idef_index < 0)
            return IRhinoCommand.result.failure;

              // Step 6, create the instance reference
              OnXform xform = new OnXform();
              xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
              IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);
              if (inst_obj != null)
              {
            inst_obj.Select(true);
              }
              else
              {
            if (!bQuietly)
              RhUtil.RhinoApp().Print("Error creating block.\n");
            return IRhinoCommand.result.failure;
              }

              // Step 7, delete existing geometry
              for (int i = 0; i < objects.Count; i++)
            context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));

              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);
        }
        ///<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;
        }