Exemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input String
            string filename = null;
            bool activate = false;
            // 1. Declare placeholder variables and assign initial invalid data.
            //    This way, if the input parameters fail to supply valid data, we know when to abort.

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref filename)) { return; }
            if (!DA.GetData(1, ref activate)) { return; }

            // If the retrieved data is Nothing, we need to abort.
            if (filename == null) { return; }
            if (!File.Exists(filename)) { return; }

            if (activate)
            {
                GH_Cluster cluster = new GH_Cluster();
                cluster.CreateFromFilePath(filename);

                GH_Document doc = OnPingDocument();
                doc.AddObject(cluster, false);
             }
        }
Exemplo n.º 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input String
            string filename = null;
            bool activate = false;
            Rhino.Geometry.Point3d point = Rhino.Geometry.Point3d.Unset;
            // 1. Declare placeholder variables and assign initial invalid data.
            //    This way, if the input parameters fail to supply valid data, we know when to abort.

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref filename)) { return; }
            if (!DA.GetData(1, ref activate)) { return; }
            if (!DA.GetData(2, ref point)) { return; }

            // If the retrieved data is Nothing, we need to abort.
            if (filename == null) { return; }
            if (!File.Exists(filename)) { return; }

            if (activate)
            {
                GH_Cluster cluster = new GH_Cluster();
                cluster.CreateFromFilePath(filename);

                GH_Document doc = OnPingDocument();
                doc.AddObject(cluster, false);

                Grasshopper.Kernel.Parameters.Param_Point paramIn = new Grasshopper.Kernel.Parameters.Param_Point();
                Grasshopper.Kernel.Parameters.Param_Geometry paramOut = new Grasshopper.Kernel.Parameters.Param_Geometry();

                paramIn.SetPersistentData(point);

                cluster.Params.RegisterInputParam(paramIn);
                cluster.Params.RegisterOutputParam(paramOut);

                cluster.CollectData();

                cluster.ComputeData();

                //Grasshopper.DataTree<object> test = new DataTree<object>();
                //test.Add(paramIn, 0);

                DA.SetData(1, paramOut);

            }
        }
Exemplo n.º 3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input String
            string filename = null;
            bool   activate = false;

            // 1. Declare placeholder variables and assign initial invalid data.
            //    This way, if the input parameters fail to supply valid data, we know when to abort.

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref filename))
            {
                return;
            }
            if (!DA.GetData(1, ref activate))
            {
                return;
            }

            // If the retrieved data is Nothing, we need to abort.
            if (filename == null)
            {
                return;
            }
            if (!File.Exists(filename))
            {
                return;
            }

            if (activate)
            {
                GH_Cluster cluster = new GH_Cluster();
                cluster.CreateFromFilePath(filename);

                GH_Document doc = OnPingDocument();
                doc.AddObject(cluster, false);
            }
        }
Exemplo n.º 4
0
        public void InitCluster()
        {
            debugText = "";

            // if we had a previous document, then let's delete it and start over
            if (wormDoc != null)
            {
                wormDoc.Enabled = false;
                wormDoc.RemoveObject(wormCluster, false);
                wormDoc.Dispose();
                wormDoc = null;
            }

            ////////////////////////
            // get clusterFileURL param again, since inputs may not have run if invalid
            ////////////////////////
            string clusterName = Params.Input[0].VolatileData.get_Branch(0)[0].ToString();

            ////////////////////////
            // get clustername and process/validate into URL
            ////////////////////////
            string clusterUrl = processValidateClusterName(clusterName);


            ////////////////////////
            // set path for temporary file location
            ////////////////////////
            string tempPath = System.IO.Path.GetTempPath();
            Uri    uri      = new Uri(clusterUrl);
            string filename = System.IO.Path.GetFileName(uri.LocalPath);

            fullTempFilePath = tempPath + filename;

            ////////////////////////
            // attempt to downloadCluster file
            ////////////////////////

            using (WebClient Client = new WebClient())
            {
                try {
                    Client.DownloadFile(clusterUrl, fullTempFilePath);
                }
                catch (WebException webEx)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Network error: " + webEx.Message);
                }
            }
            debugText += "Downloaded file " + clusterUrl + ", " + filename + "\n";
            debugText += "into " + fullTempFilePath + "\n";

            // if gh file doesn't exist in temporary location, abort
            if (!File.Exists(fullTempFilePath))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "File does not exist!");
            }

            ////////////////////////
            // Create a cluster
            ////////////////////////

            // create cluster
            wormCluster = new GH_Cluster();
            wormCluster.CreateFromFilePath(fullTempFilePath);

            // set cluster parameter count
            clusterParamNumInput  = wormCluster.Params.Input.Count;
            clusterParamNumOutput = wormCluster.Params.Output.Count;
            debugText            += "\ncluster input params # = " + clusterParamNumInput;
            debugText            += "\ncluster output params # = " + clusterParamNumOutput;

            // add/remove/rename parameters to match cluster parameter count.
            MatchParameterCount();

            // change hairworm name to match cluster name
            if (wormCluster.Name == "Cluster")
            {
                HairwormClusterName     = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
                HairwormClusterNickName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
            }
            else
            {
                HairwormClusterName     = wormCluster.Name;
                HairwormClusterNickName = wormCluster.NickName;
            }
            Name       = HairwormBaseName + " (" + HairwormClusterName + ")";
            NickName   = HairwormBaseName + " (" + this.HairwormClusterNickName + ")";
            debugText += "cluster is named = " + wormCluster.Name;
            debugText += "cluster is nicknamed = " + wormCluster.NickName;

            //get new document, enable it, and add cluster to it
            wormDoc         = new GH_Document();
            wormDoc.Enabled = true;
            wormDoc.AddObject(wormCluster, true, 0);

            // loading cluster worked. (it's important that this is almost last, because MatchParameterCount scans this to know when to disconnect params)
            loadedClusterUrlParam = clusterUrlParam;

            ExpireSolution(true);
        }
Exemplo n.º 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input String
            string filename = null;
            bool   activate = false;

            Rhino.Geometry.Point3d point = Rhino.Geometry.Point3d.Unset;
            // 1. Declare placeholder variables and assign initial invalid data.
            //    This way, if the input parameters fail to supply valid data, we know when to abort.

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref filename))
            {
                return;
            }
            if (!DA.GetData(1, ref activate))
            {
                return;
            }
            if (!DA.GetData(2, ref point))
            {
                return;
            }

            // If the retrieved data is Nothing, we need to abort.
            if (filename == null)
            {
                return;
            }
            if (!File.Exists(filename))
            {
                return;
            }

            if (activate)
            {
                GH_Cluster cluster = new GH_Cluster();
                cluster.CreateFromFilePath(filename);

                GH_Document doc = OnPingDocument();
                doc.AddObject(cluster, false);

                Grasshopper.Kernel.Parameters.Param_Point    paramIn  = new Grasshopper.Kernel.Parameters.Param_Point();
                Grasshopper.Kernel.Parameters.Param_Geometry paramOut = new Grasshopper.Kernel.Parameters.Param_Geometry();

                paramIn.SetPersistentData(point);

                cluster.Params.RegisterInputParam(paramIn);
                cluster.Params.RegisterOutputParam(paramOut);

                cluster.CollectData();

                cluster.ComputeData();


                //Grasshopper.DataTree<object> test = new DataTree<object>();
                //test.Add(paramIn, 0);



                DA.SetData(1, paramOut);
            }
        }
        public void InitCluster()
        {
            debugText = "";

            // if we had a previous document, then let's delete it and start over
            if (wormDoc != null)
            {
                wormDoc.Enabled = false;
                wormDoc.RemoveObject(wormCluster, false);
                wormDoc.Dispose();
                wormDoc = null;
            }

            ////////////////////////
            // get clusterFileURL param again, since inputs may not have run if invalid
            ////////////////////////
            string clusterName = Params.Input[0].VolatileData.get_Branch(0)[0].ToString();

            ////////////////////////
            // get clustername and process/validate into URL
            ////////////////////////
            string clusterUrl = processValidateClusterName(clusterName);

            ////////////////////////
            // set path for temporary file location
            ////////////////////////
            string tempPath = System.IO.Path.GetTempPath();
            Uri uri = new Uri(clusterUrl);
            string filename = System.IO.Path.GetFileName(uri.LocalPath);
            fullTempFilePath = tempPath + filename;

            ////////////////////////
            // attempt to downloadCluster file
            ////////////////////////

            using (WebClient Client = new WebClient())
            {
                try {
                    Client.DownloadFile(clusterUrl, fullTempFilePath);
                }
                catch(WebException webEx)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Network error: " + webEx.Message);

                }
            }
            debugText += "Downloaded file " + clusterUrl + ", " + filename + "\n";
            debugText += "into " + fullTempFilePath + "\n";

            // if gh file doesn't exist in temporary location, abort
            if (!File.Exists(fullTempFilePath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "File does not exist!"); }

            ////////////////////////
            // Create a cluster
            ////////////////////////

            // create cluster
            wormCluster = new GH_Cluster();
            wormCluster.CreateFromFilePath(fullTempFilePath);

            // set cluster parameter count
            clusterParamNumInput = wormCluster.Params.Input.Count;
            clusterParamNumOutput = wormCluster.Params.Output.Count;
            debugText += "\ncluster input params # = " + clusterParamNumInput;
            debugText += "\ncluster output params # = " + clusterParamNumOutput;

            // add/remove/rename parameters to match cluster parameter count.
            MatchParameterCount();

            // change hairworm name to match cluster name
            if(wormCluster.Name == "Cluster") {
                HairwormClusterName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
                HairwormClusterNickName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
            } else {
                HairwormClusterName = wormCluster.Name;
                HairwormClusterNickName = wormCluster.NickName;
            }
            Name = HairwormBaseName + " (" + HairwormClusterName + ")";
            NickName = HairwormBaseName + " (" + this.HairwormClusterNickName + ")";
            debugText += "cluster is named = " + wormCluster.Name;
            debugText += "cluster is nicknamed = " + wormCluster.NickName;

            //get new document, enable it, and add cluster to it
            wormDoc = new GH_Document();
            wormDoc.Enabled = true;
            wormDoc.AddObject(wormCluster, true, 0);

            // loading cluster worked. (it's important that this is almost last, because MatchParameterCount scans this to know when to disconnect params)
            loadedClusterUrlParam = clusterUrlParam;

            ExpireSolution(true);
        }