コード例 #1
0
        public void DirectManipulator()
        {
            var pointOriginNode =
                new DSFunction(Model.LibraryServices.GetFunctionDescriptor("Point.ByCoordinates@double,double,double"));

            var command = new Dynamo.Models.DynamoModel.CreateNodeCommand(pointOriginNode, 0, 0, true, false);

            Model.ExecuteCommand(command);
            RunCurrentModel();
            DynamoSelection.Instance.Selection.Add(pointOriginNode);
            RenderCurrentViewAndCompare(MethodBase.GetCurrentMethod().Name);
        }
コード例 #2
0
        /// <summary>
        /// Add a node to the Dynamo canvas.
        /// </summary>
        /// <param name="parameters">The node name, example : List.Map</param>
        /// <returns>HTML result summary.</returns>
        public dynamic AddNode(dynamic parameters)
        {
            string node = parameters.nodename;

            if (string.IsNullOrWhiteSpace(node))
            {
                return("Supplied node was empty");
            }

            string result  = "";
            var    command = new Dynamo.Models.DynamoModel.CreateNodeCommand(Guid.NewGuid().ToString(), node, 100, 100, true, false);
            var    nodes   = "";

            ServerViewExtension.RunInContext(() =>
            {
                try
                {
                    int countBefore = ServerViewExtension.dynamoViewModel.Model.CurrentWorkspace.Nodes.Count();

                    ServerViewExtension.dynamoViewModel.Model.ExecuteCommand(command);
                    int countAfter = ServerViewExtension.dynamoViewModel.Model.CurrentWorkspace.Nodes.Count();

                    var n = ServerViewExtension.dynamoViewModel.Model.CurrentWorkspace.Nodes.Select(x => "<li>" + x.Name).ToArray();
                    nodes = string.Join("</li> ", n);

                    var nodeCountDiff = countAfter - countBefore;

                    if (nodeCountDiff < 1)
                    {
                        result = $"Could not add your {node} node to canvas.";
                    }
                    else if (nodeCountDiff == 1)
                    {
                        result = $"Added {node} node to the canvas.";
                    }
                    else
                    {
                        throw new Exception($"Added {nodeCountDiff} nodes to the canvas, expected was 1.");
                    }
                }
                catch (System.Exception e)
                {
                    result = "Something went wrong, error : " + e.Message;
                }
            });
            return(Response.AsText(result, "text/html"));
        }