//在族实例上定位连接点 private XYZ LocatePointOnFamilyInstance(FamilyInstance fi, Direction dir) { //找到工井族文件中左边界或右边界的几何体,利用id定位 Options opt = new Options(); opt.IncludeNonVisibleObjects = true;//很重要,由于view为null需要将不可见的对象变为可见,否则提取空集 GeometryElement ge = null; switch (dir) { case (Direction.left): ge = welldoc.GetElement(new ElementId(leftId)).get_Geometry(opt); break; case (Direction.right): ge = welldoc.GetElement(new ElementId(rightId)).get_Geometry(opt); break; } //提取集合体上的面元素 Solid solid = null; foreach (GeometryObject obj in ge) { if (obj is Solid) { solid = obj as Solid; break; } } FaceArray fcArr = null; if (solid != null) { fcArr = solid.Faces; } //找到边界的面,并将面原点的族坐标转换为模型坐标 Transform trans = null; Options opt1 = new Options(); opt1.ComputeReferences = false; opt1.View = doc.ActiveView; GeometryElement geoElement = fi.get_Geometry(opt1); foreach (GeometryObject obj in geoElement) //利用GeometryInstrance的Transform提取坐标转换矩阵 { if (obj is GeometryInstance) { GeometryInstance inst = obj as GeometryInstance; trans = inst.Transform; break; } } EdgeArray edArr = solid.Edges; XYZ planeOrigin = (fcArr.get_Item(0) as PlanarFace).Origin; return(trans.OfPoint(new XYZ(planeOrigin.X, planeOrigin.Y + edArr.get_Item(0).ApproximateLength / 2, planeOrigin.Z - edArr.get_Item(1).ApproximateLength / 2))); }
/// <summary> /// Retrieve all faces from the first solid /// encountered in the given geometry element. /// </summary> /// <param name="geoElement">geometry element</param> /// <returns>faces</returns> public FaceArray GetFacesFrom(GeometryElement geoElement) { //GeometryObjectArray geoElems = geoElement.Objects; foreach (object o in geoElement) { Solid geoSolid = o as Solid; if (null == geoSolid) { GeometryInstance instance = o as GeometryInstance; if (null == instance) { continue; } GeometryElement geoElement2 = instance.SymbolGeometry; _matrix = instance.Transform; if (0 == geoElement2.Count <GeometryObject>()) { continue; } return(GetFacesFrom(geoElement2)); } FaceArray faces = geoSolid.Faces; if (faces == null) { continue; } if (faces.Size == 0) { continue; } return(geoSolid.Faces); } return(null); }
/// <summary> /// get necessary data when create AreaReinforcement on a horizontal floor /// </summary> /// <param name="floor">floor on which to create AreaReinforcemen</param> /// <param name="refer">reference of the horizontal face on the floor</param> /// <param name="curves">curves compose the horizontal face of the floor</param> /// <returns>is successful</returns> public bool GetFloorGeom(Floor floor, ref Reference refer, ref IList <Curve> curves) { //get horizontal face reference FaceArray faces = GeomUtil.GetFaces(floor); foreach (Face face in faces) { if (GeomUtil.IsHorizontalFace(face)) { refer = face.Reference; break; } } //no proper reference if (null == refer) { return(false); } //check the analytical model profile is rectangular AnalyticalModel model = floor.GetAnalyticalModel(); if (null == model) { return(false); } curves = model.GetCurves(AnalyticalCurveType.ActiveCurves); if (!GeomUtil.IsRectangular(curves)) { return(false); } return(true); }
/// <summary> /// The method is used to get extrusion's face along to the specified parameters /// </summary> /// <param name="extrusion">the extrusion</param> /// <param name="view">options view</param> /// <param name="ExtOrInt">If true indicate getting exterior extrusion face, else getting interior extrusion face</param> /// <returns>the face</returns> static public Face GetExtrusionFace(Extrusion extrusion, View view, bool ExtOrInt) { Face face = null; FaceArray faces = null; if (extrusion.IsSolid) { Options options = new Options(); options.ComputeReferences = true; options.View = view; GeometryObjectArray geoArr = extrusion.get_Geometry(options).Objects; foreach (GeometryObject geoObj in geoArr) { if (geoObj is Solid) { Solid s = geoObj as Solid; faces = s.Faces; } } if (ExtOrInt) { face = GetExteriorFace(faces); } else { face = GetInteriorFace(faces); } } return(face); }
public static Face GetWallFace(Wall wall, View view, WallSide side) { Face face = null; FaceArray faces = new FaceArray(); Options options = new Options(); options.ComputeReferences = true; options.View = view; if (wall != null) { IEnumerator <GeometryObject> objects = wall.get_Geometry(options).GetEnumerator(); while (objects.MoveNext()) { var currentObject = objects.Current; var solid = currentObject as Solid; if (solid != null) { faces = solid.Faces; } } face = GetFace(faces, side); } return(face); }
public static Face GetFace(FaceArray faces, WallSide side) { double elevation = 0; double tempElevation = 0; Mesh mesh; Face face = null; foreach (Face _face in faces) { tempElevation = 0; mesh = _face.Triangulate(); foreach (XYZ xyz in mesh.Vertices) { tempElevation += xyz.Y; } tempElevation /= mesh.Vertices.Count; if (side == WallSide.Exterior && (elevation < tempElevation || null == face)) { face = _face; elevation = tempElevation; } else if (side == WallSide.Interior && (elevation > tempElevation || null == face)) { face = _face; elevation = tempElevation; } } return(face); }
static Face GetClosestFace(Element e, XYZ p, XYZ normal, Options opt) { Face face = null; double minDistance = double.MaxValue; GeometryElement geo = e.get_Geometry(opt); foreach (GeometryObject obj in geo) { Solid solid = obj as Solid; if (solid != null) { FaceArray fa = solid.Faces; foreach (Face f in fa) { PlanarFace pf = f as PlanarFace; if (null != pf && IsParallel(normal, pf.FaceNormal)) { XYZ v = p - pf.Origin; double d = v.DotProduct(-pf.FaceNormal); if (d < minDistance) { face = f; minDistance = d; } } } } } return(face); }
/// <summary> /// Get edges of element's profile /// </summary> /// <param name="elem">Selected element</param> public List <List <Edge> > GetFaces(Autodesk.Revit.DB.Element elem) { List <List <Edge> > faceEdges = new List <List <Edge> >(); Options options = m_appCreator.NewGeometryOptions(); options.DetailLevel = DetailLevels.Medium; options.ComputeReferences = true; Autodesk.Revit.DB.GeometryElement geoElem = elem.get_Geometry(options); GeometryObjectArray gObjects = geoElem.Objects; foreach (GeometryObject geo in gObjects) { Solid solid = geo as Solid; if (solid != null) { EdgeArray edges = solid.Edges; FaceArray faces = solid.Faces; foreach (Face face in faces) { EdgeArrayArray edgeArrarr = face.EdgeLoops; foreach (EdgeArray edgeArr in edgeArrarr) { List <Edge> edgesList = new List <Edge>(); foreach (Edge edge in edgeArr) { edgesList.Add(edge); } faceEdges.Add(edgesList); } } } } return(faceEdges); }
public static IEnumerable <Face> ToIEnumerable(FaceArray faceArray) { foreach (var item in faceArray) { yield return(item as Face); } }
/// <summary> /// The method is used to get extrusion's face along to the specified parameters /// </summary> /// <param name="extrusion">the extrusion</param> /// <param name="view">options view</param> /// <param name="ExtOrInt">If true indicate getting exterior extrusion face, else getting interior extrusion face</param> /// <returns>the face</returns> static public Face GetExtrusionFace(Extrusion extrusion, View view, bool ExtOrInt) { Face face = null; FaceArray faces = null; if (extrusion.IsSolid) { Options options = new Options(); options.ComputeReferences = true; options.View = view; //GeometryObjectArray geoArr = extrusion.get_Geometry(options).Objects; IEnumerator <GeometryObject> Objects = extrusion.get_Geometry(options).GetEnumerator(); //foreach (GeometryObject geoObj in geoArr) while (Objects.MoveNext()) { GeometryObject geoObj = Objects.Current; if (geoObj is Solid) { Solid s = geoObj as Solid; faces = s.Faces; } } if (ExtOrInt) { face = GetExteriorFace(faces); } else { face = GetInteriorFace(faces); } } return(face); }
/// <summary> /// Creates a new CurtainSystem. /// </summary> /// <param name="doc"></param> /// <param name="typeName"></param> /// <param name="faces"></param> /// <returns></returns> public static CurtainSystem CreateCurtainSystem(this Document doc, FaceArray faces, string typeName = null) { if (doc is null) { throw new ArgumentNullException(nameof(doc)); } if (faces is null) { throw new ArgumentNullException(nameof(faces)); } var findType = doc.GetTypeList <CurtainSystemType>().FirstOrDefault(f => f.Name.Contains(typeName)); if (findType != null) { return(doc.Create.NewCurtainSystem(faces, findType)); } var defaultTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.CurtainSystemType); var defaultType = doc.GetElement(defaultTypeId) as CurtainSystemType; var cloneType = defaultType?.Duplicate(typeName) as CurtainSystemType; return(doc.Create.NewCurtainSystem(faces, cloneType)); }
/// <summary> /// Get all points of the Slab /// </summary> /// <returns>points array stores all the points on slab</returns> public EdgeArray GetFloorEdges() { EdgeArray edges = new EdgeArray(); Options options = m_commandData.Application.Application.Create.NewGeometryOptions(); options.DetailLevel = DetailLevels.Medium; //make sure references to geometric objects are computed. options.ComputeReferences = true; Autodesk.Revit.DB.GeometryElement geoElem = m_floor.get_Geometry(options); GeometryObjectArray gObjects = geoElem.Objects; //get all the edges in the Geometry object foreach (GeometryObject geo in gObjects) { Solid solid = geo as Solid; if (solid != null) { FaceArray faces = solid.Faces; foreach (Face face in faces) { EdgeArrayArray edgeArrarr = face.EdgeLoops; foreach (EdgeArray edgeArr in edgeArrarr) { foreach (Edge edge in edgeArr) { edges.Append(edge); } } } } } return(edges); }
private void SolidData(GeometryObject obj) { Solid solid = obj as Solid; if (null == solid) { return; } FaceArray faces = solid.Faces; if (faces.Size == 0) { return; } foreach (Face f in faces) { Mesh mesh = f.Triangulate(); if (null == mesh) { return; } MeshData(mesh); } }
static TessellatedShapeBuilderResult GetTessellatedSolid( Document doc, Solid transientSolid) { TessellatedShapeBuilder builder = new TessellatedShapeBuilder(); ElementId idMaterial = new FilteredElementCollector(doc) .OfClass(typeof(Material)) .FirstElementId(); ElementId idGraphicsStyle = new FilteredElementCollector(doc) .OfClass(typeof(GraphicsStyle)) .FirstOrDefault <Element>(gs => gs.Name.Equals("Walls")) .Id; builder.OpenConnectedFaceSet(true); FaceArray faceArray = transientSolid.Faces; foreach (Face face in faceArray) { List <XYZ> triFace = new List <XYZ>(3); Mesh mesh = face.Triangulate(); int triCount = mesh.NumTriangles; for (int i = 0; i < triCount; i++) { triFace.Clear(); for (int n = 0; n < 3; n++) { triFace.Add(mesh.get_Triangle(i).get_Vertex(n)); } builder.AddFace(new TessellatedFace( triFace, idMaterial)); } } builder.CloseConnectedFaceSet(); //return builder.Build( // TessellatedShapeBuilderTarget.Solid, // TessellatedShapeBuilderFallback.Abort, // idGraphicsStyle ); // 2016 builder.Fallback = TessellatedShapeBuilderFallback.Abort; builder.Target = TessellatedShapeBuilderTarget.Solid; builder.GraphicsStyleId = idGraphicsStyle; builder.Build(); // 2020 return(builder.GetBuildResult()); }
public void PaintSolid(Document doc, Solid s, double value) { int schemaId = -1; var rnd = new Random(); View view = doc.ActiveView; using (Transaction transaction = new Transaction(doc)) { if (transaction.Start("Create model curves") == TransactionStatus.Started) { if (view.AnalysisDisplayStyleId == ElementId.InvalidElementId) { CreateAVFDisplayStyle(doc, view); } SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (null == sfm) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } if (-1 != schemaId) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(schemaId)) { schemaId = -1; } } if (-1 == schemaId) { AnalysisResultSchema resultSchema1 = new AnalysisResultSchema(rnd.Next().ToString(), "Description"); schemaId = sfm.RegisterResult(resultSchema1); } FaceArray faces = s.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = new List <UV>(); List <double> doubleList = new List <double>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); BoundingBoxUV bb = face.GetBoundingBox(); uvPts.Add(bb.Min); doubleList.Add(value); valList.Add(new ValueAtPoint(doubleList)); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, schemaId); } transaction.Commit(); } } }
/// <summary> /// Determine the boundary polygons of the lowest /// horizontal planar face of the given solid. /// </summary> /// <param name="polygons">Return polygonal boundary /// loops of lowest horizontal face, i.e. profile of /// circumference and holes</param> /// <param name="solid">Input solid</param> /// <returns>False if no horizontal planar face was /// found, else true</returns> static bool GetBoundary( List <List <XYZ> > polygons, Solid solid) { PlanarFace lowest = null; FaceArray faces = solid.Faces; foreach (Face f in faces) { PlanarFace pf = f as PlanarFace; if (null != pf && Util.IsHorizontal(pf)) { if ((null == lowest) || (pf.Origin.Z < lowest.Origin.Z)) { lowest = pf; } } } if (null != lowest) { XYZ p, q = XYZ.Zero; bool first; int i, n; EdgeArrayArray loops = lowest.EdgeLoops; foreach (EdgeArray loop in loops) { List <XYZ> vertices = new List <XYZ>(); first = true; foreach (Edge e in loop) { IList <XYZ> points = e.Tessellate(); p = points[0]; if (!first) { Debug.Assert(p.IsAlmostEqualTo(q), "expected subsequent start point" + " to equal previous end point"); } n = points.Count; q = points[n - 1]; for (i = 0; i < n - 1; ++i) { XYZ v = points[i]; v -= _offset * XYZ.BasisZ; vertices.Add(v); } } q -= _offset * XYZ.BasisZ; Debug.Assert(q.IsAlmostEqualTo(vertices[0]), "expected last end point to equal" + " first start point"); polygons.Add(vertices); } } return(null != lowest); }
/// <summary> /// Retrieve all faces from the /// given element's geometry solid. /// </summary> private void GetFaces() { Options geoOptions = _appCreator.NewGeometryOptions(); geoOptions.ComputeReferences = true; GeometryElement geoElem = _element.get_Geometry(geoOptions); _faces = GetFacesFrom(geoElem); }
protected IEnumerable <Autodesk.Revit.DB.Face> GetFaces(Autodesk.Revit.DB.Options options) { var geomElem = this.InternalElement.get_Geometry(options); var faces = new FaceArray(); GetFaces(geomElem, ref faces); return(faces.Cast <Autodesk.Revit.DB.Face>()); }
internal static void ShowSolids(Document doc, IEnumerable <Solid> solids, IEnumerable <double> values) { SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1); } if (_SchemaId != -1) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(_SchemaId)) { _SchemaId = -1; } } if (_SchemaId == -1) { _SchemaId = registerResults(sfm, "ShowChanges", "Description"); } List <double> valueList = values.ToList(); int i = 0; foreach (Solid s in solids) { double value = valueList[i]; i++; FaceArray faces = s.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = new List <UV>(); List <double> doubleList = new List <double>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); BoundingBoxUV bb = face.GetBoundingBox(); uvPts.Add(bb.Min); doubleList.Add(value); valList.Add(new ValueAtPoint(doubleList)); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, _SchemaId); } } updateView(doc.ActiveView, StyleEnum.Faces); }
/// <summary> /// get necessary data when create AreaReinforcement on a straight wall /// </summary> /// <param name="wall">wall on which to create AreaReinforcemen</param> /// <param name="refer">reference of the vertical straight face on the wall</param> /// <param name="curves">curves compose the vertical face of the wall</param> /// <returns>is successful</returns> public bool GetWallGeom(Wall wall, ref Reference refer, ref CurveArray curves) { FaceArray faces = GeomUtil.GetFaces(wall); LocationCurve locCurve = wall.Location as LocationCurve; //unless API has bug, locCurve can't be null if (null == locCurve) { return(false); } //check the location is line Line locLine = locCurve.Curve as Line; if (null == locLine) { return(false); } //get the face reference foreach (Face face in faces) { if (GeomUtil.IsParallel(face, locLine)) { refer = face.Reference; break; } } //can't find proper reference if (null == refer) { return(false); } //check the analytical model profile is rectangular AnalyticalModel model = wall.GetAnalyticalModel(); if (null == model) { return(false); } IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves); curves = m_currentDoc.Application.Create.NewCurveArray(); foreach (Curve curve in curveList) { curves.Append(curve); } if (!GeomUtil.IsRectangular(curves)) { return(false); } return(true); }
public bool ResizeElement() { List <Solid> solidList = GetSolid(); if (solidList.Count == 0) { return(false); } FaceArray faceArray = solidList[0].Faces; List <double> areaList = new List <double>(faceArray.Size); int top = 0; int bottom = 0; for (int i = 0; i < faceArray.Size; i++) { areaList.Add(faceArray.get_Item(i).Area); if (i > 0) { if (areaList[i] > areaList[top]) { top = i; } } } for (int i = 0; i < areaList.Count; i++) { if (i == top) { continue; } if (Math.Abs(areaList[i] - areaList[top]) < 0.001) { bottom = i; } } Face topFace = faceArray.get_Item(top); Face bottomFace = faceArray.get_Item(bottom); FamilyInstance instance = element as FamilyInstance; if (null != instance) { Transform transform = instance.GetTransform(); transform.ScaleBasis(2); } return(true); }
public static List <Face3D> ToSAM_Face3Ds(this GeometryElement geometryElement, Transform transform = null) { if (geometryElement == null) { return(null); } List <Face3D> result = new List <Face3D>(); foreach (GeometryObject geometryObject in geometryElement) { if (geometryObject is GeometryInstance) { GeometryInstance geometryInstance = (GeometryInstance)geometryObject; Transform geometryTransform = geometryInstance.Transform; if (transform != null) { geometryTransform = geometryTransform.Multiply(transform.Inverse); } GeometryElement geometryElement_Temp = geometryInstance.GetInstanceGeometry(geometryTransform); if (geometryElement_Temp == null) { continue; } List <Face3D> face3Ds = ToSAM_Face3Ds(geometryElement_Temp); if (face3Ds != null && face3Ds.Count > 0) { result.AddRange(face3Ds); } } else if (geometryObject is Solid) { Solid solid = (Solid)geometryObject; FaceArray faceArray = solid.Faces; if (faceArray == null) { continue; } foreach (Autodesk.Revit.DB.Face face in faceArray) { List <Face3D> face3Ds = face.ToSAM(); if (face3Ds != null && face3Ds.Count != 0) { result.AddRange(face3Ds); } } } } return(result); }
// =============================================================== // helper function: given a solid, find a planar // face with the given normal (version 2) // this is a slightly enhaced version of the previous // version and checks if the face is on the given reference plane. // =============================================================== PlanarFace findFace(Extrusion pBox, XYZ normal, ReferencePlane refPlane) { // get the geometry object of the given element // Options op = new Options(); op.ComputeReferences = true; GeometryElement geomElem = pBox.get_Geometry(op); // loop through the array and find a face with the given normal // foreach (GeometryObject geomObj in geomElem) { if (geomObj is Solid) // solid is what we are interested in. { Solid pSolid = geomObj as Solid; FaceArray faces = pSolid.Faces; foreach (Face pFace in faces) { PlanarFace pPlanarFace = (PlanarFace)pFace; // check to see if they have same normal if ((pPlanarFace != null) && pPlanarFace.FaceNormal.IsAlmostEqualTo(normal)) { // additionally, we want to check if the face is on the reference plane // XYZ p0 = refPlane.BubbleEnd; XYZ p1 = refPlane.FreeEnd; //Line pCurve = _app.Create.NewLineBound(p0, p1); // Revit 2013 Line pCurve = Line.CreateBound(p0, p1); // Revit 2014 if (pPlanarFace.Intersect(pCurve) == SetComparisonResult.Subset) { return(pPlanarFace); // we found the face } } } } // will come back later as needed. // //else if (geomObj is Instance) //{ //} //else if (geomObj is Curve) //{ //} //else if (geomObj is Mesh) //{ //} } // if we come here, we did not find any. return(null); }
/// <summary> /// generate data of a Solid. /// </summary> /// <param name="obj">a geometry object of element.</param> private void AddSolid(GeometryObject obj) { Solid solid = obj as Solid; // get the faces that belong to the solid. FaceArray faces = solid.Faces; foreach (Face face in faces) { AddFace(face); } }
public void GetAverageBuildingFromMasses(Document doc, int nFloors, IDFFile.BuildingConstruction constructions, IDFFile.WWR WWR, IDFFile.BuildingOperation buildingOperations, out Dictionary <string, Element> masses) { AvgBuildings = new Dictionary <string, IDFFile.Building>(); masses = new Dictionary <string, Element>(); List <View3D> views = (new FilteredElementCollector(doc).OfClass(typeof(View3D)).Cast <View3D>()).Where(v => v.Name.Contains("Op - ")).ToList(); foreach (View3D v1 in views) { //Initialize building elements FilteredElementCollector massElement = new FilteredElementCollector(doc, v1.Id).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Mass); List <IDFFile.XYZ> groundPoints = new List <IDFFile.XYZ>(); List <IDFFile.XYZ> roofPoints = new List <IDFFile.XYZ>(); double floorArea = 0; foreach (Element mass in massElement) { Options op = new Options() { ComputeReferences = true }; GeometryElement gElement = mass.get_Geometry(op); foreach (GeometryObject SolidStructure in gElement) { Solid GeoObject = SolidStructure as Solid; if (GeoObject != null) { FaceArray AllFacesFromModel = GeoObject.Faces; if (AllFacesFromModel.Size != 0) { foreach (Face face1 in AllFacesFromModel) { XYZ fNormal = (face1 as PlanarFace).FaceNormal; //checks if it is indeed a wall by computing the normal with respect to 001 if (Math.Round(fNormal.Z, 3) == -1) { groundPoints.AddRange(Utility.GetPoints(face1)); floorArea = Utility.SqFtToSqM(face1.Area); } if (Math.Round(fNormal.Z, 3) == 1) { roofPoints.AddRange(Utility.GetPoints(face1)); } } } } } masses.Add(v1.Name.Remove(0, 5), mass); } IDFFile.Building building = InitialiseModelBuilding(groundPoints, roofPoints, floorArea, nFloors, constructions, WWR, buildingOperations); AvgBuildings.Add(v1.Name.Remove(0, 5), building); } }
private PlanarFace TopFaceOriantasion(FaceArray faces) { foreach (Face face in faces) { PlanarFace planarFace = face as PlanarFace; if (planarFace.FaceNormal.IsAlmostEqualTo(XYZ.BasisZ)) { return(planarFace); } } return(null); }
/// <summary> /// get necessary data when create AreaReinforcement on a horizontal floor /// </summary> /// <param name="floor">floor on which to create AreaReinforcemen</param> /// <param name="refer">reference of the horizontal face on the floor</param> /// <param name="curves">curves compose the horizontal face of the floor</param> /// <returns>is successful</returns> public bool GetFloorGeom(Floor floor, ref Reference refer, ref IList <Curve> curves) { //get horizontal face reference FaceArray faces = GeomUtil.GetFaces(floor); foreach (Face face in faces) { if (GeomUtil.IsHorizontalFace(face)) { refer = face.Reference; break; } } //no proper reference if (null == refer) { return(false); } //check the analytical model profile is rectangular //check the analytical model profile is rectangular Document document = floor.Document; AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); AnalyticalPanel model = null; if (assocManager != null) { ElementId associatedElementId = assocManager.GetAssociatedElementId(floor.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalPanel) { model = associatedElement as AnalyticalPanel; } } } if (null == model) { return(false); } curves = model.GetOuterContour().ToList(); if (!GeomUtil.IsRectangular(curves)) { return(false); } return(true); }
public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args) { Solid thisSolid = (Solid)((FScheme.Value.Container)args[0]).Item; Line selectLine = (Line)((FScheme.Value.Container)args[1]).Item; FaceArray faceArr = thisSolid.Faces; var thisEnum = faceArr.GetEnumerator(); SortedList <double, Autodesk.Revit.DB.Face> intersectingFaces = new SortedList <double, Autodesk.Revit.DB.Face>(); for (; thisEnum.MoveNext();) { Autodesk.Revit.DB.Face thisFace = (Autodesk.Revit.DB.Face)thisEnum.Current; IntersectionResultArray resultArray = null; SetComparisonResult resultIntersect = thisFace.Intersect(selectLine, out resultArray); if (resultIntersect != SetComparisonResult.Overlap) { continue; } bool first = true; double linePar = -1.0; foreach (IntersectionResult ir in resultArray) { double irPar = ir.Parameter; if (first == true) { linePar = irPar; first = false; } else if (irPar < linePar) { linePar = irPar; } } intersectingFaces.Add(linePar, thisFace); } var result = FSharpList <FScheme.Value> .Empty; var intersectingFacesEnum = intersectingFaces.Reverse().GetEnumerator(); for (; intersectingFacesEnum.MoveNext();) { Autodesk.Revit.DB.Face faceObj = intersectingFacesEnum.Current.Value; result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(faceObj), result); } return(FScheme.Value.NewList(result)); }
/// <summary> /// Paint solid by AVF /// </summary> /// <param name="solid">Solid to be painted</param> /// <param name="view">The view that shows solid</param> private void PaintSolid(Solid solid, View view) { String viewName = view.Name; SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view); if (sfm == null) { sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1); } if (m_schemaId != -1) { IList <int> results = sfm.GetRegisteredResults(); if (!results.Contains(m_schemaId)) { m_schemaId = -1; } } // set up the display style if (m_schemaId == -1) { AnalysisResultSchema resultSchema1 = new AnalysisResultSchema("PaintedSolid " + viewName, "Description"); AnalysisDisplayStyle displayStyle = AnalysisDisplayStyle.CreateAnalysisDisplayStyle(this.RevitDoc, "Real_Color_Surface" + viewName, new AnalysisDisplayColoredSurfaceSettings(), new AnalysisDisplayColorSettings(), new AnalysisDisplayLegendSettings()); resultSchema1.AnalysisDisplayStyleId = displayStyle.Id; m_schemaId = sfm.RegisterResult(resultSchema1); } // get points of all faces in the solid FaceArray faces = solid.Faces; Transform trf = Transform.Identity; foreach (Face face in faces) { int idx = sfm.AddSpatialFieldPrimitive(face, trf); IList <UV> uvPts = null; IList <ValueAtPoint> valList = null; ComputeValueAtPointForFace(face, out uvPts, out valList, 1); FieldDomainPointsByUV pnts = new FieldDomainPointsByUV(uvPts); FieldValues vals = new FieldValues(valList); sfm.UpdateSpatialFieldPrimitive(idx, pnts, vals, m_schemaId); } }
/***************************************************/ public static List <oM.Geometry.ISurface> FromRevit(this FaceArray faceArray) { if (faceArray == null) { return(null); } List <oM.Geometry.ISurface> result = new List <oM.Geometry.ISurface>(); foreach (Face face in faceArray) { result.Add(face.IFromRevit()); } return(result); }
private static FaceArray GetFaces(Element element) { var faceArray = new FaceArray(); var options = new Options(); options.ComputeReferences = true; var geomElem = element.get_Geometry(options); if (geomElem != null) { foreach (GeometryObject geomObj in geomElem.Objects) { var solid = geomObj as Solid; if (solid != null) { foreach (Face f in solid.Faces) { faceArray.Append(f); } } var inst = geomObj as GeometryInstance; if (inst != null) // in-place family walls { foreach (Object o in inst.SymbolGeometry.Objects) { var s = o as Solid; if (s != null) { foreach (Face f in s.Faces) { faceArray.Append(f); } } } } } } return faceArray; }
/// <summary> /// Find the bottom face of a face array. /// </summary> /// <param name="faces">A face array.</param> /// <returns>The bottom face of a face array.</returns> public static Face GetBottomFace(FaceArray faces) { Face face = null; double elevation = 0; double tempElevation = 0; Mesh mesh = null; foreach (Face f in faces) { if (IsVerticalFace(f)) { // If this is a vertical face, it cannot be a bottom face to a certainty. continue; } tempElevation = 0; mesh = f.Triangulate(); foreach (Autodesk.Revit.DB.XYZ xyz in mesh.Vertices) { tempElevation = tempElevation + xyz.Z; } tempElevation = tempElevation / mesh.Vertices.Count; if (elevation > tempElevation || null == face) { // Update the bottom face to which's elevation is the lowest. face = f; elevation = tempElevation; } } // The bottom face is consider as which's average elevation is the lowest, except vertical // face. return face; }
protected IEnumerable<Autodesk.Revit.DB.Face> GetFaces(Autodesk.Revit.DB.Options options) { var geomElem = this.InternalElement.get_Geometry(options); var faces = new FaceArray(); GetFaces(geomElem, ref faces); return faces.Cast<Autodesk.Revit.DB.Face>(); }
/// <summary> /// create a new curtain system /// </summary> /// <param name="faceIndices"> /// the faces to be covered with new curtain system /// </param> /// <param name="byFaceArray"> /// indicates whether the curtain system will be created by face array /// </param> public void CreateCurtainSystem(List<int> faceIndices, bool byFaceArray) { // just refresh the main UI if (null == faceIndices || 0 == faceIndices.Count) { if (null != CurtainSystemChanged) { CurtainSystemChanged(); } return; } SystemInfo resultInfo = new SystemInfo(m_mydocument); resultInfo.ByFaceArray = byFaceArray; resultInfo.GridFacesIndices = faceIndices; resultInfo.Index = ++m_csIndex; // // step 1: create the curtain system // // create the curtain system by face array if (true == byFaceArray) { FaceArray faceArray = new FaceArray(); foreach (int index in faceIndices) { faceArray.Append(m_mydocument.MassFaceArray.get_Item(index)); } Autodesk.Revit.DB.CurtainSystem curtainSystem = null; Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString()); t.Start(); try { curtainSystem = m_mydocument.Document.Create.NewCurtainSystem(faceArray, m_mydocument.CurtainSystemType); } catch (System.Exception) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed; t.RollBack(); return; } t.Commit(); resultInfo.CurtainForm = curtainSystem; } // create the curtain system by reference array else { ReferenceArray refArray = new ReferenceArray(); foreach (int index in faceIndices) { refArray.Append(m_mydocument.MassFaceArray.get_Item(index).Reference); } ElementSet curtainSystems = null; Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString()); t.Start(); try { curtainSystems = m_mydocument.Document.Create.NewCurtainSystem(refArray, m_mydocument.CurtainSystemType); } catch (System.Exception) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed; t.RollBack(); return; } t.Commit(); // internal fatal error, quit the sample if (null == curtainSystems || 1 != curtainSystems.Size) { m_mydocument.FatalErrorMsg = Properties.Resources.MSG_MoreThan1CSCreated; return; } // store the curtain system foreach (Autodesk.Revit.DB.CurtainSystem cs in curtainSystems) { resultInfo.CurtainForm = cs; break; } } // // step 2: update the curtain system list in the main UI // m_curtainSystemInfos.Add(resultInfo); if (null != CurtainSystemChanged) { CurtainSystemChanged(); } }
/// <summary> /// check whether the faces of the mass are one-one parallel /// </summary> /// <param name="faces"> /// the 6 faces of the mass /// </param> /// <returns> /// if the 6 faces are one-one parallel, return true; otherwise false /// </returns> private bool IsFacesParallel(FaceArray faces) { // step1: get the normals of the 6 faces List<Utility.Vector4> normals = new List<Utility.Vector4>(); foreach (Face face in faces) { EdgeArrayArray edgeArrayArray = face.EdgeLoops; EdgeArray edges = edgeArrayArray.get_Item(0); if (null == edges || 2 > edges.Size) { return false; } // we use the cross product of 2 non-parallel vectors as the normal for (int i = 0; i < edges.Size - 1; i++) { Edge edgeA = edges.get_Item(i); Edge edgeB = edges.get_Item(i + 1); // if edgeA & edgeB are parallel, can't compute the cross product bool isLinesParallel = IsLinesParallel(edgeA, edgeB); if (true == isLinesParallel) { continue; } Utility.Vector4 vec4 = ComputeCrossProduct(edgeA, edgeB); normals.Add(vec4); break; } } // step 2: the 6 normals should be one-one parallel pairs if (null == normals || 6 != normals.Count) { return false; } bool[] matchedList = new bool[6]; for (int i = 0; i < matchedList.Length; i++) { matchedList[i] = false; } // check whether the normal has another matched parallel normal for (int i = 0; i < matchedList.Length; i++) { if (true == matchedList[i]) { continue; } Utility.Vector4 vec4A = normals[i]; for (int j = 0; j < matchedList.Length; j++) { if (j == i || true == matchedList[j]) { continue; } Utility.Vector4 vec4B = normals[j]; if (true == IsLinesParallel(vec4A, vec4B)) { matchedList[i] = true; matchedList[j] = true; break; } } } // step 3: check each of the 6 normals has matched parallel normal for (int i = 0; i < matchedList.Length; i++) { if (false == matchedList[i]) { return false; } } // all the normals have matched parallel normals return true; }
private FaceArray GetFaces(ICollection<Element> elements) { FaceArray faceArray = new FaceArray(); Options options = new Options(); options.ComputeReferences = true; foreach (Element element in elements) { GeometryElement geomElem = element.get_Geometry(options); if (geomElem != null) { foreach (GeometryObject geomObj in geomElem.Objects) { Solid solid = geomObj as Solid; if (solid != null) { foreach (Face f in solid.Faces) { faceArray.Append(f); } } GeometryInstance inst = geomObj as GeometryInstance; if (inst != null) // in-place family walls { foreach (Object o in inst.SymbolGeometry.Objects) { Solid s = o as Solid; if (s != null) { foreach (Face f in s.Faces) { faceArray.Append(f); } } } } } } } return faceArray; }
/// <summary> /// The assistant method is used for getting wall face and getting extrusion face /// </summary> /// <param name="faces">faces array</param> /// <returns>the face</returns> private static Face GetInteriorFace(FaceArray faces) { double elevation = 0; double tempElevation = 0; Mesh mesh = null; Face face = null; foreach (Face f in faces) { tempElevation = 0; mesh = f.Triangulate(); foreach (Autodesk.Revit.DB.XYZ xyz in mesh.Vertices) { tempElevation = tempElevation + xyz.Y; } tempElevation = tempElevation / mesh.Vertices.Count; if (elevation > tempElevation || null == face) { face = f; elevation = tempElevation; } } return face; }
/// <summary> /// Recursively traverse the GeometryElement obtained from this Element, collecting the Curves /// </summary> /// <param name="geomElement"></param> /// <param name="faces"></param> private static void GetFaces(IEnumerable<Autodesk.Revit.DB.GeometryObject> geomElement, ref FaceArray faces) { foreach (Autodesk.Revit.DB.GeometryObject geob in geomElement) { if (geob is GeometryInstance) { GetFaces((geob as GeometryInstance).GetInstanceGeometry(), ref faces); } else if (geob is Autodesk.Revit.DB.Solid) { var mySolid = geob as Autodesk.Revit.DB.Solid; if (mySolid != null) { foreach (var f in mySolid.Faces.Cast<Autodesk.Revit.DB.Face>().ToList()) { faces.Append(f); } } } else if (geob is Autodesk.Revit.DB.GeometryElement) { GetFaces(geob as GeometryElement, ref faces); } } }