Пример #1
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView rhino_view = RhUtil.RhinoApp().ActiveView();

            if (null == rhino_view)
            {
                return(IRhinoCommand.result.failure);
            }

            On3dmView view = new On3dmView(rhino_view.ActiveViewport().View());

            view.m_wallpaper_image.Default();
            _saved_views.Push(view);

            int count = _saved_views.Count;

            if (1 == count)
            {
                RhUtil.RhinoApp().Print("The saved view stack has 1 entry.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print(string.Format("The saved view stack has {0} entries.\n", count));
            }

            return(IRhinoCommand.result.success);
        }
Пример #2
0
        public override bool ExecConduit(ref MRhinoDisplayPipeline dp, uint nChannel, ref bool bTerminate)
        {
            if (nChannel == MSupportChannels.SC_DRAWOVERLAY)
            {
                if (null != m_brep)
                {
                    MRhinoViewport vp          = dp.GetRhinoVP();
                    OnColor        saved_color = vp.SetDrawColor(RhUtil.RhinoApp().AppSettings().TrackingColor());
                    for (int i = 0; i < m_points.Count(); i++)
                    {
                        if (i % 100 == 0 && vp.InterruptDrawing())
                        {
                            break;
                        }

                        On3dPoint  pt  = m_points[i];
                        On3dVector dir = new On3dVector(m_normals[i]);
                        if (m_bFlip)
                        {
                            dir.Reverse();
                        }

                        vp.DrawDirectionArrow(pt, dir);
                    }
                    vp.SetDrawColor(saved_color);
                }
            }
            return(true);
        }
Пример #3
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MArgsRhinoGetCircle args   = new MArgsRhinoGetCircle();
            OnCircle            circle = new OnCircle();

            IRhinoCommand.result rc = RhUtil.RhinoGetCircle(args, ref circle);
            if (rc != IRhinoCommand.result.success)
            {
                return(rc);
            }

            SampleCsDrawCircleConduit conduit = new SampleCsDrawCircleConduit(circle);

            conduit.Enable();
            context.m_doc.Redraw();

            MRhinoGetString gs = new MRhinoGetString();

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

            conduit.Disable();
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #4
0
        /// <summary>
        /// Add an array of 3-D points to the document
        /// </summary>
        public object AddPoints(object pointsObj)
        {
            On3dPointArray points = new On3dPointArray();

            if (SampleCsRhinoScriptUtils.ConvertToOn3dPointArray(pointsObj, ref points))
            {
                MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();
                if (null != doc)
                {
                    ArrayList objectIds = new ArrayList();
                    for (int i = 0; i < points.Count(); i++)
                    {
                        MRhinoObject rhinoObj = doc.AddPointObject(points[i]);
                        if (null != rhinoObj)
                        {
                            objectIds.Add(rhinoObj.ModelObjectId().ToString());
                        }
                    }
                    if (objectIds.Count > 0)
                    {
                        doc.Redraw();
                        return(objectIds.ToArray());
                    }
                }
            }
            return(null);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            Rhino3dPointList points = new Rhino3dPointList();

            points.Add(new On3dPoint(0, 0, 0));
            points.Add(new On3dPoint(0, 0, 1));
            points.Add(new On3dPoint(0, 1, 0));
            points.Add(new On3dPoint(0, 1, 1));
            points.Add(new On3dPoint(1, 0, 0));
            points.Add(new On3dPoint(1, 0, 1));
            points.Add(new On3dPoint(1, 1, 0));
            points.Add(new On3dPoint(1, 1, 1));

            RhUtil.RhinoApp().Print("Before sort...\n");
            points.Print();

            points.Sort(Rhino3dPointList.sort_method.sort_xyz, true);
            RhUtil.RhinoApp().Print("Sort ascending...\n");
            points.Print();

            points.Sort(Rhino3dPointList.sort_method.sort_xyz, false);
            RhUtil.RhinoApp().Print("Sort descending...\n");
            points.Print();

            context.m_doc.AddPointCloudObject(points.ToPointArray());
            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)
        {
            SampleCsDragDropForm form = new SampleCsDragDropForm();

            form.Show(RhUtil.RhinoApp().MainWnd());
            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);
        }
        ///<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 two surfaces or polysurfacs to intersect");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(2, 2);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnBrep B0 = go.Object(0).Brep();
            IOnBrep B1 = go.Object(1).Brep();

            if (null == B0 || null == B1)
            {
                return(IRhinoCommand.result.failure);
            }

            OnCurve[]      curves = null;
            On3dPointArray points = null;
            bool           rc     = RhUtil.RhinoIntersectBreps(B0, B1, context.m_doc.AbsoluteTolerance(), out curves, out points);

            if (
                false == rc ||
                null == curves ||
                0 == curves.Length ||
                null == points ||
                0 == curves.Length
                )
            {
                RhUtil.RhinoApp().Print("No intersections found.\n");
                return(IRhinoCommand.result.nothing);
            }

            if (null != curves)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    context.m_doc.AddCurveObject(curves[i]);
                }
            }

            if (null != points)
            {
                for (int i = 0; i < points.Count(); i++)
                {
                    context.m_doc.AddPointObject(points[i]);
                }
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #9
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)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select object");
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref = go.Object(0);
            IRhinoObject obj     = obj_ref.Object();

            if (null == obj)
            {
                return(IRhinoCommand.result.failure);
            }

            // 1.) Try the object test
            RhUtil.RhinoApp().Print("Object Test: ");
            if (IsLeader(obj))
            {
                RhUtil.RhinoApp().Print("object is a leader.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print("object is not a leader.\n");
            }

            // 2.) Try the GUID test
            RhUtil.RhinoApp().Print("GUID Test: ");
            if (IsLeader(obj.Attributes().m_uuid))
            {
                RhUtil.RhinoApp().Print("object is a leader.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print("object is not a leader.\n");
            }

            // 3.) Try the geometry test
            RhUtil.RhinoApp().Print("Geometry Test: ");
            if (IsLeader(obj_ref.Geometry()))
            {
                RhUtil.RhinoApp().Print("object is a leader.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print("object is not a leader.\n");
            }

            return(IRhinoCommand.result.success);
        }
Пример #11
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null == view)
            {
                return(IRhinoCommand.result.failure);
            }

            MRhinoViewport             vp = view.ActiveViewport();
            MRhinoDisplayPipeline      dp = view.DisplayPipeline();
            MDisplayPipelineAttributes da = view.DisplayAttributes();

            // Prevent capturing of the frame buffer on every update
            MRhinoDisplayPipeline.EnableFrameBufferCapture(false);
            // Prevent the draw list from updating on every frame
            dp.FreezeDrawing(true);

            int    dir         = 0; // 0 = Right, 1 = Left, 2 = Down, and 3 = Up
            int    frame_count = 100;
            double delta_angle = 5.0 * (Math.PI / 180.0);

            for (int i = 0; i < frame_count; i++)
            {
                switch (dir)
                {
                case 0:
                    vp.LeftRightRotate(delta_angle);
                    break;

                case 1:
                    vp.LeftRightRotate(-delta_angle);
                    break;

                case 2:
                    vp.DownUpRotate(delta_angle);
                    break;

                case 3:
                    vp.DownUpRotate(-delta_angle);
                    break;
                }
                //dp.DrawFrameBuffer(da);
                view.Redraw();
                RhUtil.RhinoApp().Wait(0);
            }

            dp.FreezeDrawing(false);
            MRhinoDisplayPipeline.EnableFrameBufferCapture(true);

            view.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #12
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            EstimatorPlugIn          plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn;
            Dictionary <string, int> map    = new Dictionary <string, int>();

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

            foreach (MRhinoObject obj in it)
            {
                string[] string_array = null;
                if (0 == EstimatorHelpers.GetData(obj, ref string_array))
                {
                    continue;
                }

                for (int i = 0; i < string_array.Length; i++)
                {
                    string tag   = string_array[i];
                    int    index = plugin.m_tag_table.FindTag(tag);
                    if (index >= 0)
                    {
                        if (plugin.m_tag_table.Tag(index).Type() == EstimatorTag.tag_type.item_tag)
                        {
                            if (!map.ContainsKey(tag))
                            {
                                map.Add(tag, 1);
                            }
                            else
                            {
                                map[tag]++;
                            }
                        }
                    }
                }
            }

            if (map.Count > 0)
            {
                foreach (KeyValuePair <string, int> kvp in map)
                {
                    RhUtil.RhinoApp().Print(String.Format("Item = {0}, Count = {1}\n", kvp.Key, kvp.Value));
                }
            }
            else
            {
                RhUtil.RhinoApp().Print("No Estimator item tag data found.\n");
            }


            return(IRhinoCommand.result.success);
        }
Пример #13
0
            public VoxelGrid(RhCommon_Scene ModelSurfaces, List <IOn3dPoint> Pts, int VG_Domain)
            {
                VoxelCT        = VG_Domain;
                VoxelInventory = new List <int> [VoxelCT, VoxelCT, VoxelCT];
                Voxel          = new List <On3dPoint> [VoxelCT, VoxelCT, VoxelCT];
                IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()];

                OnBoundingBox  TightOBox = new OnBoundingBox();
                On3dPoint      BoxMin    = new On3dPoint();
                On3dPoint      BoxMax    = new On3dPoint();
                ArrayOn3dPoint Points    = new ArrayOn3dPoint();

                for (int i = 0; i < Pts.Count; i++)
                {
                    Points.Append(Pts[i]);
                }

                RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null);
                TightOBox.Set(Points, true);
                OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1));

                this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT;
                this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT;
                this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT;

                //For((int XBox = 0; XBox < VoxelCT; XBox++)
                Parallel.For(0, VoxelCT, XBox =>
                {
                    RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT - 1, 2) * 100));
                    for (int YBox = 0; YBox < VoxelCT; YBox++)
                    {
                        for (int ZBox = 0; ZBox < VoxelCT; ZBox++)
                        {
                            BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10);
                            BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10);
                            this.Voxel[XBox, YBox, ZBox] = new List <On3dPoint>();
                            this.Voxel[XBox, YBox, ZBox].Add(BoxMin);
                            this.Voxel[XBox, YBox, ZBox].Add(BoxMax);
                            this.VoxelInventory[XBox, YBox, ZBox] = new List <int>();
                            for (int Index = 0; Index < ModelSurfaces.Count(); Index++)
                            {
                                OnBoundingBox TestBox = new OnBoundingBox();
                                TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]);
                                if (BoxIntersection(ModelSurfaces, TestBox, Index))
                                {
                                    this.VoxelInventory[XBox, YBox, ZBox].Add(Index);
                                }
                            }
                        }
                    }
                });
            }
        /// <summary>
        /// This gets called when when the user runs this command.
        /// </summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            if (null != _form)
            {
                return(IRhinoCommand.result.nothing);
            }

            _form             = new SampleCsForm();
            _form.FormClosed += new FormClosedEventHandler(SampleCsForm_FormClosed);
            _form.Show(RhUtil.RhinoApp().MainWnd());

            return(IRhinoCommand.result.success);
        }
        private void m_listbox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (m_bInEvent)
            {
                return;
            }

            m_bInSelect = true;
            MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();

            // Select what got selected
            ListBox.SelectedIndexCollection selected = m_listbox.SelectedIndices;

            // Select what got selected
            int i = 0;

            for (i = 0; i < selected.Count; i++)
            {
                int index = selected[i];
                if (!m_selected.Contains(index))
                {
                    Guid         guid = new Guid(m_listbox.Items[index].ToString());
                    MRhinoObject obj  = doc.LookupObject(guid);
                    if (obj != null && obj.IsSelectable())
                    {
                        obj.Select(true);
                    }
                }
            }

            // Unselect what got unselected
            for (i = 0; i < m_selected.Count; i++)
            {
                int index = m_selected[i];
                if (!selected.Contains(index))
                {
                    Guid         guid = new Guid(m_listbox.Items[index].ToString());
                    MRhinoObject obj  = doc.LookupObject(guid);
                    if (obj != null)
                    {
                        obj.Select(false);
                    }
                }
            }

            SaveSelectedIndices();
            doc.Redraw();

            m_bInSelect = false;
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            OnLine  line  = new OnLine();
            OnPlane plane = new OnPlane();

            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Start of line");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            line.from = gp.Point();
            plane     = new OnPlane(RhUtil.RhinoActiveCPlane());
            plane.SetOrigin(line.from);

            gp.SetCommandPrompt("End of line");
            gp.Constrain(plane);
            gp.SetBasePoint(line.from);
            gp.DrawLineFromPoint(line.from, true);
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            line.to = plane.ClosestPointTo(gp.Point());
            if (!line.IsValid())
            {
                return(IRhinoCommand.result.nothing);
            }

            SampleCsDrawArrowheadConduit conduit = new SampleCsDrawArrowheadConduit(plane, line, 1.0);

            conduit.Enable();
            context.m_doc.Redraw();

            MRhinoGetString gs = new MRhinoGetString();

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

            conduit.Disable();
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #17
0
            /// <summary>
            /// Intesects all NURBS Surfaces with Voxels.
            /// </summary>
            /// <param name="Model">the scene.</param>
            /// <param name="Box">the voxel</param>
            /// <param name="Index">the index of the surface to test.</param>
            /// <returns></returns>
            private bool BoxIntersection(RhCommon_Scene Model, OnBoundingBox Box, int Index)
            {
                On3dPoint Center = Box.Center();
                double    Radius = Center.DistanceTo(Box.Min());
                double    s      = 0;
                double    t      = 0;
                On3dPoint point  = new On3dPoint();

                if (RhUtil.RhinoBrepClosestPoint(Model.Brep(Index), Center, new OnCOMPONENT_INDEX(), ref s, ref t, point, Radius))
                //if (Center.DistanceTo(point) < Radius)
                {
                    return(true);
                }
                return(false);
            }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView[] view_list = null;
            context.m_doc.GetViewList(ref view_list, true, false);
            if (null == view_list)
            {
                return(IRhinoCommand.result.failure);
            }

            foreach (MRhinoView view in view_list)
            {
                RhUtil.RhinoDollyExtentsSelected(view, true);
            }

            return(IRhinoCommand.result.success);
        }
Пример #19
0
 ///<summary> This gets called when when the user runs this command.</summary>
 public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 {
     for (int i = 0; ; i++)
     {
         IOn3dmConstructionPlane cplane = context.m_doc.Properties().NamedConstructionPlane(i);
         if (null == cplane)
         {
             break;
         }
         else
         {
             RhUtil.RhinoApp().Print(string.Format("Named CPlane {0} = {1}\n", i, cplane.m_name));
         }
     }
     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 surface");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnSurface srf = go.Object(0).Surface();

            if (null == srf)
            {
                return(IRhinoCommand.result.failure);
            }

            IOnNurbsSurface ns = srf.NurbsSurface();

            if (null == ns)
            {
                RhUtil.RhinoApp().Print("Not a NURBS surface.\n");
                return(IRhinoCommand.result.nothing);
            }

            On3dPoint cv  = new On3dPoint();
            string    str = string.Empty;

            for (int u = 0; u < ns.CVCount(0); u++)
            {
                for (int v = 0; v < ns.CVCount(1); v++)
                {
                    if (ns.GetCV(u, v, ref cv))
                    {
                        str = string.Empty;
                        RhUtil.RhinoFormatPoint(cv, ref str);
                        RhUtil.RhinoApp().Print(string.Format("CV({0},{1}) = {2}\n", u, v, str));
                    }
                }
            }

            return(IRhinoCommand.result.success);
        }
Пример #21
0
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoObjectIterator it = new MRhinoObjectIterator(
                IRhinoObjectIterator.object_state.undeleted_objects,
                IRhinoObjectIterator.object_category.active_and_reference_objects
                );

            for (MRhinoObject obj = it.First(); null != obj; obj = it.Next())
            {
                obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, false);
            }

            context.m_doc.Redraw();
            RhUtil.RhinoApp().Print("Z-Analysis is off.\n");

            return(IRhinoCommand.result.success);
        }
Пример #22
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null != view)
            {
                int left = 0, right = 0, bottom = 0, top = 0;
                view.ActiveViewport().VP().GetScreenPort(ref left, ref right, ref bottom, ref top);

                string name   = view.ActiveViewport().Name();
                int    width  = right - left;
                int    height = bottom - top;
                RhUtil.RhinoApp().Print(string.Format("Name = {0}: Width = {1}, Height = {2}\n", name, width, height));
            }

            return(IRhinoCommand.result.cancel);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null != view)
            {
                // 1/2 of smallest subtended view angle
                double half_smallest_angle = 0.0;
                if (view.ActiveViewport().VP().GetCameraAngle(ref half_smallest_angle))
                {
                    string fov = string.Empty;
                    RhUtil.RhinoFormatNumber(half_smallest_angle * (180.0 / OnUtil.On_PI), ref fov);
                    RhUtil.RhinoApp().Print(string.Format("Field of view =  {0} degrees.\n", fov));
                }
            }
            return(IRhinoCommand.result.success);
        }
Пример #24
0
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects for Z analysis");
            go.SetGeometryFilter(
                IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object |
                IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object |
                IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object
                );
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            int count = 0;

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

                if (obj.InAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID))
                {
                    // This object is already in Z analysis mode
                    continue;
                }

                if (obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, true))
                {
                    // A new object is in Z analysis mode
                    count++;
                }
            }

            context.m_doc.Redraw();
            RhUtil.RhinoApp().Print(string.Format("{0} objects were put into Z-Analysis mode.\n", count));

            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 rectangular light");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            IOnLight light = go.Object(0).Light();

            if (null == light)
            {
                return(IRhinoCommand.result.failure);
            }

            if (!light.IsRectangularLight())
            {
                RhUtil.RhinoApp().Print("Not a rectangular light.\n");
                return(IRhinoCommand.result.nothing);
            }

            On3dPoint  origin = light.Location();
            On3dVector xaxis  = light.Length();
            On3dVector yaxis  = light.Width();

            OnPlane    plane      = new OnPlane(origin, xaxis, yaxis);
            OnInterval x_interval = new OnInterval(0.0, xaxis.Length());
            OnInterval y_interval = new OnInterval(0.0, yaxis.Length());

            OnMesh mesh = RhUtil.RhinoMeshPlane(plane, x_interval, y_interval, 2, 2);

            if (null != mesh)
            {
                mesh.ConvertQuadsToTriangles();
                context.m_doc.AddMeshObject(mesh);
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.cancel);
        }
Пример #26
0
        /// <summary>
        /// Add a 3-D point to the document
        /// </summary>
        public object AddPoint(object pointObj)
        {
            On3dPoint point = new On3dPoint();

            if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointObj, ref point))
            {
                MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();
                if (null != doc)
                {
                    MRhinoObject rhinoObj = doc.AddPointObject(point);
                    if (null != rhinoObj)
                    {
                        doc.Redraw();
                        return(rhinoObj.ModelObjectId().ToString());
                    }
                }
            }
            return(null);
        }
Пример #27
0
        /// <summary>
        /// This method is called when the drag and drop operation is completed and
        /// the item being dragged was dropped on a valid, top level Rhino object.
        /// </summary>
        public override bool OnDropOnObject(IRhinoObjRef objRef, MRhinoView rhinoView, DataObject data, DragDropEffects dropEffect, Point point)
        {
            SampleCsDragData dragData = GetSampleCsDragData(data);

            if (null == dragData)
            {
                return(false);
            }

            MessageBox.Show(
                RhUtil.RhinoApp().MainWnd(),
                "String \"" + dragData.DragString + "\" Dropped on object",
                "SampleCsDragDrop",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information
                );

            return(true);
        }
Пример #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Since our form is modeless, the user can run commands
            // while our form is visible, including the Open command,
            // which closes the current document and opens a new one.
            // Thus, it's best to always ask for the active document
            // instead of maintaining a reference to the document passed
            // to the command that created this form.
            MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc();

            if (null != doc)
            {
                On3dPoint a    = new On3dPoint(0.0, 0.0, 0.0);
                On3dPoint b    = new On3dPoint(5.0, 5.0, 5.0);
                OnLine    line = new OnLine(a, b);
                doc.AddCurveObject(line);
                doc.Redraw();
            }
        }
Пример #29
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            On3dPoint        center   = new On3dPoint(OnUtil.On_origin);
            OnSphere         sphere   = new OnSphere(center, 5.0);
            OnMesh           mesh     = RhUtil.RhinoMeshSphere(sphere, 10, 10);
            MRhinoMeshObject mesh_obj = context.m_doc.AddMeshObject(mesh);

            context.m_doc.Redraw();

            MRhinoGetString gs = new MRhinoGetString();

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

            context.m_doc.DeleteObject(new MRhinoObjRef(mesh_obj));
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #30
0
        ///<summary>
        /// This gets called when when the user runs this command.
        ///</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetFileDialog dlg = new MRhinoGetFileDialog();

            if (dlg.DisplayFileDialog(IRhinoGetFileDialog.file_dialog_type.open_text_file_dialog))
            {
                string filename = dlg.FileName();
                string line     = "";
                RhUtil.RhinoApp().Print(string.Format("Opening file {0}.\n", filename));

                char[] delim = new char[2];
                delim[0] = ','; delim[1] = '\0';

                On3dPointArray points = new On3dPointArray(8);

                StreamReader reader = new StreamReader(filename);
                line = reader.ReadLine();

                while (line != null && line.Length > 0)
                {
                    string[] substrs = line.Split(delim);
                    if (substrs.Length == 3)
                    {
                        On3dPoint p = new On3dPoint();
                        p.x = double.Parse(substrs[0]);
                        p.y = double.Parse(substrs[1]);
                        p.z = double.Parse(substrs[2]);
                        points.Append(p);
                    }
                    line = reader.ReadLine();
                }

                OnNurbsCurve curve = RhUtil.RhinoInterpCurve(3, points, null, null, 1);
                context.m_doc.AddCurveObject(curve);
                reader.Close();
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }