Exemple #1
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);
            XmlElement        oldNode       = data.MigratedNodes.ElementAt(0);
            string            oldNodeId     = MigrationManager.GetGuidFromXmlElement(oldNode);

            var newNode = MigrationManager.CreateFunctionNodeFrom(oldNode);

            MigrationManager.SetFunctionSignature(newNode, "ProtoGeometry.dll",
                                                  "Cuboid.ByCorners", "Cuboid.ByCorners@Point,Point");

            migrationData.AppendNode(newNode);

            // Add default values
            foreach (XmlNode child in oldNode.ChildNodes)
            {
                var newChild = child.Clone() as XmlElement;

                switch (newChild.GetAttribute("index"))
                {
                case "0":
                    PortId     oldInPort0 = new PortId(oldNodeId, 0, PortType.INPUT);
                    XmlElement connector0 = data.FindFirstConnector(oldInPort0);
                    if (connector0 != null)
                    {
                        break;
                    }

                    XmlElement cbn0 = MigrationManager.CreateCodeBlockNodeModelNode(
                        data.Document, oldNode, 0, "Point.ByCoordinates(-1,-1,-1);");
                    migrationData.AppendNode(cbn0);
                    data.CreateConnector(cbn0, 0, newNode, 0);
                    break;

                case "1":
                    PortId     oldInPort1 = new PortId(oldNodeId, 1, PortType.INPUT);
                    XmlElement connector1 = data.FindFirstConnector(oldInPort1);
                    if (connector1 != null)
                    {
                        break;
                    }

                    XmlElement cbn1 = MigrationManager.CreateCodeBlockNodeModelNode(
                        data.Document, oldNode, 1, "Point.ByCoordinates(1,1,1);");
                    migrationData.AppendNode(cbn1);
                    data.CreateConnector(cbn1, 0, newNode, 1);
                    break;

                default:
                    break;
                }
            }

            return(migrationData);
        }
Exemple #2
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);
            XmlElement        oldNode       = data.MigratedNodes.ElementAt(0);
            string            oldNodeId     = MigrationManager.GetGuidFromXmlElement(oldNode);

            // Create DSFunction node
            XmlElement newNode = MigrationManager.CreateFunctionNodeFrom(oldNode);

            MigrationManager.SetFunctionSignature(newNode, "RevitNodes.dll",
                                                  "StructuralFraming.ByCurveLevelUpVectorAndType",
                                                  "StructuralFraming.ByCurveLevelUpVectorAndType@Curve,Level,Vector,StructuralType,FamilySymbol");
            migrationData.AppendNode(newNode);
            string newNodeId = MigrationManager.GetGuidFromXmlElement(newNode);

            // Create new nodes
            XmlElement one = MigrationManager.CreateCodeBlockNodeModelNode(
                data.Document, oldNode, 0, "1");

            migrationData.AppendNode(one);
            string oneId = MigrationManager.GetGuidFromXmlElement(one);

            XmlElement level = MigrationManager.CreateFunctionNode(
                data.Document, oldNode, 1, "RevitNodes.dll",
                "Level.ByElevation", "Level.ByElevation@double");

            migrationData.AppendNode(level);
            string levelId = MigrationManager.GetGuidFromXmlElement(level);

            // Assume that structural framing created by 0.6.3 is always Beam
            XmlElement beam = MigrationManager.CreateFunctionNode(
                data.Document, oldNode, 2, "RevitNodes.dll",
                "StructuralType.Beam", "StructuralType.Beam");

            migrationData.AppendNode(beam);
            string beamId = MigrationManager.GetGuidFromXmlElement(beam);

            // Update connectors
            PortId     oldInPort0 = new PortId(oldNodeId, 0, PortType.Input);
            PortId     oldInPort1 = new PortId(oldNodeId, 1, PortType.Input);
            XmlElement connector0 = data.FindFirstConnector(oldInPort0);
            XmlElement connector1 = data.FindFirstConnector(oldInPort1);
            PortId     newInPort0 = new PortId(newNodeId, 0, PortType.Input);
            PortId     newInPort4 = new PortId(newNodeId, 4, PortType.Input);

            data.CreateConnector(one, 0, level, 0);
            data.CreateConnector(level, 0, newNode, 1);
            data.CreateConnector(beam, 0, newNode, 3);
            data.ReconnectToPort(connector0, newInPort4);
            data.ReconnectToPort(connector1, newInPort0);

            return(migrationData);
        }
Exemple #3
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);
            XmlElement        oldNode       = data.MigratedNodes.ElementAt(0);

            // Create DSFunction node
            XmlElement newNode = MigrationManager.CreateFunctionNodeFrom(oldNode);

            MigrationManager.SetFunctionSignature(newNode, "RevitNodes.dll",
                                                  "ReferencePoint.ByLengthOnCurveReference",
                                                  "ReferencePoint.ByLengthOnCurveReference@CurveReference,double");
            migrationData.AppendNode(newNode);
            string newNodeId = MigrationManager.GetGuidFromXmlElement(newNode);

            // Create new adapter node
            XmlElement codeBlockNode = MigrationManager.CreateCodeBlockNodeModelNode(
                data.Document, oldNode, 0,
                "// Convert ModelCurve into CurveReference\n" +
                "curve.CurveReference;\n\n" +
                "// Convert normalized length into actual length\n" +
                "// and flip the evaluation if 'beginning' is set to false\n" +
                "len * (normalized ? curve.Curve.Length : 1)\n" +
                "* (beginning ? 1 : -1) + (beginning ? 0 : curve.Curve.Length);");

            migrationData.AppendNode(codeBlockNode);
            string cbnId = MigrationManager.GetGuidFromXmlElement(codeBlockNode);

            // Update connectors
            PortId     oldInPort0 = new PortId(newNodeId, 0, PortType.INPUT);
            PortId     oldInPort1 = new PortId(newNodeId, 1, PortType.INPUT);
            PortId     oldInPort2 = new PortId(newNodeId, 2, PortType.INPUT);
            PortId     oldInPort3 = new PortId(newNodeId, 3, PortType.INPUT);
            XmlElement connector0 = data.FindFirstConnector(oldInPort0);
            XmlElement connector1 = data.FindFirstConnector(oldInPort1);
            XmlElement connector2 = data.FindFirstConnector(oldInPort2);
            XmlElement connector3 = data.FindFirstConnector(oldInPort3);
            PortId     cbnInPort0 = new PortId(cbnId, 0, PortType.INPUT);
            PortId     cbnInPort1 = new PortId(cbnId, 1, PortType.INPUT);
            PortId     cbnInPort2 = new PortId(cbnId, 2, PortType.INPUT);
            PortId     cbnInPort3 = new PortId(cbnId, 3, PortType.INPUT);

            data.ReconnectToPort(connector0, cbnInPort0);
            data.ReconnectToPort(connector1, cbnInPort1);
            data.ReconnectToPort(connector2, cbnInPort2);
            data.ReconnectToPort(connector3, cbnInPort3);
            data.CreateConnector(codeBlockNode, 0, newNode, 0);
            data.CreateConnector(codeBlockNode, 1, newNode, 1);

            return(migrationData);
        }
Exemple #4
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);

            XmlElement oldNode   = data.MigratedNodes.ElementAt(0);
            string     oldNodeId = MigrationManager.GetGuidFromXmlElement(oldNode);

            XmlElement codeBlockNode = MigrationManager.CreateCodeBlockNodeModelNode(
                data.Document, oldNode, 0,
                "domain[0][0]..domain[1][0]..#ucount+1;\n" +
                "domain[0][1]..domain[1][1]..#vcount+1;");

            migrationData.AppendNode(codeBlockNode);
            string codeBlockNodeId = MigrationManager.GetGuidFromXmlElement(codeBlockNode);

            XmlElement uvNode = MigrationManager.CreateFunctionNode(data.Document, oldNode, 1,
                                                                    "ProtoGeometry.dll", "UV.ByCoordinates", "UV.ByCoordinates@double,double");

            uvNode.SetAttribute("lacing", "CrossProduct");
            migrationData.AppendNode(uvNode);

            XmlElement flattenNode = MigrationManager.CreateFunctionNodeFrom(oldNode);

            MigrationManager.SetFunctionSignature(flattenNode, "",
                                                  "Flatten", "Flatten");
            flattenNode.SetAttribute("lacing", "Shortest");
            migrationData.AppendNode(flattenNode);

            // Update connectors
            PortId     oldInPort0 = new PortId(oldNodeId, 0, PortType.Input);
            PortId     oldInPort1 = new PortId(oldNodeId, 1, PortType.Input);
            PortId     oldInPort2 = new PortId(oldNodeId, 2, PortType.Input);
            PortId     newInPort0 = new PortId(codeBlockNodeId, 0, PortType.Input);
            PortId     newInPort1 = new PortId(codeBlockNodeId, 1, PortType.Input);
            PortId     newInPort2 = new PortId(codeBlockNodeId, 2, PortType.Input);
            XmlElement connector0 = data.FindFirstConnector(oldInPort0);
            XmlElement connector1 = data.FindFirstConnector(oldInPort1);
            XmlElement connector2 = data.FindFirstConnector(oldInPort2);

            data.ReconnectToPort(connector0, newInPort0);
            data.ReconnectToPort(connector1, newInPort1);
            data.ReconnectToPort(connector2, newInPort2);

            data.CreateConnector(codeBlockNode, 0, uvNode, 0);
            data.CreateConnector(codeBlockNode, 1, uvNode, 1);
            data.CreateConnector(uvNode, 0, flattenNode, 0);

            return(migrationData);
        }
Exemple #5
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);
            XmlElement        oldNode       = data.MigratedNodes.ElementAt(0);
            string            oldNodeId     = MigrationManager.GetGuidFromXmlElement(oldNode);

            var newNode = MigrationManager.CreateFunctionNodeFrom(oldNode);

            MigrationManager.SetFunctionSignature(newNode, "RevitNodes.dll",
                                                  "Solid.BoxByCenterAndDimensions",
                                                  "Solid.BoxByCenterAndDimensions@Point,double,double,double");

            migrationData.AppendNode(newNode);

            // Add default values
            foreach (XmlNode child in oldNode.ChildNodes)
            {
                var newChild = child.Clone() as XmlElement;

                switch (newChild.GetAttribute("index"))
                {
                case "0":
                    PortId     oldInPort0 = new PortId(oldNodeId, 0, PortType.INPUT);
                    XmlElement connector0 = data.FindFirstConnector(oldInPort0);
                    if (connector0 != null)
                    {
                        break;
                    }

                    XmlElement cbn = MigrationManager.CreateCodeBlockNodeModelNode(
                        data.Document, oldNode, 0, "Point.ByCoordinates(0,0,0);");
                    migrationData.AppendNode(cbn);
                    data.CreateConnector(cbn, 0, newNode, 0);
                    break;

                case "1":
                case "2":
                case "3":
                    newNode.AppendChild(newChild);
                    break;

                default:
                    break;
                }
            }

            return(migrationData);
        }
Exemple #6
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migrationData = new NodeMigrationData(data.Document);

            XmlElement oldNode   = data.MigratedNodes.ElementAt(0);
            string     oldNodeId = MigrationManager.GetGuidFromXmlElement(oldNode);

            XmlElement codeBlockNode = MigrationManager.CreateCodeBlockNodeModelNode(
                data.Document, oldNode, 0,
                "dom[0][0]+Math.RandomList\n" +
                "(ucount*vcount)\n" +
                "*(dom[1][0]-dom[0][0]);\n" +
                "dom[0][1]+Math.RandomList\n" +
                "(ucount*vcount)\n" +
                "*(dom[1][1]-dom[0][1]);");

            codeBlockNode.SetAttribute("nickname", "Random UV");
            migrationData.AppendNode(codeBlockNode);
            string codeBlockNodeId = MigrationManager.GetGuidFromXmlElement(codeBlockNode);

            XmlElement uvNode = MigrationManager.CreateFunctionNodeFrom(oldNode);

            MigrationManager.SetFunctionSignature(uvNode, "ProtoGeometry.dll",
                                                  "UV.ByCoordinates", "UV.ByCoordinates@double,double");
            uvNode.SetAttribute("lacing", "Longest");
            migrationData.AppendNode(uvNode);

            // Update connectors
            PortId     oldInPort0 = new PortId(oldNodeId, 0, PortType.Input);
            PortId     oldInPort1 = new PortId(oldNodeId, 1, PortType.Input);
            PortId     oldInPort2 = new PortId(oldNodeId, 2, PortType.Input);
            PortId     newInPort0 = new PortId(codeBlockNodeId, 0, PortType.Input);
            PortId     newInPort1 = new PortId(codeBlockNodeId, 1, PortType.Input);
            PortId     newInPort2 = new PortId(codeBlockNodeId, 2, PortType.Input);
            XmlElement connector0 = data.FindFirstConnector(oldInPort0);
            XmlElement connector1 = data.FindFirstConnector(oldInPort1);
            XmlElement connector2 = data.FindFirstConnector(oldInPort2);

            data.ReconnectToPort(connector0, newInPort0);
            data.ReconnectToPort(connector1, newInPort1);
            data.ReconnectToPort(connector2, newInPort2);

            data.CreateConnector(codeBlockNode, 0, uvNode, 0);
            data.CreateConnector(codeBlockNode, 1, uvNode, 1);

            return(migrationData);
        }
Exemple #7
0
        public void TestCreateCodeBlockNodeModelNode()
        {
            //Arrange
            string documentDynPath = Path.Combine(TestDirectory, @"core\NodeStates.dyn");
            XmlDocument xmlDoc = new XmlDocument();
            XmlDocument xmlOldNodeDoc = new XmlDocument();
            xmlOldNodeDoc.LoadXml("<Dynamo.Graph.Nodes.CodeBlockNodeModel type=\"Dynamo.Graph.Nodes.CodeBlockNodeModel\"  x=\"203.6\" y=\"220\"/>");
            XmlElement xmlOldNode = xmlOldNodeDoc.DocumentElement;
            XmlElement xmlResult = null;

            //Act
            if (File.Exists(documentDynPath))
            {
                xmlDoc.Load(documentDynPath);
                xmlResult = MigrationManager.CreateCodeBlockNodeModelNode(xmlDoc, xmlOldNode, 0, "1");
            }

            //Assert
            //Check that all the attibutes where generated correctly
            Assert.IsNotNull(xmlResult);
            Assert.AreEqual(xmlResult.GetAttribute("type"), "Dynamo.Graph.Nodes.CodeBlockNodeModel");
            Assert.AreEqual(xmlResult.GetAttribute("nickname"), "Code Block");
            Assert.AreEqual(xmlResult.GetAttribute("CodeText"), "1");
        }
Exemple #8
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            #region Migration Setup Steps

            NodeMigrationData migratedData = new NodeMigrationData(data.Document);

            // Legacy "ModelText" node takes in the following 6 inputs:
            //
            //      0 - text (string)
            //      1 - position (XYZ)
            //      2 - normal (XYZ)
            //      3 - up (XYZ)
            //      4 - depth (double)
            //      5 - text type name (string)
            //
            // The new "ModelText.ByTextSketchPlaneAndPosition" node takes in
            // the following inputs:
            //
            //      0 - text (string)
            //      1 - sketchPlane (SketchPlane)
            //      2 - xCoordinateInPlane (double)
            //      3 - yCoordinateInPlane (double)
            //      4 - textDepth (double)
            //      5 - modelTextType (ModelTextType)
            //
            XmlElement oldNode   = data.MigratedNodes.ElementAt(0);
            string     oldNodeId = MigrationManager.GetGuidFromXmlElement(oldNode);

            #endregion

            #region Create New Nodes...

            XmlElement dsModelText = MigrationManager.CreateFunctionNodeFrom(oldNode);
            MigrationManager.SetFunctionSignature(dsModelText, "RevitNodes.dll",
                                                  "ModelText.ByTextSketchPlaneAndPosition",
                                                  "ModelText.ByTextSketchPlaneAndPosition@" +
                                                  "string,SketchPlane,double,double,double,ModelTextType");

            migratedData.AppendNode(dsModelText);
            string dsModelTextId = MigrationManager.GetGuidFromXmlElement(dsModelText);

            // Create a "Plane.ByOriginNormal" that takes a "Point" (origin) and
            // a "Vector" (normal). This new node will convert both the "position"
            // and "normal" to a "Plane".
            XmlElement plane = MigrationManager.CreateFunctionNode(
                data.Document, oldNode, 0, "ProtoGeometry.dll", "Plane.ByOriginNormal",
                "Plane.ByOriginNormal@Point,Vector");

            migratedData.AppendNode(plane);
            string planeId = MigrationManager.GetGuidFromXmlElement(plane);

            // Create a "SketchPlane.ByPlane" node which converts a "Plane"
            // into a "SketchPlane".
            XmlElement dsSketchPlane = MigrationManager.CreateFunctionNode(
                data.Document, oldNode, 1, "RevitNodes.dll",
                "SketchPlane.ByPlane", "SketchPlane.ByPlane@Plane");

            migratedData.AppendNode(dsSketchPlane);
            string dsSketchPlaneId = MigrationManager.GetGuidFromXmlElement(dsSketchPlane);

            // Create a "ModelTextType.ByName" node that converts a "string"
            // into "ModelTextType" node.
            XmlElement dsModelTextType = MigrationManager.CreateFunctionNode(
                data.Document, oldNode, 2, "RevitNodes.dll",
                "ModelTextType.ByName", "ModelTextType.ByName@string");

            migratedData.AppendNode(dsModelTextType);
            string dsModelTextTypeId = MigrationManager.GetGuidFromXmlElement(dsModelTextType);

            //append asVector Node
            XmlElement pointAsVector0 = MigrationManager.CreateFunctionNode(
                data.Document, oldNode, 3, "ProtoGeometry.dll",
                "Point.AsVector", "Point.AsVector");
            migratedData.AppendNode(pointAsVector0);
            string pointAsVector0Id = MigrationManager.GetGuidFromXmlElement(pointAsVector0);

            //append number Node
            XmlElement numberNode = MigrationManager.CreateCodeBlockNodeModelNode(
                data.Document, oldNode, 4, "0;");
            migratedData.AppendNode(numberNode);

            #endregion

            #region Move Connectors Onto the New Nodes

            // Move connector for "text" over to the new node.
            PortId     oldInPort = new PortId(oldNodeId, 0, PortType.Input);
            PortId     newInPort = new PortId(dsModelTextId, 0, PortType.Input);
            XmlElement connector = data.FindFirstConnector(oldInPort);
            data.ReconnectToPort(connector, newInPort);

            // Move connector for "position" over to "Plane" node.
            oldInPort = new PortId(oldNodeId, 1, PortType.Input);
            newInPort = new PortId(planeId, 0, PortType.Input);
            connector = data.FindFirstConnector(oldInPort);
            data.ReconnectToPort(connector, newInPort);

            // Move connector for "normal" over to "Plane" node.
            oldInPort = new PortId(oldNodeId, 2, PortType.Input);
            newInPort = new PortId(pointAsVector0Id, 0, PortType.Input);
            connector = data.FindFirstConnector(oldInPort);
            data.ReconnectToPort(connector, newInPort);
            data.CreateConnector(pointAsVector0, 0, plane, 1);

            // Connect from "Plane" to "SketchPlane".
            data.CreateConnector(plane, 0, dsSketchPlane, 0);

            // Connect from "SketchPlane" to the new node.
            data.CreateConnector(dsSketchPlane, 0, dsModelText, 1);

            oldInPort = new PortId(oldNodeId, 3, PortType.Input);
            data.RemoveFirstConnector(oldInPort);

            // Move connector for "depth" over to the new node.
            oldInPort = new PortId(oldNodeId, 4, PortType.Input);
            newInPort = new PortId(dsModelTextId, 4, PortType.Input);
            connector = data.FindFirstConnector(oldInPort);
            data.ReconnectToPort(connector, newInPort);

            // Move connector for "text type name" over to "ModelTextType" node.
            oldInPort = new PortId(oldNodeId, 5, PortType.Input);
            newInPort = new PortId(dsModelTextTypeId, 0, PortType.Input);
            connector = data.FindFirstConnector(oldInPort);
            data.ReconnectToPort(connector, newInPort);

            // Connect from "ModelTextType" to the new node.
            data.CreateConnector(dsModelTextType, 0, dsModelText, 5);

            data.CreateConnector(numberNode, 0, dsModelText, 2);
            data.CreateConnector(numberNode, 0, dsModelText, 3);

            #endregion

            return(migratedData);
        }
Exemple #9
0
        public static NodeMigrationData Migrate_0630_to_0700(NodeMigrationData data)
        {
            NodeMigrationData migratedData = new NodeMigrationData(data.Document);
            XmlElement        oldNode      = data.MigratedNodes.ElementAt(0);
            string            oldNodeId    = MigrationManager.GetGuidFromXmlElement(oldNode);

            //create the node itself
            XmlElement dsRevitNode = MigrationManager.CreateFunctionNodeFrom(oldNode);

            MigrationManager.SetFunctionSignature(dsRevitNode, "RevitNodes.dll",
                                                  "Solid.Cylinder", "Solid.Cylinder@Point,double,Vector,double");

            migratedData.AppendNode(dsRevitNode);
            string dsRevitNodeId = MigrationManager.GetGuidFromXmlElement(dsRevitNode);

            //create and reconnect the connecters
            PortId     oldInPort0 = new PortId(oldNodeId, 0, PortType.INPUT);
            XmlElement connector0 = data.FindFirstConnector(oldInPort0);

            PortId     oldInPort1 = new PortId(oldNodeId, 1, PortType.INPUT);
            XmlElement connector1 = data.FindFirstConnector(oldInPort1);

            PortId     oldInPort2 = new PortId(oldNodeId, 2, PortType.INPUT);
            XmlElement connector2 = data.FindFirstConnector(oldInPort2);

            PortId     oldInPort3 = new PortId(oldNodeId, 3, PortType.INPUT);
            XmlElement connector3 = data.FindFirstConnector(oldInPort3);

            PortId newInPort0 = new PortId(dsRevitNodeId, 0, PortType.INPUT);
            PortId newInPort1 = new PortId(dsRevitNodeId, 1, PortType.INPUT);
            PortId newInPort2 = new PortId(dsRevitNodeId, 2, PortType.INPUT);
            PortId newInPort3 = new PortId(dsRevitNodeId, 3, PortType.INPUT);

            data.ReconnectToPort(connector0, newInPort2);
            data.ReconnectToPort(connector1, newInPort0);
            data.ReconnectToPort(connector2, newInPort1);
            data.ReconnectToPort(connector3, newInPort3);

            // Add default values
            foreach (XmlNode child in oldNode.ChildNodes)
            {
                var newChild = child.Clone() as XmlElement;
                switch (newChild.GetAttribute("index"))
                {
                case "0":
                    if (connector0 != null)
                    {
                        break;
                    }
                    XmlElement zAxis0 = MigrationManager.CreateFunctionNode(
                        data.Document, oldNode, 1, "ProtoGeometry.dll",
                        "Vector.ZAxis", "Vector.ZAxis");
                    migratedData.AppendNode(zAxis0);
                    data.CreateConnector(zAxis0, 0, dsRevitNode, 2);
                    break;

                case "1":
                    if (connector1 != null)
                    {
                        break;
                    }
                    XmlElement cbn1 = MigrationManager.CreateCodeBlockNodeModelNode(
                        data.Document, oldNode, 0, "Point.ByCoordinates(0,0,0);");
                    migratedData.AppendNode(cbn1);
                    data.CreateConnector(cbn1, 0, dsRevitNode, 0);
                    break;

                case "2":
                    newChild.SetAttribute("index", "1");
                    dsRevitNode.AppendChild(newChild);
                    break;

                case "3":
                    dsRevitNode.AppendChild(newChild);
                    break;

                default:
                    break;
                }
            }

            return(migratedData);
        }