/// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 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.
            Line     line   = Line.Unset;
            Vector3d vector = Vector3d.Unset;
            string   name   = string.Empty;

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref line))
            {
                return;
            }
            if (!DA.GetData(1, ref vector))
            {
                return;
            }
            if (!DA.GetData(2, ref name))
            {
                name = "<name>";
            }

            // 3. Abort on invalid inputs.
            if (!line.IsValid)
            {
                return;
            }
            if (!vector.IsValid)
            {
                return;
            }

            // 4. Build hMember.
            var mem = new HM.hMember(HMGHUtil.GHLineToHMLine(line), HMGHUtil.VectorToTriple(vector));

            mem.Name = name;

            // 9. Assign output.
            DA.SetData(0, mem);
        }
Exemple #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)
        {
            // Declare placeholder variables and assign initial invalid data.
            List <Line>   inputLines           = new List <Line>();
            List <string> names                = new List <string>();
            bool          firstConnectionIsFTF = false;
            Dictionary <string, HM.Triple> webNormalsDictionary = null;
            Dictionary <string, int>       prioritiesDictionary = null;
            Dictionary <string, int>       extensionDictionary  = null;
            double tolerance = 0.001;

            // Retrieve input data.
            if (!DA.GetDataList(0, inputLines))
            {
                return;
            }
            if (!DA.GetDataList(1, names))
            {
                names = null;
            }
            if (!DA.GetData(2, ref firstConnectionIsFTF))
            {
                firstConnectionIsFTF = false;
            }
            if (!DA.GetData(3, ref webNormalsDictionary))
            {
                webNormalsDictionary = null;
            }
            if (!DA.GetData(4, ref prioritiesDictionary))
            {
                prioritiesDictionary = null;
            }
            if (!DA.GetData(5, ref extensionDictionary))
            {
                extensionDictionary = null;
            }
            if (!DA.GetData(6, ref tolerance))
            {
                tolerance = 0.001;
            }

            if (names == null)
            {
                names = new List <string>();
                for (int j = 0; j < inputLines.Count; j++)
                {
                    names.Add(j.ToString());
                }
            }

            if (names.Count < inputLines.Count)
            {
                throw new Exception("You must provide a name for every member.");
            }

            // Convert GH lines to HM lines
            var HMLines = new List <HM.Line>();
            var i       = 0;

            foreach (Line l in inputLines)
            {
                HMLines.Add(HMGHUtil.GHLineToHMLine(l));
            }

            // Create Structure
            var structure = HM.hStructure.StructureFromLines(
                HMLines,
                names,
                webNormalsDict: webNormalsDictionary,
                priorityDict: prioritiesDictionary,
                extensionDict: extensionDictionary,
                firstConnectionIsFTF: firstConnectionIsFTF,
                intersectionTolerance: tolerance,
                planarityTolerance: tolerance);

            DA.SetDataList(0, structure.Members);
            DA.SetDataList(1, structure._solveOrder);
            DA.SetDataList(2, structure._solvedBy);
        }