コード例 #1
0
        private void OnExtractPtToGhPoints(object sender, EventArgs e)
        {
            var GHPoints = new List <GH_Point>();

            foreach (var item in this.ExtractedCoordinates)
            {
                var pt = new Point3d(item.X, item.Y, 0);
                GHPoints.Add(new GH_Point(pt));
            }
            var thisParamAttr = this.Params.Input[1].Attributes;
            var paramPt       = new GH.Kernel.Parameters.Param_Point();

            paramPt.CreateAttributes();
            paramPt.PersistentData.AppendRange(GHPoints);
            paramPt.Attributes.Pivot = new PointF(thisParamAttr.Bounds.Left - 80, thisParamAttr.Bounds.Y + 10);
            GH.Instances.ActiveCanvas.Document.AddObject(paramPt, false);
            paramPt.ExpireSolution(false);

            //create a group
            var GhGroup = new GH_Group();

            GhGroup.CreateAttributes();
            GhGroup.Colour   = Color.White;
            GhGroup.NickName = "Extracted Coordinates";
            GhGroup.AddObject(paramPt.InstanceGuid);
            GH.Instances.ActiveCanvas.Document.AddObject(GhGroup, false);
            GhGroup.ExpireSolution(false);

            GH.Instances.ActiveCanvas.Document.NewSolution(false);
        }
コード例 #2
0
        /*******************************************/
        /**** Public Methods                    ****/
        /*******************************************/

        public static NodeGroup ToNodeGroup(this GH_Group group)
        {
            List <IGH_DocumentObject> content = group.Objects();

            List <GH_Group> internalGroups = content.OfType <GH_Group>().ToList();

            content = content.Except(internalGroups.SelectMany(x => x.Objects())).ToList();

            List <GH_Scribble>     comments   = content.OfType <GH_Scribble>().ToList();
            List <GH_ActiveObject> components = content.OfType <GH_ActiveObject>().ToList();

            List <Guid>      nodeIds            = components.Select(x => x.InstanceGuid).ToList();
            List <NodeGroup> internalNodeGroups = internalGroups.Select(x => x.ToNodeGroup()).Where(x => x != null).ToList();
            string           description        = comments.Count == 1 ? comments.First().Text : "";

            // Provide a warning if a group has more than one description
            if (comments.Count > 1)
            {
                List <string> internalDescriptions  = GetChildDescriptions(internalNodeGroups);
                List <string> exclusiveDescriptions = comments.Select(x => x.Text).Except(internalDescriptions).ToList();

                if (exclusiveDescriptions.Count == 1)
                {
                    description = exclusiveDescriptions.First();
                    string message = "A group directly contains descriptions that are also contained by its sub-groups. Those descriptions will be ignored.";
                    if (description.Length > 0)
                    {
                        message += "\nThat group description is " + description;
                    }
                    Base.Compute.RecordWarning(message);
                }
                else if (exclusiveDescriptions.Count > 1)
                {
                    string message = "A group contains more than one description. No description will be provided for that group. Descriptions found:";
                    message += comments.Select(x => "\n - " + x.Text).Aggregate((a, b) => a + b);
                    Base.Compute.RecordWarning(message);
                }
                else
                {
                    string message = "A group contains no description that is not also in a sub-group. No description will be provided for that group. Descriptions found:";
                    message += comments.Select(x => "\n - " + x.Text).Aggregate((a, b) => a + b);
                    Base.Compute.RecordWarning(message);
                }
            }

            // Make sure there is no component also contained in sub-groups
            List <Guid> childNodeIds = GetChildNodeIds(internalNodeGroups);
            List <Guid> safeNodeIds  = nodeIds.Except(childNodeIds).ToList();

            if (safeNodeIds.Count < nodeIds.Count)
            {
                nodeIds = safeNodeIds;
                string message = "A group directly contains elements that are also contained by its sub-groups. Those elements will only be part of the sub-group.";
                if (description.Length > 0)
                {
                    message += "\nThat group description is " + description;
                }
                Base.Compute.RecordWarning(message);
            }

            return(new NodeGroup
            {
                Description = description,
                NodeIds = nodeIds,
                InternalGroups = internalNodeGroups
            });
        }