public void ReferenceCurve() { var model = dynSettings.Controller.DynamoModel; string samplePath = Path.Combine(_testPath, @".\ReferenceCurve.dyn"); string testPath = Path.GetFullPath(samplePath); model.Open(testPath); dynSettings.Controller.RunExpression(true); FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document); fec.OfClass(typeof(CurveElement)); //verify one model curve created int count = fec.ToElements().Count; Assert.IsInstanceOf(typeof(ModelCurve), fec.ToElements().First()); Assert.IsTrue(((ModelCurve)fec.ToElements().First()).IsReferenceLine); Assert.AreEqual(1, count); ElementId id = fec.ToElements().First().Id; //update any number node and verify //that the element gets updated not recreated var doubleNodes = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is dynBasicInteractive <double>); dynBasicInteractive <double> node = doubleNodes.First() as dynBasicInteractive <double>; node.Value = node.Value + .1; dynSettings.Controller.RunExpression(true); Assert.AreEqual(1, fec.ToElements().Count); Assert.AreEqual(id.IntegerValue, fec.ToElements().First().Id.IntegerValue); }
public void SwitchDocuments() { var model = dynSettings.Controller.DynamoModel; //open the workflow and run the expression string testPath = Path.Combine(_testPath, "ReferencePointTest.dyn"); model.Open(testPath); Assert.AreEqual(3, dynSettings.Controller.DynamoModel.Nodes.Count()); dynSettings.Controller.RunExpression(true); //verify we have a reference point FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document); fec.OfClass(typeof(ReferencePoint)); Assert.AreEqual(1, fec.ToElements().Count()); //open a new document and activate it UIDocument initialDoc = dynRevitSettings.Revit.ActiveUIDocument; string shellPath = Path.Combine(_testPath, @"empty1.rfa"); dynRevitSettings.Revit.OpenAndActivateDocument(shellPath); initialDoc.Document.Close(false); //assert that the doc is set on the controller Assert.IsNotNull(dynRevitSettings.Doc.Document); //update the double node so the graph reevaluates var doubleNodes = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is dynBasicInteractive <double>); dynBasicInteractive <double> node = doubleNodes.First() as dynBasicInteractive <double>; node.Value = node.Value + .1; //run the expression again dynSettings.Controller.RunExpression(true); fec = new FilteredElementCollector(dynRevitSettings.Doc.Document); fec.OfClass(typeof(ReferencePoint)); Assert.AreEqual(1, fec.ToElements().Count()); //finish out by restoring the original initialDoc = dynRevitSettings.Revit.ActiveUIDocument; shellPath = Path.Combine(_testPath, @"empty.rfa"); dynRevitSettings.Revit.OpenAndActivateDocument(shellPath); initialDoc.Document.Close(false); }