Dynamo.Graph.Workspaces.WorkspaceModel.ReloadModel C# (CSharp) Method

ReloadModel() public method

Updates ModelBase object with given xml data
public ReloadModel ( XmlElement modelData ) : void
modelData System.Xml.XmlElement Xml data to update model
return void
        public void ReloadModel(XmlElement modelData)
        {
            ModelBase model = GetModelForElement(modelData);
            model.Deserialize(modelData, SaveContext.Undo);
        }

Usage Example

コード例 #1
0
ファイル: PresetExtensions.cs プロジェクト: zjloscar/Dynamo
        internal static bool ApplyPreset(this WorkspaceModel workspace, PresetModel state)
        {
            if (state == null)
            {
                return(false);
            }

            //start an undoBeginGroup
            using (var undoGroup = workspace.UndoRecorder.BeginActionGroup())
            {
                //reload each node, and record each each modification in the undogroup
                foreach (var node in state.Nodes)
                {
                    //check that node still exists in this workspace,
                    //otherwise bail on this node, check by GUID instead of nodemodel
                    if (workspace.Nodes.Select(x => x.GUID).Contains(node.GUID))
                    {
                        var originalpos    = node.Position;
                        var serializedNode = state.SerializedNodes.ToList().Find(x => Guid.Parse(x.GetAttribute("guid")) == node.GUID);
                        //overwrite the xy coords of the serialized node with the current position, so the node is not moved
                        serializedNode.SetAttribute("x", originalpos.X.ToString(CultureInfo.InvariantCulture));
                        serializedNode.SetAttribute("y", originalpos.Y.ToString(CultureInfo.InvariantCulture));
                        serializedNode.SetAttribute("isPinned", node.PreviewPinned.ToString());

                        workspace.UndoRecorder.RecordModificationForUndo(node);
                        workspace.ReloadModel(serializedNode);
                    }
                }
                //select all the modified nodes in the UI
                DynamoSelection.Instance.ClearSelection();
                foreach (var node in state.Nodes)
                {
                    DynamoSelection.Instance.Selection.Add(node);
                }
            }

            return(true);
        }
WorkspaceModel