public void CanGetAreaBoundaries() { // Arrange var area = ElementSelector.ByElementId(316208, true) as Area; var expectedCurves = new List <List <Curve> >() { new List <Curve>() { Line.ByStartPointEndPoint( Point.ByCoordinates(6223.036, 3184.616, 0.000), Point.ByCoordinates(-8076.964, 3184.616, 0.000)), Line.ByStartPointEndPoint( Point.ByCoordinates(-8221.964, 3039.616, 0.000), Point.ByCoordinates(-8221.964, -2660.384, 0.000)), Line.ByStartPointEndPoint( Point.ByCoordinates(-8076.964, -2805.384, 0.000), Point.ByCoordinates(6223.036, -2805.384, 0.000)), Line.ByStartPointEndPoint( Point.ByCoordinates(6368.036, -2660.384, 0.000), Point.ByCoordinates(6368.036, 3039.616, 0.000)), } }; // Act var areaCurves = area.Boundaries; // Assert AssertListOfCurves(expectedCurves, areaCurves); }
public void CanUnjoinTwoElements() { var wall1 = ElementSelector.ByElementId(184176, true); var wall2 = ElementSelector.ByElementId(207960, true); var floor = ElementSelector.ByElementId(208259, true); var doc = DocumentManager.Instance.CurrentDBDocument; string expectedNotJoinedExceptionMessages = Revit.Properties.Resources.NotJoinedElements; // Are joined bool originalWall1AndWall2JoinedValue = JoinGeometryUtils.AreElementsJoined(doc, wall1.InternalElement, wall2.InternalElement); Assert.AreEqual(true, originalWall1AndWall2JoinedValue); // Are not joined bool originalWall2AndFloorJoinedValue = JoinGeometryUtils.AreElementsJoined(doc, wall2.InternalElement, floor.InternalElement); Assert.AreEqual(false, originalWall2AndFloorJoinedValue); wall1.UnjoinGeometry(wall2); bool newWall1AndWall2JoinedValue = wall1.AreJoined(wall2); // Are joined should have changed Assert.AreNotEqual(newWall1AndWall2JoinedValue, originalWall1AndWall2JoinedValue); // Should throw InvalidOperationException var ex = Assert.Throws <InvalidOperationException>(() => wall2.UnjoinGeometry(floor)); Assert.AreEqual(ex.Message, expectedNotJoinedExceptionMessages); }
public void CanGetWallTypeThermalProperties() { // Arrange var wall = ElementSelector.ByElementId(184176, true); double expectedWallTypeAbsorptance = 0.7; double expectedWallTypeHeatTransferCoefficient = 1E+30; int expectedWallTypeRoughness = 3; double expectedWallTypeThermalMass = 0; double expectedWallTypeThermalResistance = 0; // Act var wallType = wall.ElementType as WallType; var thermalProperties = wallType.GetThermalProperties(); double resultWallTypeAbsorptance = (double)thermalProperties["Absorptance"]; double resultWallTypeHeatTransferCoefficient = (double)thermalProperties["HeatTransferCoefficient"]; int resultWallTypeRoughness = (int)thermalProperties["Roughness"]; double resultWallTypeThermalMass = (double)thermalProperties["ThermalMass"]; double resultWallTypeThermalResistance = (double)thermalProperties["ThermalResistance"]; // Assert Assert.AreEqual(expectedWallTypeAbsorptance, resultWallTypeAbsorptance, Tolerance); Assert.AreEqual(expectedWallTypeHeatTransferCoefficient, resultWallTypeHeatTransferCoefficient, Tolerance); Assert.AreEqual(expectedWallTypeRoughness, resultWallTypeRoughness); Assert.AreEqual(expectedWallTypeThermalMass, resultWallTypeThermalMass, Tolerance); Assert.AreEqual(expectedWallTypeThermalResistance, resultWallTypeThermalResistance, Tolerance); }
public void CanSuccessfullyJoinTwoIntersectingElements() { // Arrange Document doc = DocumentManager.Instance.CurrentDBDocument; var primaryBeam = ElementSelector.ByElementId(208422, true); var nonIntersectingBeam = ElementSelector.ByElementId(209681, true); var joinedBeam = ElementSelector.ByElementId(208572, true); var notJoinedWall = ElementSelector.ByElementId(207960, true); var notJoinedFloor = ElementSelector.ByElementId(208259, true); var nonIntersectingTestExpectedExceptionType = typeof(System.NullReferenceException); string nonIntersectingTestExpectedExceptionString = "Elements are not intersecting"; // Act List <int> joinedTestExpectedOutcome = new List <int> { 208422, 208572 }; List <int> notJoinedTestExpectedOutcome = new List <int> { 207960, 208259 }; var alreadyJoinedOutcome = primaryBeam.JoinGeometry(joinedBeam).Select(elem => elem.Id).ToList(); var notJoinedIntersectingOutcome = notJoinedWall.JoinGeometry(notJoinedFloor).Select(elem => elem.Id).ToList(); // Assert Assert.AreEqual(joinedTestExpectedOutcome, alreadyJoinedOutcome); Assert.AreEqual(notJoinedTestExpectedOutcome, notJoinedIntersectingOutcome); // Non intersecting elements should throw a NullReferenceException // with the messages Elements are not intersecting var ex = Assert.Throws <InvalidOperationException>(() => primaryBeam.JoinGeometry(nonIntersectingBeam)); Assert.AreEqual(ex.Message, nonIntersectingTestExpectedExceptionString); }
public void CanGetRoofTypeThermalProperties() { // Arrange var roof = ElementSelector.ByElementId(316136, true); double expectedRoofTypeAbsorptance = 0.7; double expectedRoofTypeHeatTransferCoefficient = 0.15892777; int expectedRoofTypeRoughness = 3; double expectedRoofTypeThermalMass = 1056333.2; double expectedRoofTypeThermalResistance = 6.29216624; // Act var roofType = roof.ElementType as RoofType; var thermalProperties = roofType.GetThermalProperties(); double resultRoofTypeAbsorptance = (double)thermalProperties["Absorptance"]; double resultRoofTypeHeatTransferCoefficient = (double)thermalProperties["HeatTransferCoefficient"]; int resultRoofTypeRoughness = (int)thermalProperties["Roughness"]; double resultRoofTypeThermalMass = (double)thermalProperties["ThermalMass"]; double resultRoofTypeThermalResistance = (double)thermalProperties["ThermalResistance"]; // Assert Assert.AreEqual(expectedRoofTypeAbsorptance, resultRoofTypeAbsorptance, Tolerance); Assert.AreEqual(expectedRoofTypeHeatTransferCoefficient, resultRoofTypeHeatTransferCoefficient, Tolerance); Assert.AreEqual(expectedRoofTypeRoughness, resultRoofTypeRoughness); Assert.AreEqual(expectedRoofTypeThermalMass, resultRoofTypeThermalMass, Tolerance); Assert.AreEqual(expectedRoofTypeThermalResistance, resultRoofTypeThermalResistance, Tolerance); }
public void CanGetFloorTypeThermalProperties() { // Arrange var floor = ElementSelector.ByElementId(316138, true); double expectedFloorTypeAbsorptance = 0.7; double expectedFloorTypeHeatTransferCoefficient = 0.117437; int expectedFloorTypeRoughness = 3; double expectedFloorTypeThermalMass = 365549.43; double expectedFloorTypeThermalResistance = 8.515159; // Act var floorType = floor.ElementType as FloorType; var thermalProperties = floorType.GetThermalProperties(); double resultFloorTypeAbsorptance = (double)thermalProperties["Absorptance"]; double resultFloorTypeHeatTransferCoefficient = (double)thermalProperties["HeatTransferCoefficient"]; int resultFloorTypeRoughness = (int)thermalProperties["Roughness"]; double resultFloorTypeThermalMass = (double)thermalProperties["ThermalMass"]; double resultFloorTypeThermalResistance = (double)thermalProperties["ThermalResistance"]; // Assert Assert.AreEqual(expectedFloorTypeAbsorptance, resultFloorTypeAbsorptance, Tolerance); Assert.AreEqual(expectedFloorTypeHeatTransferCoefficient, resultFloorTypeHeatTransferCoefficient, Tolerance); Assert.AreEqual(expectedFloorTypeRoughness, resultFloorTypeRoughness); Assert.AreEqual(expectedFloorTypeThermalMass, resultFloorTypeThermalMass, Tolerance); Assert.AreEqual(expectedFloorTypeThermalResistance, resultFloorTypeThermalResistance, Tolerance); }
public void CanSetPinnedStatus() { string samplePath = Path.Combine(workingDirectory, @".\Element\setElementsPinStatus.dyn"); string testPath = Path.GetFullPath(samplePath); //check Select Model Element var elem = ElementSelector.ByElementId(184176, true); Assert.IsNotNull(elem); bool originalPinnedStatus = elem.InternalElement.Pinned; Assert.AreEqual(false, originalPinnedStatus); ViewModel.OpenCommand.Execute(testPath); RunCurrentModel(); //now flip the switch for setting the pinned status to true var boolNode = ViewModel.Model.CurrentWorkspace.Nodes.Where(x => x is CoreNodeModels.Input.BoolSelector).First(); bool boolNodeValue = true; ((CoreNodeModels.Input.BasicInteractive <bool>)boolNode).Value = boolNodeValue; RunCurrentModel(); bool newPinnedStatus = elem.InternalElement.Pinned; Assert.AreNotEqual(originalPinnedStatus, newPinnedStatus); Assert.AreEqual(boolNodeValue, newPinnedStatus); }
/// <summary> /// Gets the value of a family parameter of the current family type, this applies to all family parameters (instance and type). /// </summary> /// <param name="parameterName">A family parameter of the current type.</param> /// <param name="familyTypeName">The name of the family type.</param> /// <returns>The parameter value.</returns> public object GetParameterValueByName(string familyTypeName, string parameterName) { Autodesk.Revit.DB.FamilyParameter familyParameter = FamilyManager.get_Parameter(parameterName); if (familyParameter == null) { throw new InvalidOperationException(Properties.Resources.ParameterNotFound); } TransactionManager.Instance.EnsureInTransaction(this.InternalFamilyDocument); SetFamilyDocumentCurrentType(familyTypeName); TransactionManager.Instance.TransactionTaskDone(); switch (familyParameter.StorageType) { case Autodesk.Revit.DB.StorageType.Integer: return(FamilyManager.CurrentType.AsInteger(familyParameter) * UnitConverter.HostToDynamoFactor(familyParameter.Definition.GetSpecTypeId())); case Autodesk.Revit.DB.StorageType.Double: return(FamilyManager.CurrentType.AsDouble(familyParameter) * UnitConverter.HostToDynamoFactor(familyParameter.Definition.GetSpecTypeId())); case Autodesk.Revit.DB.StorageType.String: return(FamilyManager.CurrentType.AsString(familyParameter)); case Autodesk.Revit.DB.StorageType.ElementId: Elements.Element element = ElementSelector.ByElementId(FamilyManager.CurrentType.AsElementId(familyParameter).IntegerValue); return(element); default: return(null); } }
public void CanSetAndGetAboveValue() { // Arrange var dimension = ElementSelector.ByElementId(316269, true) as Dimension; var dimensionWithSegments = ElementSelector.ByElementId(316257, true) as Dimension; var expectedDimensionWithSegmentsValue = new List <string>() { "Above", "Above", }; var expectedDimensionValue = new List <string>() { "Above", }; // Act var oldDimensionAboveValue = dimension.AboveValue; var oldDimensionWithSegmentsAboveValue = dimensionWithSegments.AboveValue; var setNewAboveValueDimension = dimension.SetAboveValue("Above"); var setNewAboveValueDimensionWithSegment = dimensionWithSegments.SetAboveValue("Above"); var newAboveValueDimension = dimension.AboveValue; var newAboveValueDimensionWithSegment = dimensionWithSegments.AboveValue; // Assert Assert.AreNotEqual(oldDimensionAboveValue, newAboveValueDimension); Assert.AreNotEqual(oldDimensionWithSegmentsAboveValue, newAboveValueDimensionWithSegment); CollectionAssert.AreEqual(expectedDimensionValue, newAboveValueDimension); CollectionAssert.AreEqual(expectedDimensionWithSegmentsValue, newAboveValueDimensionWithSegment); }
public static IList <Element> OfElementType(Type elementType) { if (elementType == null) { return(null); } /* * (Konrad) According to RevitAPI documentation the quick filter * ElementClassFilter() has certain limitations that prevent it * from working on certain derived classes. In that case we need * to collect elements from base class and then perform additional * filtering to get our intended element set. */ if (ClassFilterExceptions.Contains(elementType)) { var type = GetClassFilterExceptionsValidType(elementType); return(new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .OfClass(type) .Where(x => x.GetType() == elementType) .Select(x => ElementSelector.ByElementId(x.Id.IntegerValue)) .ToList()); } var classFilter = new Autodesk.Revit.DB.ElementClassFilter(elementType); return(new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument) .WherePasses(classFilter) .ToElementIds() .Select(x => ElementSelector.ByElementId(x.IntegerValue)) .ToList()); }
public void CanGetSpaceFinishBoundary() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; List <List <Curve> > expectedBoundaries = new List <List <Curve> >() { new List <Curve>() { Line.ByStartPointEndPoint( Point.ByCoordinates(-741.333, 3845.025, 0.000), Point.ByCoordinates(-8451.333, 3845.025, 0.000)) as Curve, Line.ByStartPointEndPoint( Point.ByCoordinates(-8451.333, 3845.025, 0.000), Point.ByCoordinates(-8451.333, -214.975, 0.000)) as Curve, Line.ByStartPointEndPoint( Point.ByCoordinates(-8451.333, -214.975, 0.000), Point.ByCoordinates(-741.333, -214.975, 0.000)) as Curve, Line.ByStartPointEndPoint( Point.ByCoordinates(-741.333, -214.975, 0.000), Point.ByCoordinates(-741.333, 3845.025, 0.000)) as Curve } }; // Act var boundaryLines = space.FinishBoundary; // Assert AssertBoundaryLists(expectedBoundaries, boundaryLines); }
public void CanSaveFamilyInCurrentDocument() { // Arrange var saveableFamily = ElementSelector.ByElementId(110049, true); var noneditableFamily = ElementSelector.ByElementId(20915, true); string savedFamilyName = saveableFamily.Name + ".rfa"; string nonExistingTempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); string existingTempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(existingTempFolder); string expectedSavedFilePathNonExistingFolder = Path.GetFullPath(Path.Combine(nonExistingTempFolder, savedFamilyName)); string expectedSavedFilePathExistingFolder = Path.GetFullPath(Path.Combine(existingTempFolder, savedFamilyName)); // Act var doc = Document.Current; var resultSavedFamilyInNonExistingFolder = doc.SaveFamilyToFolder((Family)saveableFamily, nonExistingTempFolder); var resultSavedFamilyInExistingFolder = doc.SaveFamilyToFolder((Family)saveableFamily, existingTempFolder); var resultnoneditableFamily = Assert.Throws <Autodesk.Revit.Exceptions.ArgumentException>(() => doc.SaveFamilyToFolder((Family)noneditableFamily, existingTempFolder)); var fileExistInNonExistingFolder = File.Exists(Path.Combine(nonExistingTempFolder, savedFamilyName)); var fileExistInExistingFolder = File.Exists(Path.Combine(existingTempFolder, savedFamilyName)); // Assert Assert.AreEqual(expectedSavedFilePathNonExistingFolder, resultSavedFamilyInNonExistingFolder); Assert.AreEqual(expectedSavedFilePathExistingFolder, resultSavedFamilyInExistingFolder); Assert.IsTrue(fileExistInNonExistingFolder); Assert.IsTrue(fileExistInExistingFolder); // Clean up Directory.Delete(nonExistingTempFolder, true); Directory.Delete(existingTempFolder, true); }
public void CanGetSpaceCoreCenterBoundary() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; List <List <Curve> > expectedBoundaries = new List <List <Curve> >() { new List <Curve>() { Line.ByStartPointEndPoint( Point.ByCoordinates(-678.833, 3907.525, 0.000), Point.ByCoordinates(-8513.833, 3907.525, 0.000)) as Curve, Line.ByStartPointEndPoint( Point.ByCoordinates(-8513.833, 3907.525, 0.000), Point.ByCoordinates(-8513.833, -442.475, 0.000)) as Curve, Line.ByStartPointEndPoint( Point.ByCoordinates(-8513.833, -442.475, 0.000), Point.ByCoordinates(-678.833, -442.475, 0.000)) as Curve, Line.ByStartPointEndPoint( Point.ByCoordinates(-678.833, -442.475, 0.000), Point.ByCoordinates(-678.833, 3907.525, 0.000)) as Curve } }; // Act var boundaryLines = space.CoreCenterBoundary; // Assert AssertBoundaryLists(expectedBoundaries, boundaryLines); }
public void CanSuccessfullyGetElementPinnedStatus() { var pinnedElement = ElementSelector.ByElementId(184176, true); AssertElementPinnedStatusIs(pinnedElement, true); var unPinnedElement = ElementSelector.ByElementId(184324, true); AssertElementPinnedStatusIs(unPinnedElement, false); }
public void CanCheckIfGroupIsAttached() { // Arrange var modelGroup = ElementSelector.ByElementId(316699, true) as Group; var attachedGroup = ElementSelector.ByElementId(316701, true) as Group; // Assert Assert.AreEqual(false, modelGroup.IsAttached); Assert.AreEqual(true, attachedGroup.IsAttached); }
public void ByFace_ShouldCreateFaceWall() { Element elem = ElementSelector.ByElementId(205302); var refr = elem.ElementFaceReferences[0].InternalReference; var wallType = WallType.ByName("Generic - 5\""); FaceWall wall = FaceWall.ByFace(Autodesk.Revit.DB.WallLocationLine.CoreCenterline, wallType, refr); Assert.NotNull(wall); Assert.AreEqual(wall.GetType(), typeof(FaceWall)); Assert.NotNull(wall.InternalElement); }
public void CanCheckIfPointIsInsideSpace() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; var point1 = Point.ByCoordinates(-6166.333, 6435.025, 0.000); var point2 = Point.ByCoordinates(-6166.333, 383.025, 0.000); // Assert Assert.AreEqual(false, space.IsPointInsideSpace(point1)); Assert.AreEqual(true, space.IsPointInsideSpace(point2)); }
public void Solids_ExtractsSolidAccountingForInstanceTransform() { var ele = ElementSelector.ByElementId(46874, true); var solids = ele.Solids; Assert.AreEqual(1, solids.Length); var bbox = BoundingBox.ByGeometry(solids); bbox.MaxPoint.ShouldBeApproximately(-64.266, -7.999, 60.693, 1e-3); bbox.MinPoint.ShouldBeApproximately(-92.708, -38.479, 0, 1e-3); }
public void CanGetSpaceVolume() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; double expectedVolume = 125.2104; // Act double spaceVolume = space.Volume; // Assert Assert.AreEqual(expectedVolume, spaceVolume, Tolerance); }
public void CanGetSpaceArea() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; double expectedArea = 31.302; // Act double spaceArea = space.Area; // Assert Assert.AreEqual(expectedArea, spaceArea, Tolerance); }
public void ElementCurveReferences_ExtractsExpectedReferences() { var ele = ElementSelector.ByElementId(32107, true); var refs = ele.ElementCurveReferences; Assert.AreEqual(4, refs.Length); foreach (var refer in refs) { Assert.AreEqual(32107, refer.InternalReference.ElementId.IntegerValue); } }
public static object GetParameterValue(Autodesk.Revit.DB.Parameter param) { object result; switch (param.StorageType) { case StorageType.ElementId: int valueId = param.AsElementId().IntegerValue; if (valueId > 0) { // When the element is obtained here, to convert it to our element wrapper, it // need to be figured out whether this element is created by us. Here the existing // element wrappers will be checked. If there is one, its property to specify // whether it is created by us will be followed. If there is none, it means the // element is not created by us. var elem = ElementIDLifecycleManager <int> .GetInstance().GetFirstWrapper(valueId) as Element; result = ElementSelector.ByElementId(valueId, elem == null ? true : elem.IsRevitOwned); } else { int paramId = param.Id.IntegerValue; if (paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM || paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM_MT) { var categories = DocumentManager.Instance.CurrentDBDocument.Settings.Categories; result = new Category(categories.get_Item((BuiltInCategory)valueId)); } else { // For other cases, return a localized string result = param.AsValueString(); } } break; case StorageType.String: result = param.AsString(); break; case StorageType.Integer: result = param.AsInteger(); break; case StorageType.Double: result = param.AsDouble() * Revit.GeometryConversion.UnitConverter.HostToDynamoFactor(param.Definition.UnitType); break; default: throw new Exception(string.Format(Properties.Resources.ParameterWithoutStorageType, param)); } return(result); }
public void CanGetSpaceName() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; string expectedName = "Space"; // Act string spaceName = space.Name; // Assert Assert.AreEqual(expectedName, spaceName); }
public void Solids_ExtractsSolidAccountingForInstanceTransform() { var ele = ElementSelector.ByElementId(46874, true); var solids = ele.Solids; Assert.AreEqual(1, solids.Length); var bbox = BoundingBox.ByGeometry(solids); bbox.MaxPoint.ShouldBeApproximately(-210.846457, -26.243438, 199.124016, 1e-2); bbox.MinPoint.ShouldBeApproximately(-304.160105, -126.243438, 0, 1e-2); }
public void CanGetSpaceNumber() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; string expectedNumber = "1"; // Act string spaceNumber = space.Number; // Assert Assert.AreEqual(expectedNumber, spaceNumber); }
public static IList <Element> OfElementType(Type elementType) { var elFilter = new ElementClassFilter(elementType); var fec = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); fec.WherePasses(elFilter); var instances = fec.ToElements() .Select(x => ElementSelector.ByElementId(x.Id.IntegerValue)).ToList(); return(instances); }
public void CanGetSpaceHeight() { // Arrange var space = ElementSelector.ByElementId(316365, true) as Space; double expectedHeight = 4000; // Act double spaceHeight = space.Height; // Assert Assert.AreEqual(expectedHeight, spaceHeight, Tolerance); }
public void CanGetElevationMarkerViewCount() { // Arrange var elevationMarker = ElementSelector.ByElementId(327385, true) as Revit.Elements.ElevationMarker; var expectedViewCount = 3; // Act var elevationMarkerViewCount = elevationMarker.CurrentViewCount; // Assert Assert.AreEqual(expectedViewCount, elevationMarkerViewCount); }
public void CanSuccessfullySetAndGetElement() { var wall = ElementSelector.ByElementId(184176, true); var famSym = FamilyType.ByName("18\" x 18\""); var name = "Column"; wall.SetParameterByName(name, famSym); var sym = wall.GetParameterValueByName(name) as Element; Assert.NotNull(sym); Assert.AreEqual(sym.Name, "18\" x 18\""); }
public static IList <Element> AtLevel(Level arg) { var levFilter = new ElementLevelFilter(arg.InternalLevel.Id); var fec = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument); var instances = fec.WherePasses(levFilter) .WhereElementIsNotElementType() .ToElementIds() .Select(id => ElementSelector.ByElementId(id.IntegerValue)) .ToList(); return(instances); }