Esempio n. 1
0
        /// <summary>
        /// Sets the freeze state of the elements associated with that node.
        /// </summary>
        /// <param name="workspace">The workspace.</param>
        /// <param name="node">The node.</param>
        /// <param name="engine">The engine.</param>
        public static void SetElementFreezeState(WorkspaceModel workspace, NodeModel node, EngineController engine)
        {
            RuntimeCore runtimeCore = null;

            if (engine != null && (engine.LiveRunnerCore != null))
            {
                runtimeCore = engine.LiveRunnerRuntimeCore;
            }

            if (runtimeCore == null || node == null)
            {
                return;
            }

            // Selecting all nodes that are either a DSFunction,
            // a DSVarArgFunction or a CodeBlockNodeModel into a list.
            var nodeGuids = workspace.Nodes.Where((n) =>
            {
                return(n is DSFunction ||
                       (n is DSVarArgFunction) ||
                       (n is CodeBlockNodeModel));
            }).Where((n) => n.GUID == node.GUID).Select((x) => x.GUID);

            var nodeTraceDataList = runtimeCore.RuntimeData.GetCallsitesForNodes(nodeGuids, runtimeCore.DSExecutable);

            foreach (Guid guid in nodeTraceDataList.Keys)
            {
                foreach (CallSite cs in nodeTraceDataList[guid])
                {
                    foreach (CallSite.SingleRunTraceData srtd in cs.TraceData)
                    {
                        List <ISerializable> traceData = srtd.RecursiveGetNestedData();

                        foreach (ISerializable thingy in traceData)
                        {
                            SerializableId sid = thingy as SerializableId;

                            if (sid != null)
                            {
                                setEachElementFreezeState(node.IsFrozen, sid.IntID);
                            }

                            else if (thingy is MultipleSerializableId)
                            {
                                (thingy as MultipleSerializableId).IntIDs.ForEach(x => setEachElementFreezeState(node.IsFrozen, x));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get an Element unique Identifier from trace
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public static ElementUUID GetElementUUIDFromTrace(Document document)
        {
            //Get the element ID that was cached in the callsite
            ISerializable traceData = TraceUtils.GetTraceData(REVIT_TRACE_ID);

            SerializableId id = traceData as SerializableId;

            if (id == null)
            {
                return(null); //There was no usable data in the trace cache
            }
            var traceDataUuid = id.StringID;

            return(new ElementUUID(traceDataUuid));
        }
Esempio n. 3
0
        public static ElementId GetElementIdFromTrace(Document document)
        {
            //Get the element ID that was cached in the callsite
            ISerializable traceData = TraceUtils.GetTraceData(REVIT_TRACE_ID);

            SerializableId id = traceData as SerializableId;

            if (id == null)
            {
                return(null); //There was no usable data in the trace cache
            }
            var traceDataInt = id.IntID;

            return(new Autodesk.Revit.DB.ElementId(traceDataInt));
        }
Esempio n. 4
0
        /// <summary>
        /// Set the element associated with the current operation from trace
        /// null if there is no object, or it's of the wrong type etc.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static void SetElementForTrace(ElementId elementId, ElementUUID elementUUID)
        {
            if (IsEnabled)
            {
                SerializableId id = new SerializableId();
                id.IntID    = elementId.IntegerValue;
                id.StringID = elementUUID.UUID;

                // if we're mutating the current Element id, that means we need to
                // clean up the old object

                // Set the element ID cached in the callsite
                TraceUtils.SetTraceData(REVIT_TRACE_ID, id);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This function gets the nodes which are binding with the elements which have the
        /// given element IDs
        /// </summary>
        /// <param name="ids">The given element IDs</param>
        /// <param name="workspace">The workspace model for the nodes</param>
        /// <param name="engine">The engine controller</param>
        /// <returns>the related nodes</returns>
        public static IEnumerable <NodeModel> GetNodesFromElementIds(IEnumerable <ElementId> ids,
                                                                     WorkspaceModel workspace, EngineController engine)
        {
            List <NodeModel> nodes = new List <NodeModel>();

            if (!ids.Any())
            {
                return(nodes.AsEnumerable());
            }

            RuntimeCore runtimeCore = null;

            if (engine != null && (engine.LiveRunnerCore != null))
            {
                runtimeCore = engine.LiveRunnerRuntimeCore;
            }

            if (runtimeCore == null)
            {
                return(null);
            }

            // Selecting all nodes that are either a DSFunction,
            // a DSVarArgFunction or a CodeBlockNodeModel into a list.
            var nodeGuids = workspace.Nodes.Where((n) =>
            {
                return(n is DSFunction ||
                       (n is DSVarArgFunction) ||
                       (n is CodeBlockNodeModel));
            }).Select((n) => n.GUID);

            var nodeTraceDataList = runtimeCore.RuntimeData.GetCallsitesForNodes(nodeGuids, runtimeCore.DSExecutable);

            bool areElementsFoundForThisNode;

            foreach (Guid guid in nodeTraceDataList.Keys)
            {
                areElementsFoundForThisNode = false;
                foreach (CallSite cs in nodeTraceDataList[guid])
                {
                    foreach (CallSite.SingleRunTraceData srtd in cs.TraceData)
                    {
                        List <ISerializable> traceData = srtd.RecursiveGetNestedData();

                        foreach (ISerializable thingy in traceData)
                        {
                            SerializableId sid = thingy as SerializableId;

                            if (sid != null)
                            {
                                foreach (var id in ids)
                                {
                                    if (sid.IntID == id.IntegerValue)
                                    {
                                        areElementsFoundForThisNode = true;
                                        break;
                                    }
                                }

                                if (areElementsFoundForThisNode)
                                {
                                    NodeModel inm =
                                        workspace.Nodes.Where((n) => n.GUID == guid).FirstOrDefault();
                                    nodes.Add(inm);
                                    break;
                                }
                            }
                        }

                        if (areElementsFoundForThisNode)
                        {
                            break;
                        }
                    }

                    if (areElementsFoundForThisNode)
                    {
                        break;
                    }
                }
            }

            return(nodes.AsEnumerable());
        }
Esempio n. 6
0
        /// <summary>
        /// Sets the freeze state of the elements associated with that node.
        /// </summary>
        /// <param name="workspace">The workspace.</param>
        /// <param name="node">The node.</param>
        /// <param name="engine">The engine.</param>
        public static void SetElementFreezeState(WorkspaceModel workspace, NodeModel node, EngineController engine)
        {
            RuntimeCore runtimeCore = null;

            if (engine != null && (engine.LiveRunnerCore != null))
            {
                runtimeCore = engine.LiveRunnerRuntimeCore;
            }

            if (runtimeCore == null || node == null)
            {
                return;
            }

            // Selecting all nodes that are either a DSFunction,
            // a DSVarArgFunction or a CodeBlockNodeModel into a list.
            var nodeGuids = workspace.Nodes.Where((n) =>
            {
                return(n is DSFunction ||
                       (n is DSVarArgFunction) ||
                       (n is CodeBlockNodeModel));
            }).Where((n) => n.GUID == node.GUID).Select((x) => x.GUID);

            var nodeTraceDataList = runtimeCore.RuntimeData.GetCallsitesForNodes(nodeGuids, runtimeCore.DSExecutable);

            foreach (Guid guid in nodeTraceDataList.Keys)
            {
                foreach (CallSite cs in nodeTraceDataList[guid])
                {
                    foreach (CallSite.SingleRunTraceData srtd in cs.TraceData)
                    {
                        List <ISerializable> traceData = srtd.RecursiveGetNestedData();

                        foreach (ISerializable thingy in traceData)
                        {
                            SerializableId sid = thingy as SerializableId;

                            if (sid != null)
                            {
                                //Get the Autodesk.Revit.Element.
                                Element el;
                                DocumentManager.Instance.CurrentDBDocument.TryGetElement(new ElementId(sid.IntID),
                                                                                         out el);

                                //Get the Revit Element wrapper.
                                if (el != null)
                                {
                                    dynamic elem =
                                        ElementIDLifecycleManager <int> .GetInstance().GetFirstWrapper(el.Id.IntegerValue);

                                    if (elem != null)
                                    {
                                        elem.IsFrozen = node.IsFrozen;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }