Ejemplo n.º 1
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(
            List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode node;
            Func <string, bool, Revit.Elements.Element> func = ElementSelector.ByUniqueId;

            var results = SelectionResults.ToList();

            if (SelectionResults == null || !results.Any())
            {
                node = AstFactory.BuildNullNode();
            }
            else if (results.Count == 1)
            {
                var el = results.First();

                // If there is only one object in the list,
                // return a single item.
                node = AstFactory.BuildFunctionCall(
                    func,
                    new List <AssociativeNode>
                {
                    AstFactory.BuildStringNode(el.UniqueId),
                    AstFactory.BuildBooleanNode(true)
                });
            }
            else
            {
                var newInputs =
                    results.Select(
                        el =>
                        AstFactory.BuildFunctionCall(
                            func,
                            new List <AssociativeNode>
                {
                    AstFactory.BuildStringNode(el.UniqueId),
                    AstFactory.BuildBooleanNode(true)
                })).ToList();

                node = AstFactory.BuildExprList(newInputs);
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Ejemplo n.º 2
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(
            List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode       node;
            Func <string, object> func = GeometryObjectSelector.ByReferenceStableRepresentation;

            var results = SelectionResults.ToList();

            if (SelectionResults == null || !results.Any())
            {
                node = AstFactory.BuildNullNode();
            }
            else if (results.Count == 1)
            {
                var stableRef = GetIdentifierFromModelObject(results.First());

                node = AstFactory.BuildFunctionCall(
                    func,
                    new List <AssociativeNode> {
                    AstFactory.BuildStringNode(stableRef),
                });
            }
            else
            {
                var stableRefs = results.Select(GetIdentifierFromModelObject);

                var newInputs =
                    stableRefs.Select(
                        stableRef =>
                        AstFactory.BuildFunctionCall(
                            func,
                            new List <AssociativeNode> {
                    AstFactory.BuildStringNode(stableRef),
                }))
                    .ToList();

                node = AstFactory.BuildExprList(newInputs);
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }