public static Plane GetPlaneWithBasisY(PlanarFace f, XYZ vecY) { if (!GeomUtil.IsEqual(GeomUtil.DotMatrix(vecY, f.FaceNormal), 0)) { throw new Exception("VecY is not perpendicular with Normal!"); } return(Plane.CreateByOriginAndBasis(f.Origin, GeomUtil.UnitVector(GeomUtil.CrossMatrix(vecY, f.FaceNormal)), vecY)); }
public static RebarHookOrientation GetHookOrient(Autodesk.Revit.DB.XYZ curveVec, Autodesk.Revit.DB.XYZ normal, Autodesk.Revit.DB.XYZ hookVec) { Autodesk.Revit.DB.XYZ tempVec = normal; for (int i = 0; i < 4; i++) { tempVec = GeomUtil.CrossMatrix(tempVec, curveVec); if (GeomUtil.IsSameDirection(tempVec, hookVec)) { if (i == 0) { return(RebarHookOrientation.Right); } else if (i == 2) { return(RebarHookOrientation.Left); } } } throw new Exception("Can't find the hook orient according to hook direction."); }
public static XYZ GetProjectPoint(Curve line, XYZ point) { if (IsPointInLineOrExtend(CheckGeometry.ConvertLine(line), point)) { return(point); } XYZ vecL = GeomUtil.SubXYZ(line.GetEndPoint(1), line.GetEndPoint(0)); XYZ vecP = GeomUtil.SubXYZ(point, line.GetEndPoint(0)); Plane p = Plane.CreateByOriginAndBasis(line.GetEndPoint(0), GeomUtil.UnitVector(vecL), GeomUtil.UnitVector(GeomUtil.CrossMatrix(vecL, vecP))); return(GetProjectPoint(p, point)); }
public static ViewSection CreateWallSection(Document linkedDoc, Document doc, Polygon directPolygon, ElementId id, string viewName, double offset) { Element e = linkedDoc.GetElement(id); if (!(e is Wall)) { throw new Exception("Element is not a wall!"); } Wall wall = (Wall)e; Line line = (wall.Location as LocationCurve).Curve as Line; ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); XYZ p1 = line.GetEndPoint(0), p2 = line.GetEndPoint(1); List <XYZ> ps = new List <XYZ> { p1, p2 }; ps.Sort(new ZYXComparer()); p1 = ps[0]; p2 = ps[1]; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z, maxZ = bb.Max.Z; double l = GeomUtil.GetLength(GeomUtil.SubXYZ(p2, p1)); double h = maxZ - minZ; double w = wall.WallType.Width; XYZ tfMin = new XYZ(-l / 2 - offset, minZ - offset, -w - offset); XYZ tfMax = new XYZ(l / 2 + offset, maxZ + offset, w + offset); XYZ wallDir = GeomUtil.UnitVector(p2 - p1); XYZ upDir = XYZ.BasisZ; XYZ viewDir = GeomUtil.CrossMatrix(wallDir, upDir); XYZ midPoint = (p1 + p2) / 2; XYZ pMidPoint = GetProjectPoint(directPolygon.Plane, midPoint); XYZ pPnt = GeomUtil.OffsetPoint(pMidPoint, viewDir, w * 10); if (GeomUtil.IsBigger(GeomUtil.GetLength(pMidPoint, directPolygon.CentralXYZPoint), GeomUtil.GetLength(pPnt, directPolygon.CentralXYZPoint))) { wallDir = -wallDir; upDir = XYZ.BasisZ; viewDir = GeomUtil.CrossMatrix(wallDir, upDir); } else { } pPnt = GeomUtil.OffsetPoint(p1, wallDir, offset); XYZ min = null, max = null; if (GeomUtil.IsBigger(GeomUtil.GetLength(GeomUtil.SubXYZ(pPnt, midPoint)), GeomUtil.GetLength(GeomUtil.SubXYZ(p1, midPoint)))) { min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, wallDir, offset), -viewDir, offset); max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, -wallDir, offset), viewDir, offset); } else { min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, -wallDir, offset), -viewDir, offset); max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, wallDir, offset), viewDir, offset); } min = new XYZ(min.X, min.Y, minZ - offset); max = new XYZ(max.X, max.Y, maxZ + offset); Transform tf = Transform.Identity; tf.Origin = (p1 + p2) / 2; tf.BasisX = wallDir; tf.BasisY = XYZ.BasisZ; tf.BasisZ = GeomUtil.CrossMatrix(wallDir, upDir); BoundingBoxXYZ sectionBox = new BoundingBoxXYZ() { Transform = tf, Min = tfMin, Max = tfMax }; ViewSection vs = ViewSection.CreateSection(doc, vft.Id, sectionBox); tf = vs.get_BoundingBox(null).Transform.Inverse; max = tf.OfPoint(max); min = tf.OfPoint(min); double maxx = 0, maxy = 0, maxz = 0, minx = 0, miny = 0, minz = 0; if (max.Z > min.Z) { maxz = max.Z; minz = min.Z; } else { maxz = min.Z; minz = max.Z; } if (Math.Round(max.X, 4) == Math.Round(min.X, 4)) { maxx = max.X; minx = minz; } else if (max.X > min.X) { maxx = max.X; minx = min.X; } else { maxx = min.X; minx = max.X; } if (Math.Round(max.Y, 4) == Math.Round(min.Y, 4)) { maxy = max.Y; miny = minz; } else if (max.Y > min.Y) { maxy = max.Y; miny = min.Y; } else { maxy = min.Y; miny = max.Y; } BoundingBoxXYZ sectionView = new BoundingBoxXYZ(); sectionView.Max = new XYZ(maxx, maxy, maxz); sectionView.Min = new XYZ(minx, miny, minz); vs.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(ElementId.InvalidElementId); vs.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING).Set(0); vs.CropBoxActive = true; vs.CropBoxVisible = true; doc.Regenerate(); vs.CropBox = sectionView; vs.Name = viewName; return(vs); }