コード例 #1
0
        protected void Caputre(string suffix)
        {
            Bitmap bitmap           = RhinoView.CaptureToBitmap(new Size(this.PictWidth, this.PictHeight), false, false, false);
            string numberofMaxFrame = "D" + ((int)this.MaxFrame).ToString().Length.ToString();

            if (bitmap != null)
            {
                string end      = PictTypeItems[Typeindex].ToString().ToLower();
                string filePath = FilePath + "Whale  " + (this.RightFrame).ToString(numberofMaxFrame) + suffix + "." + end;
                bitmap.Save(filePath, PictTypeItems[Typeindex]);
            }
            bitmap.Dispose();
        }
コード例 #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string view_name = "";

            DA.GetData <string>(0, ref view_name);

            string server_msg = "";

            DA.GetData <string>(1, ref server_msg);

            string post = "{\"id\": \"" + screenshot_id + "\"}";

            //if (!active)
            if (Equals(server_msg, "100"))
            {
                string url = "http://127.0.0.1:5000/api/v1.0/ss-register-id";

                Tuple <bool, string> result = Helpers.PostToServer(url, post);
                string message = result.Item2;

                if (!result.Item1)
                {
                    Helpers.Print(DA, "Error:" + message);
                    throw new Exception(message);
                }
                else
                {
                    var serializer = new JavaScriptSerializer();
                    var json       = serializer.Deserialize <ScreenshotMSG>(message);

                    Helpers.Print(DA, json.status);
                    addFileWatcher(DA, json.path);
                }
            }

            if (active)
            {
                RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;

                if (view_name == "")
                {
                    Helpers.Print(DA, "Using active viewport " + view.MainViewport.Name);
                }
                else
                {
                    ViewTable   view_table = Rhino.RhinoDoc.ActiveDoc.Views;
                    RhinoView[] views      = view_table.GetViewList(true, false);

                    bool exists = false;

                    for (int i = 0; i < views.Length; i++)
                    {
                        view = views[i];
                        string vp_name = view.MainViewport.Name;

                        if (string.Equals(vp_name, view_name))
                        {
                            Helpers.Print(DA, "Viewport " + view_name + " found");
                            exists = true;
                            break;
                        }
                    }

                    if (exists)
                    {
                    }
                    else
                    {
                        Helpers.Print(DA, "New viewport " + view_name + " created");
                        Rectangle rec      = new Rectangle(0, 0, 800, 600);
                        RhinoView new_view = view_table.Add(view_name, Rhino.Display.DefinedViewportProjection.Perspective, rec, true);
                        new_view.MainViewport.WorldAxesVisible        = false;
                        new_view.MainViewport.ConstructionGridVisible = false;
                        new_view.MainViewport.ConstructionAxesVisible = false;
                        new_view.MainViewport.DisplayMode             = DisplayModeDescription.FindByName("shaded");

                        view = new_view;
                    }


                    Bitmap bitmap = view.CaptureToBitmap(false, false, false);

                    string url = "http://127.0.0.1:5000/api/v1.0/ss-get-path";

                    Tuple <bool, string> result = Helpers.PostToServer(url, post);
                    string message = result.Item2;

                    if (!result.Item1)
                    {
                        Helpers.Print(DA, "Error:" + message);
                        throw new Exception(message);
                    }
                    else
                    {
                        var serializer = new JavaScriptSerializer();
                        var json       = serializer.Deserialize <ScreenshotMSG>(message);

                        if (string.Equals(json.status, "success"))
                        {
                            string[] components = { json.path, "png" };
                            string   path       = string.Join(".", components);

                            Helpers.Print(DA, "Screenshot captured to: " + path);
                            bitmap.Save(path);
                        }
                        else
                        {
                            Helpers.Print(DA, json.status);
                        }
                    }

                    Helpers.PingServer("http://127.0.0.1:5000/api/v1.0/ss-done");
                }
                //else
                //{
                //    Helpers.Print(DA, screenshot_id + " active.");
                //}

                active = false;
            }
        }