예제 #1
0
        public void CanGetElementTypeProperties()
        {
            // Arrange
            var wall   = ElementSelector.ByElementId(184176, true);
            var column = ElementSelector.ByElementId(184324, true);

            var expectedWallTypeName         = "Generic - 8\"";
            var expectedWallTypeFamilyName   = "Basic Wall";
            var expectedWallTypeCanBeDeleted = true;
            var expectedWallTypeCanBeCopied  = true;
            var expectedWallTypeCanBeRenamed = true;

            var expectedColumnTypeName         = "24\" x 24\"";
            var expectedColumnTypeFamilyName   = "Rectangular Column";
            var expectedColumnTypeCanBeDeleted = true;
            var expectedColumnTypeCanBeCopied  = true;
            var expectedColumnTypeCanBeRenamed = true;

            // Act
            var wallElementType   = wall.ElementType;
            var columnElementType = column.ElementType;

            var resultWallTypeName         = wallElementType.Name;
            var resultWallTypeFamilyName   = wallElementType.FamilyName;
            var resultWallTypeCanBeDeleted = wallElementType.CanBeDeleted;
            var resultWallTypeCanBeCopied  = wallElementType.CanBeCopied;
            var resultWallTypeCanBeRenamed = wallElementType.CanBeRenamed;

            var resultColumnTypeName         = columnElementType.Name;
            var resultColumnTypeFamilyName   = columnElementType.FamilyName;
            var resultColumnTypeCanBeDeleted = columnElementType.CanBeDeleted;
            var resultColumnTypeCanBeCopied  = columnElementType.CanBeCopied;
            var resultColumnTypeCanBeRenamed = columnElementType.CanBeRenamed;

            // Assert
            Assert.AreEqual(expectedWallTypeName, resultWallTypeName);
            Assert.AreEqual(expectedWallTypeFamilyName, resultWallTypeFamilyName);
            Assert.AreEqual(expectedWallTypeCanBeDeleted, resultWallTypeCanBeDeleted);
            Assert.AreEqual(expectedWallTypeCanBeCopied, resultWallTypeCanBeCopied);
            Assert.AreEqual(expectedWallTypeCanBeRenamed, resultWallTypeCanBeRenamed);

            Assert.AreEqual(expectedColumnTypeName, resultColumnTypeName);
            Assert.AreEqual(expectedColumnTypeFamilyName, resultColumnTypeFamilyName);
            Assert.AreEqual(expectedColumnTypeCanBeDeleted, resultColumnTypeCanBeDeleted);
            Assert.AreEqual(expectedColumnTypeCanBeCopied, resultColumnTypeCanBeCopied);
            Assert.AreEqual(expectedColumnTypeCanBeRenamed, resultColumnTypeCanBeRenamed);
        }
예제 #2
0
        public void CanGetFamilyInstanceSpace()
        {
            // Arrange
            var famInstance             = ElementSelector.ByElementId(316162, true) as FamilyInstance;
            var famInstanceOutsideSpace = ElementSelector.ByElementId(316286, true) as FamilyInstance;

            var expectedSpaceId = 316157;

            // Act
            var familyInstanceSpace = famInstance.Space;
            var spaceId             = familyInstanceSpace.Id;
            var outsideSpace        = famInstanceOutsideSpace.Space;

            // Assert
            Assert.AreEqual(expectedSpaceId, spaceId);
            Assert.IsNull(outsideSpace);
        }
예제 #3
0
        public static IList <Element> OfFamilyType(FamilySymbol familyType)
        {
            var instanceFilter = new ElementClassFilter(typeof(Autodesk.Revit.DB.FamilyInstance));
            var fec            = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);

            var familyInstances = fec.WherePasses(instanceFilter)
                                  .WhereElementIsNotElementType()
                                  .ToElements()
                                  .Cast <Autodesk.Revit.DB.FamilyInstance>();

            var matches = familyInstances.Where(x => x.Symbol.Id == familyType.InternalFamilySymbol.Id);

            var instances = matches
                            .Select(x => ElementSelector.ByElementId(x.Id.IntegerValue)).ToList();

            return(instances);
        }
예제 #4
0
        public void CanGetGroupType()
        {
            // Arrange
            var modelGroup    = ElementSelector.ByElementId(316699, true) as Group;
            var attachedGroup = ElementSelector.ByElementId(316701, true) as Group;

            var expectedModelGroupTypeId    = 316700;
            var expectedattachedGroupTypeId = 316702;

            // Act
            var modelGroupTypeId    = modelGroup.GroupType.Id;
            var attachedGroupTypeId = attachedGroup.GroupType.Id;

            // Assert
            Assert.AreEqual(expectedModelGroupTypeId, modelGroupTypeId);
            Assert.AreEqual(expectedattachedGroupTypeId, attachedGroupTypeId);
        }
예제 #5
0
        public static IList <Element> OfElementType(Type elementType)
        {
            if (elementType == null)
            {
                return(null);
            }

            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);
        }
예제 #6
0
        public void UpdatedGraphIsNotRunAgain_MAGN_8367()
        {
            var model = ViewModel.Model;

            string filePath = Path.Combine(workingDirectory, @".\Bugs\MAGN_8367.dyn");
            string testPath = Path.GetFullPath(filePath);

            ViewModel.OpenCommand.Execute(testPath);
            AssertNoDummyNodes();

            // check all the nodes and connectors are loaded
            Assert.AreEqual(6, model.CurrentWorkspace.Nodes.Count());
            Assert.AreEqual(7, model.CurrentWorkspace.Connectors.Count());

            RunCurrentModel();

            string selectNodeID    = "982d28d8-a6ea-45d0-ac23-9f7c0f88c312";
            var    selectNode      = GetNode <DSModelElementSelection>(selectNodeID) as DSModelElementSelection;
            string codeBlockNodeID = "d36ae6dc-ae6e-4ad8-b616-af73464e5f57";
            var    codeBlockNode   = GetNode <CodeBlockNodeModel>(codeBlockNodeID) as CodeBlockNodeModel;
            string colorNodeID     = "11192cef-552f-43bb-b5ab-42f809e285e0";
            var    colorNode       = GetNode <DSFunction>(colorNodeID) as DSFunction;

            // Change the selected element
            selectNode.UpdateSelection(new[] { ElementSelector.
                                               ByUniqueId("2049bcda-4652-4dce-8114-728cd33b120b-00000f4f").InternalElement });
            // Change the color to (0, 255, 255)
            colorNode.InPorts[1].Connectors.Remove(colorNode.InPorts[1].Connectors[0]);
            RunCurrentModel();

            // Change the selected element back to the first element
            selectNode.UpdateSelection(new[] { ElementSelector.
                                               ByUniqueId("350f68bb-624c-405f-b93f-f7e6ff82778b-00000910").InternalElement });
            // Change the color again to (0, 0, 255)
            colorNode.InPorts[2].Connectors.Remove(colorNode.InPorts[2].Connectors[0]);
            RunCurrentModel();

            // Now check the overriden color of element with ID of 2320 to be (0, 0, 255)
            var settings = DocumentManager.Instance.CurrentUIDocument.ActiveView.
                           GetElementOverrides(ElementSelector.
                                               ByUniqueId("350f68bb-624c-405f-b93f-f7e6ff82778b-00000910").InternalElement.Id);

            Assert.AreEqual(0, settings.ProjectionLineColor.Red);
            Assert.AreEqual(0, settings.ProjectionLineColor.Green);
            Assert.AreEqual(255, settings.ProjectionLineColor.Blue);
        }
예제 #7
0
        public void CanCreateElevationViewsByMarkerIndex()
        {
            // Arrange
            var elevationMarker = ElementSelector.ByElementId(327339, true) as Revit.Elements.ElevationMarker;
            var planView        = ElementSelector.ByElementId(312, true) as Revit.Elements.Views.View;

            var expectedViewName = "Elevation 8 - c";
            var index            = 2;

            // Act
            var elevationView     = elevationMarker.CreateElevationByMarkerIndex(planView, index);
            var elevationViewName = elevationView.Name;

            // Assert
            Assert.AreEqual(expectedViewName, elevationViewName);
            Assert.AreEqual(false, elevationMarker.InternalMarker.IsAvailableIndex(index));
        }
예제 #8
0
 public static TrackEvent GetEvent(ElementSelector elementSelector)
 {
     if (elementSelector.SelectorType == SelectorType.None)
     {
         return(null);
     }
     if (elementSelector.SelectorType == SelectorType.ByName)
     {
         var trackRegEx = new Regex(elementSelector.Name);
         return(MainContainer.Vegas.Project.Tracks.SelectMany(x => x.Events).FirstOrDefault(x => trackRegEx.IsMatch(x.Name) && x.IsAudio() == elementSelector.IsAudio()));
     }
     if (elementSelector.SelectorType == SelectorType.BySelection)
     {
         return(MainContainer.Vegas.Project.Tracks.SelectMany(x => x.Events).FirstOrDefault(x => x.Selected && x.IsAudio() == elementSelector.IsAudio()));
     }
     return(null);
 }
예제 #9
0
        public void CanCreateGroupFromListOfElements()
        {
            // Arrange
            List <int> elementIds = new List <int>()
            {
                184176, 184324
            };
            List <Element> elementsToGroup = elementIds.Select(id => ElementSelector.ByElementId(id, true)).ToList();

            // Act
            var group     = Group.ByElements(elementsToGroup);
            var memberIds = group.InternalGroup.GetMemberIds().Select(id => id.IntegerValue).ToList();

            // Assert
            Assert.IsNotNull(group);
            CollectionAssert.AreEqual(elementIds, memberIds);
        }
예제 #10
0
        public void CanGetFamilyInstanceRoom()
        {
            // Arrange
            var famInstance            = ElementSelector.ByElementId(316162, true) as FamilyInstance;
            var famInstanceOutsideRoom = ElementSelector.ByElementId(316286, true) as FamilyInstance;

            var expectedRoomId = 316151;

            // Act
            var familyInstanceRoom = famInstance.Room;
            var roomId             = familyInstanceRoom.Id;
            var outsideRoom        = famInstanceOutsideRoom.Room;

            // Assert
            Assert.AreEqual(expectedRoomId, roomId);
            Assert.IsNull(outsideRoom);
        }
예제 #11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document        doc             = uidoc.Document;
            ElementSelector elementSelector = new ElementSelector();

            elementSelector.SeclectElement(doc, uidoc);
            Element element = elementSelector.e;
            SampleCreateSharedParameter sampleCreateSharedParameter = new SampleCreateSharedParameter(doc, app);

            sampleCreateSharedParameter.LINK = @"C:\Users\OAI-IICM\Desktop\APIRevit-C#\Project\IICM\API_revit_IICM_1020\Define\Structural-Parameters.txt";
            sampleCreateSharedParameter.CreateSampleSharedParameters(element);
            return(Result.Succeeded);
        }
예제 #12
0
        public void ByFaceUVDivisionsRotation_ValidArgs()
        {
            var ele = ElementSelector.ByType <Autodesk.Revit.DB.Form>(true).FirstOrDefault();

            Assert.NotNull(ele);

            var form = ele as Form;
            var face = form.ElementFaceReferences.First();

            var divSrf = DividedSurface.ByFaceUVDivisionsAndRotation(face, 5, 6, 30);

            Assert.NotNull(divSrf);

            Assert.AreEqual(5, divSrf.UDivisions);
            Assert.AreEqual(6, divSrf.VDivisions);
            Assert.AreEqual(30.0, divSrf.Rotation, 0.001);
        }
예제 #13
0
        public void CanTransformElement()
        {
            // Arrange
            var delta                 = 0.001;
            var originPoint           = Coordinates.BasePoint();
            var fromCS                = CoordinateSystem.ByOrigin(originPoint);
            var translatedOriginPoint = originPoint.Translate(Vector.XAxis(), 10000) as Autodesk.DesignScript.Geometry.Point;
            var contextCS             = CoordinateSystem.ByOrigin(translatedOriginPoint).Rotate(translatedOriginPoint,
                                                                                                Vector.ZAxis(),
                                                                                                25);

            var wall = ElementSelector.ByElementId(316150) as Revit.Elements.FamilyInstance;
            var rectangularColumn = ElementSelector.ByElementId(318266) as Revit.Elements.FamilyInstance;
            var steelColumn       = ElementSelector.ByElementId(316180) as Revit.Elements.FamilyInstance;
            var lineBasedFamily   = ElementSelector.ByElementId(317296) as Revit.Elements.FamilyInstance;

            var expectedRectangularColumnLocation = Autodesk.DesignScript.Geometry.Point.ByCoordinates(4665.007, -2577.392, 0);
            var expectedLineBasedFamilyLocation   = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(Autodesk.DesignScript.Geometry.Point.ByCoordinates(6030.576, -1719.941, 0),
                                                                                                             Autodesk.DesignScript.Geometry.Point.ByCoordinates(7059.036, -494.270, 0));

            var originalRectangularColumnLocation = Autodesk.DesignScript.Geometry.Point.ByCoordinates(-5924.398, -81.245, 0);;
            var originalLineBasedFamilyLocation   = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(Autodesk.DesignScript.Geometry.Point.ByCoordinates(-4324.398, 118.755, 0),
                                                                                                             Autodesk.DesignScript.Geometry.Point.ByCoordinates(-2724.398, 118.755, 0));

            // Act
            var transformlineBasedFamily             = lineBasedFamily.Transform(fromCS, contextCS);
            var transformedlineBasedFamilyLocation   = transformlineBasedFamily.GetLocation() as Autodesk.DesignScript.Geometry.Line;
            var transformRectangularColumn           = rectangularColumn.Transform(fromCS, contextCS);
            var transformedRectangularColumnLocation = transformRectangularColumn.GetLocation() as Autodesk.DesignScript.Geometry.Point;
            var wallEx        = Assert.Throws <System.NullReferenceException>(() => wall.Transform(fromCS, contextCS));
            var steelColumnEx = Assert.Throws <System.NullReferenceException>(() => steelColumn.Transform(fromCS, contextCS));


            // Assert - Elements have moved
            Assert.AreNotEqual(originalRectangularColumnLocation.X, transformedRectangularColumnLocation.X);
            Assert.AreNotEqual(originalRectangularColumnLocation.Y, transformedRectangularColumnLocation.Y);
            Assert.AreNotEqual(originalLineBasedFamilyLocation.StartPoint.X, transformedlineBasedFamilyLocation.StartPoint.X);
            Assert.AreNotEqual(originalLineBasedFamilyLocation.StartPoint.Y, transformedlineBasedFamilyLocation.StartPoint.Y);

            // Assert - Elements are in correct position
            Assert.AreEqual(expectedRectangularColumnLocation.X, transformedRectangularColumnLocation.X, delta);
            Assert.AreEqual(expectedRectangularColumnLocation.Y, transformedRectangularColumnLocation.Y, delta);
            Assert.AreEqual(expectedLineBasedFamilyLocation.StartPoint.X, transformedlineBasedFamilyLocation.StartPoint.X, delta);
            Assert.AreEqual(expectedLineBasedFamilyLocation.StartPoint.Y, transformedlineBasedFamilyLocation.StartPoint.Y, delta);
        }
예제 #14
0
        public void CanGetAttachedDetailGroup()
        {
            // Arrange
            var modelGroup    = ElementSelector.ByElementId(316699, true) as Group;
            var attachedGroup = ElementSelector.ByElementId(316701, true) as Group;

            var expectedAttachedDetailGroup = new List <int>()
            {
                316702
            };

            // Act
            var attachedDetailGroup   = modelGroup.AttachedDetailGroup;
            var attachedDetailGroupId = attachedDetailGroup.Select(x => x.Id).ToList();

            // Assert
            CollectionAssert.AreEqual(expectedAttachedDetailGroup, attachedDetailGroupId);
        }
예제 #15
0
        public static IList <Element> AtLevel(Level arg)
        {
            if (arg == null)
            {
                return(null);
            }

            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);
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbSelector.Text))
            {
                lbSelectorError.Text = "Selector is required";
                return;
            }

            if (Selector == null)
            {
                Selector = new ElementSelector();
            }


            Selector.SelectorType = (ElementSelectorType)cbbSelectorType.SelectedValue;
            Selector.Selector     = tbSelector.Text;
            Close();
        }
예제 #17
0
        public void CanPlaceFamilyInstanceByTypeAndCoordinateSystem()
        {
            // Arrange
            var famType          = ElementSelector.ByElementId(131610, true) as FamilyType;
            var coordinateSystem = CoordinateSystem.ByOrigin(0, 0)
                                   .Rotate(Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(Point.ByCoordinates(0, 0), Vector.ByCoordinates(0, 0, 1)), 45);

            var expectedFacingOrientation = Vector.ByCoordinates(-0.707, 0.707, 0.000);

            // Act
            var familyInstance    = FamilyInstance.ByCoordinateSystem(famType, coordinateSystem);
            var facingOrientation = familyInstance.InternalFamilyInstance.FacingOrientation;

            // Assert
            Assert.AreEqual(expectedFacingOrientation.X, facingOrientation.X, Tolerance);
            Assert.AreEqual(expectedFacingOrientation.Y, facingOrientation.Y, Tolerance);
            Assert.AreEqual(expectedFacingOrientation.Z, facingOrientation.Z, Tolerance);
        }
예제 #18
0
        public void CanSuccessfullyDeleteElement()
        {
            // Id of wall
            const int wallId = 184176;

            // Get element from document
            using (Element wall = ElementSelector.ByElementId(wallId, true))
            {
                Assert.IsNotNull(wall);

                // Delete Element
                int[] deleted = Element.Delete(wall);

                // Confirm list of elements represent the wall requested to delete.
                Assert.AreEqual(1, deleted.Length);
                Assert.AreEqual(wallId, deleted[0]);
            }
        }
예제 #19
0
        public static IList <Element> OfCategory(Category category)
        {
            if (category == null)
            {
                return(null);
            }

            var catFilter = new ElementCategoryFilter(category.InternalCategory.Id);
            var fec       = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
            var instances =
                fec.WherePasses(catFilter)
                .WhereElementIsNotElementType()
                .ToElementIds()
                .Select(id => ElementSelector.ByElementId(id.IntegerValue))
                .ToList();

            return(instances);
        }
예제 #20
0
        public void CanCreateElevationMarker()
        {
            // Arrange
            var room = ElementSelector.ByElementId(316289, true);
            var elevationViewFamilyType = ElementSelector.ByElementId(86228, true);

            var expectedType            = typeof(Revit.Elements.ElevationMarker);
            var expectedLocation        = Autodesk.DesignScript.Geometry.Point.ByCoordinates(1392.616, 915.356, 0.000);
            var elevationMarkerLocation = room.GetLocation() as Autodesk.DesignScript.Geometry.Point;

            // Act
            var elevationMarker = Revit.Elements.ElevationMarker.ByViewTypeLocation(elevationViewFamilyType, elevationMarkerLocation, 100);

            var newElevationMarkerType = elevationMarker.GetType();

            // Assert
            Assert.AreEqual(expectedType, newElevationMarkerType);
        }
예제 #21
0
        public void AllSolidsConvert()
        {
            var allSolidsInDoc = ElementSelector.ByType <Autodesk.Revit.DB.Form>(true)
                                 .Cast <Revit.Elements.Form>()
                                 .SelectMany(x => x.InternalGeometry())
                                 .OfType <Autodesk.Revit.DB.Solid>()
                                 .ToList();

            foreach (var solid in allSolidsInDoc)
            {
                var asmSolid = solid.ToProtoType();

                asmSolid.Volume.ShouldBeApproximately(solid.Volume);
                asmSolid.Area.ShouldBeApproximately(solid.SurfaceArea);
                Assert.AreEqual(solid.Faces.Size, asmSolid.Faces.Length);
                asmSolid.Centroid().ShouldBeApproximately(solid.ComputeCentroid());
            }
        }
예제 #22
0
        public static Element ById(object id)
        {
            if (id == null)
            {
                return(null);
            }

            // handle ElementId types first
            if (id.GetType() == typeof(Autodesk.Revit.DB.ElementId))
            {
                return(ElementSelector.ByElementId(((Autodesk.Revit.DB.ElementId)id).IntegerValue));
            }

            var     idType = Type.GetTypeCode(id.GetType());
            int     intId;
            Element element;

            switch (idType)
            {
            case TypeCode.Int64:
                element = ElementSelector.ByElementId(Convert.ToInt32((long)id));
                break;

            case TypeCode.Int32:
                element = ElementSelector.ByElementId((int)id);
                break;

            case TypeCode.String:
                string idString = (string)id;
                if (Int32.TryParse(idString, out intId))
                {
                    element = ElementSelector.ByElementId(intId);
                    break;
                }

                element = ElementSelector.ByUniqueId(idString);
                break;

            default:
                throw new InvalidOperationException(Revit.Properties.Resources.InvalidElementId);
            }

            return(element);
        }
예제 #23
0
        public void CanUnjoinListOfElements()
        {
            var wall1 = ElementSelector.ByElementId(184176, true);
            var wall2 = ElementSelector.ByElementId(207960, true);
            var floor = ElementSelector.ByElementId(208259, true);
            var doc   = DocumentManager.Instance.CurrentDBDocument;

            // Are joined
            bool originalWall1AndWall2JoinedValue = JoinGeometryUtils.AreElementsJoined(doc,
                                                                                        wall1.InternalElement,
                                                                                        wall2.InternalElement);

            Assert.AreEqual(true, originalWall1AndWall2JoinedValue);
            // Are joined
            bool originalWall1AndFloorJoinedValue = JoinGeometryUtils.AreElementsJoined(doc,
                                                                                        wall1.InternalElement,
                                                                                        floor.InternalElement);

            Assert.AreEqual(true, originalWall1AndFloorJoinedValue);
            // Are not joined
            bool originalWall2AndFloorJoinedValue = JoinGeometryUtils.AreElementsJoined(doc,
                                                                                        wall2.InternalElement,
                                                                                        floor.InternalElement);

            Assert.AreEqual(false, originalWall2AndFloorJoinedValue);

            var elementList = new List <Element>()
            {
                wall1, wall2, floor
            };

            Element.UnjoinAllGeometry(elementList);

            bool newWall1AndWall2JoinedValue = wall1.AreJoined(wall2);
            bool newWall1AndFloorJoinedValue = wall1.AreJoined(floor);
            bool newWall2AndFloorJoinedValue = wall2.AreJoined(floor);

            // Are joined should have changed
            Assert.AreNotEqual(newWall1AndWall2JoinedValue, originalWall1AndWall2JoinedValue);
            // Are joined should have changed
            Assert.AreNotEqual(newWall1AndFloorJoinedValue, originalWall1AndFloorJoinedValue);
            // Are joined should be the same
            Assert.AreEqual(newWall2AndFloorJoinedValue, originalWall2AndFloorJoinedValue);
        }
예제 #24
0
        public void SetParameterByName_Element_CanSuccessfullySetMaterialByElement()
        {
            var mat = Revit.Elements.Material.ByName("Glass");

            var ele = ElementSelector.ByType <Autodesk.Revit.DB.FamilyInstance>(true).First();

            var paramName = "Body Material";
            var elemId0   = ele.GetParameterValueByName(paramName);

            Assert.AreNotEqual(mat.Id, elemId0);

            ele.SetParameterByName(paramName, mat);

            DocumentManager.Regenerate();

            var elemId1 = ele.GetParameterValueByName(paramName) as Element;

            Assert.AreEqual(mat.InternalElement.Id, elemId1.InternalElement.Id);
        }
예제 #25
0
        public void Faces_ExtractsFacesAccountingForInstanceTransform()
        {
            var ele   = ElementSelector.ByElementId(46874, true);
            var faces = ele.Faces;

            Assert.AreEqual(6, faces.Length);

            var bbox = BoundingBox.ByGeometry(faces);

            bbox.MaxPoint.ShouldBeApproximately(-64.266, -7.999, 60.693, 1e-3);
            bbox.MinPoint.ShouldBeApproximately(-92.708, -38.479, 0, 1e-3);

            var refs = faces.Select(x => ElementFaceReference.TryGetFaceReference(x));

            foreach (var refer in refs)
            {
                Assert.AreEqual(46874, refer.InternalReference.ElementId.IntegerValue);
            }
        }
예제 #26
0
 /// <summary>
 /// This Method is called when occurs an event in the unity scene
 /// </summary>
 private void OnSceneGUI()
 {
     if (currentSceneview != null)
     {
         objectSelected = ElementSelector.GetSelectedObject();
         if (objectSelected != null)
         {
             Debug.Log(objectSelected.name);
         }
         else
         {
             Debug.Log("No Selected Object");
         }
     }
     else
     {
         objectSelected = null;
     }
 }
예제 #27
0
        public void Faces_ExtractsFacesAccountingForInstanceTransform()
        {
            var ele   = ElementSelector.ByElementId(46874, true);
            var faces = ele.Faces;

            Assert.AreEqual(6, faces.Length);

            var bbox = BoundingBox.ByGeometry(faces);

            bbox.MaxPoint.ShouldBeApproximately(-210.846457, -26.243438, 199.124016, 1e-2);
            bbox.MinPoint.ShouldBeApproximately(-304.160105, -126.243438, 0, 1e-2);

            var refs = faces.Select(x => ElementFaceReference.TryGetFaceReference(x));

            foreach (var refer in refs)
            {
                Assert.AreEqual(46874, refer.InternalReference.ElementId.IntegerValue);
            }
        }
예제 #28
0
 private MatchInfo SearchIn(XmlNode searchFor,
                            IList <XmlNode> searchIn,
                            ICollection <int> availableIndexes,
                            int fromInclusive, int toExclusive,
                            ElementSelector e)
 {
     for (int i = fromInclusive; i < toExclusive; i++)
     {
         if (!availableIndexes.Contains(i))
         {
             continue;
         }
         if (NodesMatch(searchFor, searchIn[i], e))
         {
             return(new MatchInfo(searchIn[i], i));
         }
     }
     return(null);
 }
예제 #29
0
        public void CanGetGroupLocation()
        {
            // Arrange
            var modelGroup    = ElementSelector.ByElementId(316699, true) as Group;
            var attachedGroup = ElementSelector.ByElementId(316701, true) as Group;

            var expectedModelGroupLocation = Point.ByCoordinates(-5838.369, 4122.718, 0.000);
            var expectedAttachedGroupLocationExceptionMessage = Revit.Properties.Resources.AttachedGroupLocation;

            // Act
            var modelGroupLocation    = modelGroup.Location;
            var attachedGroupLocation = Assert.Throws <InvalidOperationException>(() => GetLocation(attachedGroup));

            // Assert
            Assert.AreEqual(expectedModelGroupLocation.X, modelGroupLocation.X, Tolerance);
            Assert.AreEqual(expectedModelGroupLocation.Y, modelGroupLocation.Y, Tolerance);
            Assert.AreEqual(expectedModelGroupLocation.Z, modelGroupLocation.Z, Tolerance);
            Assert.AreEqual(expectedAttachedGroupLocationExceptionMessage, attachedGroupLocation.Message);
        }
예제 #30
0
        /// <summary>
        /// Selects two elements as matching if the child elements selected
        /// via XPath match using the given childSelector.
        /// </summary>
        /// <remarks>
        ///   <para>
        ///     The xpath expression should yield elements.  Two elements
        ///     match if a DefaultNodeMatcher applied to the selected children
        ///     finds matching pairs for all children.
        ///   </para>
        /// </remarks>
        /// <param name="xpath">XPath expression applied in the context of the
        /// elements to chose from that selects the children to compare.</param>
        /// <param name="childSelector">ElementSelector to apply to the selected children.</param>
        /// <param name="prefix2Uri">provides prefix mapping for
        /// namespace prefixes used inside the xpath expression. Maps
        /// from prefix to namespace URI</param>
        public static ElementSelector ByXPath(string xpath,
                                              IDictionary <string, string> prefix2Uri,
                                              ElementSelector childSelector)
        {
            IXPathEngine engine = new XPathEngine();

            if (prefix2Uri != null)
            {
                engine.NamespaceContext = prefix2Uri;
            }
            INodeMatcher nm = new DefaultNodeMatcher(childSelector);

            return((control, test) => {
                IEnumerable <XmlNode> controlChildren = engine.SelectNodes(xpath, control);
                int expected = controlChildren.Count();
                int matched = nm.Match(controlChildren, engine.SelectNodes(xpath, test)).Count();
                return expected == matched;
            });
        }
예제 #31
0
        private void ByNameAndText_SingleLevel(ElementSelector s)
        {
            XmlElement control = doc.CreateElement(FOO);
            control.AppendChild(doc.CreateTextNode(BAR));
            XmlElement equal = doc.CreateElement(FOO);
            equal.AppendChild(doc.CreateTextNode(BAR));
            XmlElement equalC = doc.CreateElement(FOO);
            equalC.AppendChild(doc.CreateCDataSection(BAR));
            XmlElement noText = doc.CreateElement(FOO);
            XmlElement differentText = doc.CreateElement(FOO);
            differentText.AppendChild(doc.CreateTextNode(BAR));
            differentText.AppendChild(doc.CreateTextNode(BAR));

            Assert.IsTrue(s(control, equal));
            Assert.IsTrue(s(control, equalC));
            Assert.IsFalse(s(control, noText));
            Assert.IsFalse(s(control, differentText));
        }
예제 #32
0
        private void PureElementNameComparisons(ElementSelector s)
        {
            XmlElement control = doc.CreateElement(FOO);
            XmlElement equal = doc.CreateElement(FOO);
            XmlElement different = doc.CreateElement(BAR);
            XmlElement controlNS = doc.CreateElement(BAR, FOO, SOME_URI);

            Assert.IsFalse(s(null, null));
            Assert.IsFalse(s(null, control));
            Assert.IsFalse(s(control, null));
            Assert.IsTrue(s(control, equal));
            Assert.IsFalse(s(control, different));
            Assert.IsFalse(s(control, controlNS));
            Assert.IsTrue(s(doc.CreateElement(FOO, SOME_URI), controlNS));
        }
예제 #33
0
 public DefaultNodeMatcher(ElementSelector es)
     : this(es, DefaultNodeTypeMatcher)
 {
 }
예제 #34
0
 public DefaultNodeMatcher(ElementSelector es, NodeTypeMatcher ntm)
 {
     elementSelector = es;
     nodeTypeMatcher = ntm;
 }