Пример #1
0
        protected override void Updater_ElementsModified(IEnumerable <string> updated)
        {
            // If there is nothing modified or the SelectionResults
            // collection is null, then return
            if (!updated.Any() || SelectionResults == null)
            {
                return;
            }

            var doc = DocumentManager.Instance.CurrentDBDocument;

            // If this modification is being parsed as part of a document
            // update that also contains a deletion, then we need to try to
            // get the elements first to see if they are valid.
            var validIds = SelectionResults.Select(doc.GetElement).Where(x => x != null).Select(x => x.UniqueId);

            // If none of the updated elements are included in the
            // list of valid ids in the selection, then return.
            if (!validIds.Any(updated.Contains))
            {
                return;
            }

            // We want this modification to trigger a graph reevaluation
            // and we want the AST for this node to be regenerated.
            OnNodeModified(forceExecute: true);
        }
Пример #2
0
        protected override void Updater_ElementsDeleted(
            Document document, IEnumerable <ElementId> deleted)
        {
            if (!SelectionResults.Any() ||
                !document.Equals(SelectionOwner) ||
                !deleted.Any())
            {
                return;
            }

            // If the deleting operations does not make any elements in SelectionResults
            // invalid, then there is no need to update.
            if (SelectionResults.Where(el => !el.IsValidObject).Count() == 0)
            {
                return;
            }

            // We are given a set of ElementIds, but because the elements
            // have already been deleted from Revit, we can't get the
            // corresponding GUID. Instead, we just go through the collection of
            // elements and get the ones that are still valid.

            var validEls = Selection.Where(el => el.IsValidObject).ToList();

            UpdateSelection(validEls);
        }
Пример #3
0
        public override string ToString()
        {
            if (Selection.Any() && !SelectionResults.Any())
            {
                return(Resources.NoFamilyInstancesInDividedSurfaceWarning);
            }

            return(base.ToString());
        }
Пример #4
0
        protected override void Updater_ElementsModified(IEnumerable <string> updated)
        {
            var doc = DocumentManager.Instance.CurrentDBDocument;

            // If an element is modified, require recalc
            if (SelectionResults == null ||
                !SelectionResults.Select(r => doc.GetElement(r).UniqueId).Any(updated.Contains))
            {
                return;
            }

            RequiresRecalc = true;
        }
Пример #5
0
        protected override void Updater_ElementsDeleted(
            Document document, IEnumerable <ElementId> deleted)
        {
            if (!SelectionResults.Any() || !document.Equals(SelectionOwner))
            {
                return;
            }

            var uuids =
                deleted.Select(document.GetElement)
                .Where(el => el != null)
                .Select(el => el.UniqueId);

            UpdateSelection(Selection.Where(x => !uuids.Contains(x.UniqueId)));
        }
Пример #6
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(
            List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode node;

            if (SelectionResults == null || !SelectionResults.Any())
            {
                node = AstFactory.BuildNullNode();
            }
            else
            {
                var newInputs = new List <AssociativeNode>();

                foreach (var reference in SelectionResults)
                {
                    if (reference.GlobalPoint == null)
                    {
                        return(new[]
                        {
                            AstFactory.BuildAssignment(
                                GetAstIdentifierForOutputIndex(0),
                                AstFactory.BuildNullNode())
                        });
                    }

                    var pt = reference.GlobalPoint.ToPoint();

                    //this is a selected point on a face
                    var ptArgs = new List <AssociativeNode>
                    {
                        AstFactory.BuildDoubleNode(pt.X),
                        AstFactory.BuildDoubleNode(pt.Y),
                        AstFactory.BuildDoubleNode(pt.Z)
                    };

                    var functionCallNode =
                        AstFactory.BuildFunctionCall(
                            new Func <double, double, double, Point>(Point.ByCoordinates),
                            ptArgs);

                    newInputs.Add(functionCallNode);
                }

                node = AstFactory.BuildExprList(newInputs);
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Пример #7
0
        protected override void Updater_ElementsModified(IEnumerable <string> updated)
        {
            if (!updated.Any())
            {
                return;
            }

            var updatedSet = new HashSet <string>(updated);

            if (!SelectionResults.Select(x => x.UniqueId).Any(updatedSet.Contains))
            {
                return;
            }

            UpdateSelection(Selection);
        }
Пример #8
0
        protected override void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context)
        {
            if (!SelectionResults.Any())
            {
                return;
            }

            var uuidsSelection =
                selection.Select(GetIdentifierFromModelObject).Where(x => x != null);

            foreach (var id in uuidsSelection)
            {
                XmlElement outEl = xmlDoc.CreateElement("instance");
                outEl.SetAttribute("id", id);
                nodeElement.AppendChild(outEl);
            }
        }
Пример #9
0
        protected override void Updater_ElementsDeleted(
            Document document, IEnumerable <ElementId> deleted)
        {
            // If an element is deleted, ensure all references which refer
            // to that element are removed from the selection

            if (!SelectionResults.Any() || !document.Equals(SelectionOwner))
            {
                return;
            }

            UpdateSelection(SelectionResults.Where(x => !deleted.Contains(x.ElementId)));

            RaisePropertyChanged("SelectionResults");
            RaisePropertyChanged("Text");
            RequiresRecalc = true;
        }
Пример #10
0
        protected override void Updater_ElementsModified(IEnumerable <string> updated)
        {
            // If nothing has been updated, then return

            if (!updated.Any())
            {
                return;
            }

            // If the updated list doesn't include any objects in the current selection
            // then return;
            if (!SelectionResults.Where(x => x.IsValidObject).Select(x => x.UniqueId).Any(updated.Contains))
            {
                return;
            }

            UpdateSelection(Selection);
        }
Пример #11
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) });
        }
Пример #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputAstNodes"></param>
        /// <returns></returns>
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode node;

            if (SelectionResults == null || !SelectionResults.Any())
            {
                node = AstFactory.BuildNullNode();
            }
            else
            {
                IEnumerable <AssociativeNode> strInputs = SelectionResults.Select(res => AstFactory.BuildStringNode(res) as AssociativeNode);
                ExprListNode inputNode1 = AstFactory.BuildExprList(strInputs.ToList());
                node = AstFactory.BuildFunctionCall(new Func <IEnumerable <string>, IEnumerable <SteelDbObject> >(Utils.GetDynObjects), new List <AssociativeNode>()
                {
                    inputNode1
                });
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Пример #13
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) });
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputAstNodes"></param>
        /// <returns></returns>
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode node;

            if (SelectionResults == null || !SelectionResults.Any())
            {
                node = AstFactory.BuildNullNode();
            }
            else
            {
                //IEnumerable<AssociativeNode> strInputs = SelectionResults.Select(res => AstFactory.BuildStringNode(res) as AssociativeNode);
                //ExprListNode inputNode1 = AstFactory.BuildExprList(strInputs.ToList());
                //node = AstFactory.BuildFunctionCall(new Func<IEnumerable<string>, IEnumerable<SteelDbObject>>(Utils.GetDynObjects), new List<AssociativeNode>() { inputNode1 });

                var newInputs = new List <AssociativeNode>();

                foreach (var resP in SelectionResults)
                {
                    //this is a selected point on a face
                    var ptArgs = new List <AssociativeNode>
                    {
                        AstFactory.BuildDoubleNode(resP.X),
                        AstFactory.BuildDoubleNode(resP.Y),
                        AstFactory.BuildDoubleNode(resP.Z)
                    };

                    var functionCallNode =
                        AstFactory.BuildFunctionCall(
                            new Func <double, double, double, Autodesk.DesignScript.Geometry.Point>(Autodesk.DesignScript.Geometry.Point.ByCoordinates),
                            ptArgs);

                    newInputs.Add(functionCallNode);
                }

                node = AstFactory.BuildExprList(newInputs);
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Пример #15
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(
            List <AssociativeNode> inputAstNodes)
        {
            AssociativeNode       node;
            Func <string, object> func = GeometryObjectSelector.GetPointByReference;

            if (SelectionResults == null || !SelectionResults.Any())
            {
                node = AstFactory.BuildNullNode();
            }
            else
            {
                var newInputs = new List <AssociativeNode>();

                foreach (var reference in SelectionResults)
                {
                    var stableRef = GetIdentifierFromModelObject(reference);

                    //this is a selected point on a face
                    var ptArgs = new List <AssociativeNode>
                    {
                        AstFactory.BuildStringNode(stableRef)
                    };

                    var functionCallNode =
                        AstFactory.BuildFunctionCall(
                            func,
                            ptArgs);

                    newInputs.Add(functionCallNode);
                }

                node = AstFactory.BuildExprList(newInputs);
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Пример #16
0
        protected override void Updater_ElementsDeleted(
            Document document, IEnumerable <ElementId> deleted)
        {
            // If an element is deleted, ensure all references which refer
            // to that element are removed from the selection

            // If there is no selection, or the doc of the deleted
            // elements is not this doc, or if there is nothing
            // in the deleted set, then return

            if (!SelectionResults.Any() ||
                !document.Equals(SelectionOwner) ||
                !deleted.Any() ||
                !SelectionResults.Any(x => deleted.Contains(x.ElementId)))
            {
                return;
            }

            // The new selections is everything in the current selection
            // that is not in the deleted collection as well
            var newSelection = SelectionResults.Where(x => !deleted.Contains(x.ElementId));

            UpdateSelection(newSelection);
        }
Пример #17
0
 protected virtual string FormatSelectionText <T>(IEnumerable <T> elements)
 {
     return(elements.Any()
         ? System.String.Join(" ", SelectionResults.Take(20).Select(x => x.ToString()))
         : "");
 }
Пример #18
0
 public override string ToString()
 {
     return(SelectionResults.Any()
         ? string.Format("{0} : {1}", Prefix, FormatSelectionText(SelectionResults))
         : Resources.SelectionNodeNothingSelected);
 }
Пример #19
0
 public override string ToString()
 {
     return(SelectionResults.Any()
         ? string.Format("{0} : {1}", Prefix, FormatSelectionText(SelectionResults))
         : "Nothing selected.");
 }