Exemplo n.º 1
0
 public ImpalaAccess(GH_Component parent)
 {
     component  = parent ?? throw new ArgumentNullException();
     document   = parent.OnPingDocument();
     InputData  = component.Params.Input.Select(p => p.VolatileData).ToArray();
     OutputData = component.Params.Output.Select(p => p.VolatileData).ToArray();
     // Todo - this constructor isn't quite done.
 }
        public static ConvertSettings UpdateSolutionEndEventHandler(this GH_Component gHComponent, ConvertSettings convertSettings = null)
        {
            if (gHComponent == null)
            {
                return(null);
            }

            if (convertSettings == null)
            {
                return(Core.Revit.Query.ConvertSettings());
            }

            GH_Document.SolutionEndEventHandler solutionEndEventHandler = null;

            gHComponent.OnPingDocument().SolutionEnd += solutionEndEventHandler = (sender, args) =>
            {
                (sender as GH_Document).SolutionEnd -= solutionEndEventHandler;
                convertSettings.ClearObjects();
                //gHComponent.Phase = GH_SolutionPhase.Blank;
            };

            return(convertSettings);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This function is resposible for writing python files after
        /// gathering all inputs and outputs in a python-syntax form.
        /// </summary>
        /// <param name="WinForm"></param>
        public void writeReadPythonFile(GH_Component ThisComponent,
                                        PythonShell WinForm,
                                        IGH_DataAccess DA,
                                        int index,
                                        string path)
        {
            string variablesAre = "";
            string foot         = string.Empty;

            /// Section 1
            /// Initiate temporary Python file name that will be executed as well as the temporary folder.
            string name = "PythonFileWritten_" + index.ToString();

            try
            {
                variablesAre = ""; // Collecting the input variables here.

                /// Section 2
                /// Add the output variables' names and initiate them as None.
                for (int i = 0; i < ThisComponent.Params.Output.Count; i++)
                {
                    variablesAre += ThisComponent.Params.Output[i].NickName + @" = None\n";
                }

                /// Section 3.
                /// Collect input data names, and values then initiate them in a python syntax form as : "variableName = varibaleValue \n"
                for (int i = 0; i < ThisComponent.Params.Input.Count; i++)
                {
                    string datahere  = "";
                    string paramType = "";
                    try
                    {
                        paramType = ThisComponent.Params.Input[i].Sources[0].Type.ToString();
                    }
                    catch
                    {
                        paramType = ThisComponent.Params.Input[i].Type.ToString();
                    }

                    // GET input type at first
                    try
                    {
                        if (ThisComponent.Params.Input[i].Access == GH_ParamAccess.list /* &&
                                                                                         * (paramType == "Grasshopper.Kernel.Types.GH_Integer" ||
                                                                                         * paramType == "Grasshopper.Kernel.Types.GH_Number" ||
                                                                                         * paramType == "Grasshopper.Kernel.Types.GH_Boolean")*/)
                        {
                            //MessageBox.Show(ThisComponent.Params.Input[i].VolatileData.DataDescription(false, false));
                            string thisInputString = ThisComponent.Params.Input[i].VolatileData.DataDescription(false, false).
                                                     Trim().Replace(System.Environment.NewLine + System.Environment.NewLine, "],[").Replace(System.Environment.NewLine, ",");

                            datahere = recomposeInputString(thisInputString);

                            /*string thisInputString = ThisComponent.Params.Input[i].VolatileData.DataDescription(false, false).Trim().Replace(System.Environment.NewLine, ",");
                             * datahere = recomposeInputString(thisInputString);*/
                        }
                        else if (ThisComponent.Params.Input[i].Access == GH_ParamAccess.tree)
                        {
                            string thisInputString = ThisComponent.Params.Input[i].VolatileData.DataDescription(false, false).
                                                     Trim().Replace(System.Environment.NewLine + System.Environment.NewLine, "],[").Replace(System.Environment.NewLine, ",");
                            thisInputString = "[" + thisInputString + "]";

                            datahere = recomposeInputStringTree(thisInputString);
                            //MessageBox.Show(ThisComponent.Params.Input[i].VolatileData.DataDescription(false, false));
                        }
                        else
                        {
                            datahere += getInputs(ThisComponent, DA, i);
                        }
                    }
                    catch
                    {
                        datahere += "None";
                    }
                    if (datahere == "")
                    {
                        datahere = "None";
                    }
                    variablesAre += ThisComponent.Params.Input[i].NickName + " = " + datahere + @" \n";
                }
                foot = Resources.SavedPythonFile.savingFile;
                string thisOutputData = "";


                for (int i = 0; i < ThisComponent.Params.Output.Count; i++)
                {
                    if (i < ThisComponent.Params.Output.Count - 1)
                    {
                        thisOutputData += "\"" + ThisComponent.Params.Output[i].NickName + "\":" + ThisComponent.Params.Output[i].NickName + ", ";
                    }
                    else
                    {
                        thisOutputData += "\"" + ThisComponent.Params.Output[i].NickName + "\":" + ThisComponent.Params.Output[i].NickName;
                    }
                }
                foot = foot.Replace("##data##", thisOutputData);
                foot = foot.Replace("##fileName##", path.Replace(@"\", "/") + @"_PythonExecutionOrder_" + index.ToString() + @".xml");
            }
            catch (Exception exep)
            {
                //MessageBox.Show(exep.ToString());
            }

            /// Section 5.
            /// Save all data as a python file that will be run when the component is expired.
            string thisfilePath = "None";
            string thisfileName = "None";

            if (ThisComponent.OnPingDocument().IsFilePathDefined)
            {
                thisfilePath = ThisComponent.OnPingDocument().FilePath;
                thisfileName = ThisComponent.OnPingDocument().DisplayName;
            }
            else
            {
                thisfilePath = @"C:\GH_CPython";
                thisfileName = "unname";
            }



            string envVars = Resources.SavedPythonFile.initghEnv.Replace(Environment.NewLine, @"\n").Replace("##filePath##", thisfilePath.Replace(@"\", "/"));

            envVars      = envVars.Replace("##fileName##", thisfileName.Replace("*", ""));
            variablesAre = Resources.SavedPythonFile.initVars.Replace("##InitVars##", variablesAre.Replace("'", @"\'")).Replace("##initGHENV##", envVars);
            System.IO.File.WriteAllText(path + name + ".py", variablesAre + "\n" + WinForm.PythonCanvas.Text + "\n" + foot);
        }
Exemplo n.º 4
0
 public static bool ConnectToFrame(GH_Component com, out Animation.Frame frameComponent)
 {
     if (Animation.Frame.Component == null || Animation.Frame.Component.OnPingDocument() != com.OnPingDocument())
     {
         com.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please Set Frame Component First!");
         frameComponent = null;
         return(false);
     }
     else if (Animation.Frame.Component.Params.Input[0].SourceCount == 0)
     {
         com.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please Finish Frame Component!");
         frameComponent = null;
         return(false);
     }
     else
     {
         frameComponent = Animation.Frame.Component;
         return(true);
     }
 }