/// <summary> // Add a door to the center of the given wall. // cf. Developer Guide p137. NewFamilyInstance() for Doors and Window. /// </summary> public void AddDoor(Wall hostWall) { // Hard coding the door type we will use. // E.g., "M_Single-Flush: 0915 x 2134mm const string doorFamilyName = Util.Constant.DoorFamilyName; const string doorTypeName = Util.Constant.DoorTypeName; const string doorFamilyAndTypeName = doorFamilyName + ": " + doorTypeName; // Get the door type to use. FamilySymbol doorType = (FamilySymbol)ElementFiltering.FindFamilyType(_doc, typeof(FamilySymbol), doorFamilyName, doorTypeName, BuiltInCategory.OST_Doors); if (doorType == null) { TaskDialog.Show( "Add door", "Cannot find (" + doorFamilyAndTypeName + "). Maybe you use a different template? Try with DefaultMetric.rte."); } if (!doorType.IsActive) { doorType.Activate(); } // Get the start and end points of the wall. LocationCurve locCurve = (LocationCurve)hostWall.Location; XYZ pt1 = locCurve.Curve.GetEndPoint(0); XYZ pt2 = locCurve.Curve.GetEndPoint(1); // Calculate the mid point. XYZ pt = (pt1 + pt2) / 2.0; // we want to set the reference as a bottom of the wall or level1. ElementId idLevel1 = hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); //Level level1 = (Level)_doc.get_Element(idLevel1); // 2012 Level level1 = (Level)_doc.GetElement(idLevel1); // since 2013 // Finally, create a door. FamilyInstance aDoor = _doc.Create.NewFamilyInstance( pt, doorType, hostWall, level1, StructuralType.NonStructural); }
/// <summary> /// Add a window to the center of the wall given. /// cf. Developer Guide p137. NewFamilyInstance() for Doors and Window. /// Basically the same idea as a door except that we need to set sill hight. /// </summary> public void AddWindow(Wall hostWall) { // Hard coding the window type we will use. // E.g., "M_Fixed: 0915 x 1830mm const string windowFamilyName = Util.Constant.WindowFamilyName; const string windowTypeName = Util.Constant.WindowTypeName; const string windowFamilyAndTypeName = windowFamilyName + ": " + windowTypeName; double sillHeight = Constant.MmToFeet(915); // Get the door type to use. FamilySymbol windowType = (FamilySymbol)ElementFiltering.FindFamilyType(_doc, typeof(FamilySymbol), windowFamilyName, windowTypeName, BuiltInCategory.OST_Windows); if (windowType == null) { TaskDialog.Show( "Add window", "Cannot find (" + windowFamilyAndTypeName + "). Maybe you use a different template? Try with DefaultMetric.rte."); } if (!windowType.IsActive) { windowType.Activate(); } // Get the start and end points of the wall. LocationCurve locCurve = (LocationCurve)hostWall.Location; XYZ pt1 = locCurve.Curve.GetEndPoint(0); XYZ pt2 = locCurve.Curve.GetEndPoint(1); // Calculate the mid point. XYZ pt = (pt1 + pt2) / 2.0; // we want to set the reference as a bottom of the wall or level1. ElementId idLevel1 = hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); //Level level1 = (Level)_doc.get_Element(idLevel1); // 2012 Level level1 = (Level)_doc.GetElement(idLevel1); // since 2013 // Finally create a window. FamilyInstance aWindow = _doc.Create.NewFamilyInstance(pt, windowType, hostWall, level1, StructuralType.NonStructural); aWindow.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).Set(sillHeight); }
private static void SetCurveFromLine(CSAModel model, LocationCurve locationCurve) { XYZ parallelVector = null; XYZ verticalVector = null; parallelVector = (locationCurve.Curve as Line).Direction; verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0); parallelVector = VLLocationHelper.GetVectorByQuadrant(parallelVector, QuadrantType.OneAndFour); verticalVector = VLLocationHelper.GetVectorByQuadrant(verticalVector, QuadrantType.OneAndTwo); if ((verticalVector.X - 1).IsMiniValue()) { verticalVector = verticalVector.RevertByCoordinateType(VLCoordinateType.XY); } model.VerticalVector = verticalVector; model.ParallelVector = parallelVector; }
// Метод соеденяет трубы прямым фиттингом (UnionFitting) private void CreateFitting(Document doc, List <Pipe> pipes) { for (int i = 0; i < pipes.Count - 1; i++) { LocationCurve locCurve = pipes[i].Location as LocationCurve; XYZ connectPoint = locCurve.Curve.GetEndPoint(1); Connector connector1 = Util.GetConnectorClosestTo(pipes[i], connectPoint); Connector connector2 = Util.GetConnectorClosestTo(pipes[i + 1], connectPoint); using (Transaction t = new Transaction(doc, "ConnectToConnect")) { t.Start(); doc.Create.NewUnionFitting(connector1, connector2); t.Commit(); } } }
/// <summary> /// return section box for a view parallel to given wall /// </summary> /// <param name="wall"></param> /// <returns></returns> BoundingBoxXYZ getSectionVewParallelToWall(Wall wall) { LocationCurve lc = wall.Location as LocationCurve; Curve curve = lc.Curve; //view direction sectionBox.Transform.BasisZ //up direction sectionBox.Transform.BasisY //right hand is computed so that (right,up viewdirection) form a left handed coordinate system //crop region projections of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max onto the view cut plane //far clip distance difference of the z-coordinates of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max XYZ p = curve.GetEndPoint(0); XYZ q = curve.GetEndPoint(1); XYZ v = q - p; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double w = v.GetLength(); double h = maxZ - minZ; double d = wall.WallType.Width; double offset = 0.1 * w; XYZ min = new XYZ(-w, minZ - offset, -offset); XYZ max = new XYZ(w, maxZ + offset, offset); XYZ midpoint = p + 0.5 * v; XYZ walldir = v.Normalize(); XYZ up = XYZ.BasisZ; XYZ viewDir = walldir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpoint; t.BasisX = walldir; t.BasisY = up; t.BasisZ = viewDir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; return(sectionBox); }
public override Value Evaluate(FSharpList <Value> args) { var instance = (FamilyInstance)((Value.Container)args[0]).Item; // ADAPTIVE COMPONENT if (AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(instance)) { var refPtIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); FSharpList <Value> refPts = FSharpList <Value> .Empty; foreach (var id in refPtIds) { var pt = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; refPts = FSharpList <Value> .Cons(Value.NewContainer(pt.Position), refPts); } return(Value.NewList(Utils.SequenceToFSharpList(refPts.Reverse()))); } // INSTANCE WITH PLACEMENT POINT var ptRefs = instance.GetFamilyPointPlacementReferences(); if (ptRefs.Any()) { var pts = ptRefs.Select(x => x.Location.Origin); var containers = pts.Select(Value.NewContainer); return(Value.NewList(Utils.SequenceToFSharpList(containers))); } LocationPoint point = null; LocationCurve c = null; // INSTANCE WITH LOCATION POINT point = instance.Location as LocationPoint; if (point != null) { return(Value.NewContainer(point.Point)); } //INSTANCE WITH LOCATION CURVE c = instance.Location as LocationCurve; if (c != null) { return(Value.NewContainer(c.Curve)); } throw new Exception("A location could not be found for the selected family instance(s)."); }
/// <summary> /// Return all wall profile boundary loop polygons /// for the given walls, offset out from the outer /// face of the wall by a certain amount. /// </summary> static public List <List <XYZ> > GetWallProfilePolygons( //Application app, List <Element> walls, Options opt) { XYZ p, q, v, w; //Options opt = app.Create.NewGeometryOptions(); List <List <XYZ> > polygons = new List <List <XYZ> >(); foreach (Wall wall in walls) { string desc = Util.ElementDescription(wall); LocationCurve curve = wall.Location as LocationCurve; if (null == curve) { throw new Exception(desc + ": No wall curve found."); } p = curve.Curve.GetEndPoint(0); q = curve.Curve.GetEndPoint(1); v = q - p; v = v.Normalize(); w = XYZ.BasisZ.CrossProduct(v).Normalize(); if (wall.Flipped) { w = -w; } GeometryElement geo = wall.get_Geometry(opt); //GeometryObjectArray objects = geo.Objects; // 2012 //foreach( GeometryObject obj in objects ) // 2012 foreach (GeometryObject obj in geo) // 2013 { Solid solid = obj as Solid; if (solid != null) { GetProfile(polygons, solid, v, w); } } } return(polygons); }
/// <summary> /// Utility to get the "center" of the element based on location parameters, projected to Z=0. /// </summary> /// <param name="e">The element.</param> /// <returns>The center location.</returns> private static XYZ GetNominalCenterLocation(Element e) { LocationPoint lp = e.Location as LocationPoint; if (lp != null) { return(MoveToElevationZero(lp.Point)); } LocationCurve lc = e.Location as LocationCurve; if (lc != null) { return(MoveToElevationZero(lc.Curve.Evaluate(0.5, true))); } return(XYZ.Zero); }
/// <summary> /// Добавление окна. /// </summary> /// <param name="hostWall"></param> public void AddWindow(Wall hostWall) { // hard coding the window type we will use. // e.g., "M_Fixed: 0915 x 1830mm const string windowFamilyName = "Фиксированные"; // "M_Fixed" const string windowTypeName = "0915 x 1830 мм"; // "0915 x 1830mm" const string windowFamilyAndTypeName = windowFamilyName + ": " + windowTypeName; double sillHeight = ElementModification.mmToFeet(915); // get the door type to use. FamilySymbol windowType = (FamilySymbol)ElementFiltering.FindFamilyType( m_rvtDoc, typeof(FamilySymbol), windowFamilyName, windowTypeName, BuiltInCategory.OST_Windows); if (windowType == null) { TaskDialog.Show("Revit Intro Lab", "Cannot find (" + windowFamilyAndTypeName + "). Try with DefaultMetric.rte."); } // get the start and end points of the wall. LocationCurve locCurve = (LocationCurve)hostWall.Location; XYZ pt1 = locCurve.Curve.GetEndPoint(0); XYZ pt2 = locCurve.Curve.GetEndPoint(1); // calculate the mid point. XYZ pt = (pt1 + pt2) / 2.0; // we want to set the reference as a bottom of the wall or level1. ElementId idLevel1 = hostWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId(); Level level1 = (Level)m_rvtDoc.GetElement(idLevel1); // finally create a window. FamilyInstance aWindow = m_rvtDoc.Create.NewFamilyInstance(pt, windowType, hostWall, level1, StructuralType.NonStructural); // set the sill height aWindow.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).Set(sillHeight); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Get application and documnet objects UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; View view = doc.ActiveView; //TextNoteOptions options = new TextNoteOptions(); ElementId typeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); Collector co = new Collector(); //int i = 1; int i = co.GetMaxValue(doc); IList <Reference> pickedObjs = uidoc.Selection.PickObjects(ObjectType.Element, "Select Multiple Elements"); List <ElementId> ids = (from Reference r in pickedObjs select r.ElementId).ToList(); using (Transaction tx = new Transaction(doc)) { tx.Start("transaction"); if (pickedObjs != null && pickedObjs.Count > 0) { foreach (ElementId eid in ids) { Element e = doc.GetElement(eid); //string strng = "random"; //FamilyInstance faminst = e as FamilyInstance; LocationPoint locPoint = e.Location as LocationPoint; if (null != locPoint) { XYZ point_a = locPoint.Point; TextNote note = TextNote.Create(doc, view.Id, point_a, i.ToString(), typeId); } else { LocationCurve locCurve = e.Location as LocationCurve; XYZ point_a = locCurve.Curve.Evaluate(0.5, true); TextNote note = TextNote.Create(doc, view.Id, point_a, i.ToString(), typeId); } i += 1; } } tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// Checks a single curved/profiled wall for embedded columns. /// </summary> /// <param name="wall">The wall to check.</param> /// <param name="locationCurve">The location curve extracted from this wall.</param> /// <param name="wallCurve">The profile of the wall.</param> private void CheckProfiledWallForEmbeddedColumns(Wall wall, LocationCurve locationCurve, Curve wallCurve) { double bottomHeight = GetElevationForRay(wall); // Figure out the increment for the normalized parameter based on how long the wall is. double parameterIncrement = WallIncrement / wallCurve.Length; // Find columns within 2' of the start of the ray. Any smaller, and you run the risk of not finding a boundary // face of the column within the target range. double findColumnWithin = 2; // check for columns along every WallIncrement fraction of the wall for (double parameter = 0; parameter < 1.0; parameter += parameterIncrement) { FindColumnsOnEitherSideOfWall(wall, locationCurve, wallCurve, parameter, bottomHeight, findColumnWithin); } }
public static Transform getLocalCoordinatesPoint(Element element, UIDocument uidoc) { Transform transform = null; if (element is Wall) { Wall wall = element as Wall; LocationCurve lc = wall.Location as LocationCurve; Line line = lc.Curve as Line; IList <Reference> sideFaces = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior); Face face = uidoc.Document.GetElement(sideFaces[0]).GetGeometryObjectFromReference(sideFaces[0]) as Face; Reference reference = face.Reference; UV uv = new UV(0, 0); XYZ wallfacedir = face.ComputeNormal(uv) as XYZ; XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = q - p; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double w = v.GetLength(); double h = maxZ - minZ; XYZ midpoint = p + 0.5 * v; XYZ up = XYZ.BasisZ; XYZ walldir = wallfacedir.CrossProduct(up); transform = Transform.Identity; transform.Origin = new XYZ(midpoint.X, midpoint.Y, 0); transform.BasisX = walldir.Normalize(); transform.BasisY = up; transform.BasisZ = wallfacedir * -1; } return(transform); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; View acview = uidoc.ActiveView; UIView acuiview = uidoc.ActiveUiview(); Transaction ts = new Transaction(doc, "******"); try { ts.Start(); //获取一堵墙,并创建一条和墙位置垂直的旋转轴,然后对这堵墙进行逆时针60°的旋转 //点选指定执行的元素, 本次按只能选择柱考虑 Reference pickedEleReference = sel.PickObject(ObjectType.Element, "选择个墙吧"); //通过引用取到选中的元素 Wall wall = doc.GetElement(pickedEleReference) as Wall; LocationCurve wallLine = wall.Location as LocationCurve; XYZ point1 = wallLine.Curve.GetEndPoint(0); XYZ point2 = new XYZ(point1.X, point1.Y, 30); Line axis = Line.CreateBound(point1, point2); ElementTransformUtils.RotateElement(doc, wall.Id, axis, Math.PI / (180 / 60)); ts.Commit(); } catch (Exception) { if (ts.GetStatus() == TransactionStatus.Started) { ts.RollBack(); } } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection selection = uidoc.Selection; while (true) { try { using (Transaction ts = new Transaction(doc)) { ts.Start("打断"); Reference refElement = selection.PickObject(ObjectType.PointOnElement, "请选择需要打断的点"); XYZ point = refElement.GlobalPoint; Element elem = doc.GetElement(refElement); LocationCurve lc = elem.Location as LocationCurve; XYZ newPoint = lc.Curve.Project(point).XYZPoint; if (lc == null) { TaskDialog.Show("Error", "您选择的构建不可以分割,请重新选择"); continue; } XYZ startPoint = lc.Curve.GetEndPoint(0); XYZ endPoint = lc.Curve.GetEndPoint(1); Line l1 = Line.CreateBound(startPoint, newPoint); Line l2 = Line.CreateBound(newPoint, endPoint); Element el1 = doc.GetElement(ElementTransformUtils.CopyElement(doc, elem.Id, new XYZ(1, 0, 0)).First()); Element el2 = doc.GetElement(ElementTransformUtils.CopyElement(doc, elem.Id, new XYZ(1, 0, 0)).First()); (el1.Location as LocationCurve).Curve = l1; (el2.Location as LocationCurve).Curve = l2; doc.Delete(elem.Id); ts.Commit(); } } catch { break; } } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; FamilyInstance beam = Util.SelectSingleElementOfType( uidoc, typeof(FamilyInstance), "a beam", false) as FamilyInstance; BuiltInCategory bic = BuiltInCategory.OST_StructuralFraming; if (null == beam || null == beam.Category || !beam.Category.Id.IntegerValue.Equals((int)bic)) { message = "Please select a single beam element."; } else { LocationCurve curve = beam.Location as LocationCurve; if (null == curve) { message = "No curve available"; return(Result.Failed); } XYZ p = curve.Curve.GetEndPoint(0); XYZ q = curve.Curve.GetEndPoint(1); XYZ v = 0.1 * (q - p); p = p - v; q = q + v; //Creator creator = new Creator( doc ); //creator.CreateModelLine( p, q ); Creator.CreateModelLine(doc, p, q); } return(Result.Succeeded); }
double GetMinPointCurve(LocationCurve _lc) { double Zpt1 = _lc.Curve.GetEndPoint(0).Z; double mpt1 = PoundsToM(Zpt1); double Zpt2 = _lc.Curve.GetEndPoint(1).Z; double mpt2 = PoundsToM(Zpt2); //Применить тернарный оператор if (Zpt2 > Zpt1) { return(Zpt1); } else { return(Zpt2); } }
//HACK deltaFromGround is not used public Element InsertDoor(Length deltaFromStart, Length deltaFromGround, Element host, ElementId familyId) { LocationCurve locCurve = host.Location as LocationCurve; XYZ start = locCurve.Curve.GetEndPoint(0); XYZ dir = locCurve.Curve.GetEndPoint(1) - start; XYZ location = start + dir.Normalize() * deltaFromStart; FamilySymbol symbol = (familyId == null) ? GetFirstSymbol(FindCategoryFamilies(doc, BuiltInCategory.OST_Doors).FirstOrDefault()) : doc.GetElement(familyId) as FamilySymbol; if (!symbol.IsActive) { symbol.Activate(); doc.Regenerate(); } return(doc.Create.NewFamilyInstance(location, symbol, host, host.Document.GetElement(host.LevelId) as Level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural)); }
/// <summary> /// Finds the normal to the wall centerline at the given parameter. /// </summary> /// <param name="wall">The wall.</param> /// <param name="curve">The location curve of the wall.</param> /// <param name="parameter">The normalized parameter.</param> /// <returns>The normalized normal vector.</returns> private XYZ GetNormalToWallAt(Wall wall, LocationCurve curve, double parameter) { Curve wallCurve = curve.Curve; // There is no normal at a given point for a line. We need to get the normal based on the tangent of the wall location curve. if (wallCurve is Line) { XYZ wallDirection = GetTangentAt(wallCurve, 0); XYZ wallNormal = new XYZ(wallDirection.Y, wallDirection.X, 0); return(wallNormal); } else { Transform t = wallCurve.ComputeDerivatives(parameter, true); // For non-linear curves, BasisY is the normal vector to the curve. return(t.BasisY.Normalize()); } }
/// <summary> /// Get points of first face /// </summary> /// <param name="faces">edges in all faces</param> /// <returns>points of first face</returns> public override List <List <XYZ> > GetNeedPoints(List <List <Edge> > faces) { List <Edge> needFace = new List <Edge>(); List <List <XYZ> > needPoints = new List <List <XYZ> >(); LocationCurve location = m_data.Location as LocationCurve; Curve curve = location.Curve; List <XYZ> xyzs = curve.Tessellate() as List <XYZ>; Vector4 zAxis = new Vector4(0, 0, 1); //if Location curve of wall is line, then return first face if (xyzs.Count == 2) { needFace = faces[0]; } //else we return the face whose normal is Z axis foreach (List <Edge> face in faces) { foreach (Edge edge in face) { List <XYZ> edgexyzs = edge.Tessellate() as List <XYZ>; if (xyzs.Count == edgexyzs.Count) { //get the normal of face Vector4 normal = GetFaceNormal(face); Vector4 cross = Vector4.CrossProduct(zAxis, normal); cross.Normalize(); if (cross.Length() == 1) { needFace = face; } } } } needFace = faces[0]; //get points array in edges foreach (Edge edge in needFace) { List <XYZ> edgexyzs = edge.Tessellate() as List <XYZ>; needPoints.Add(edgexyzs); } return(needPoints); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; FilteredElementCollector walls = new FilteredElementCollector(doc); walls.OfClass(typeof(Wall)); foreach (Wall wall in walls) { Parameter param = wall.get_Parameter( BuiltInParameter.HOST_AREA_COMPUTED); double a = ((null != param) && (StorageType.Double == param.StorageType)) ? param.AsDouble() : 0.0; string s = (null != param) ? param.AsValueString() : "null"; LocationCurve lc = wall.Location as LocationCurve; XYZ p = lc.Curve.GetEndPoint(0); XYZ q = lc.Curve.GetEndPoint(1); double l = q.DistanceTo(p); string format = "Wall <{0} {1}> length {2} area {3} ({4})"; Debug.Print(format, wall.Id.IntegerValue.ToString(), wall.Name, Util.RealString(l), Util.RealString(a), s); } return(Result.Succeeded); }
public static void BeamGenerator(Document doc, ElementId eId, out Beam beam) { beam = new Beam(); Element e = doc.GetElement(eId); FamilyInstance fi = e as FamilyInstance; LocationCurve locCurve = fi.Location as LocationCurve; beam.id = eId; beam.name = e.Name; beam.end0 = (locCurve.Curve as Line).GetEndPoint(0); beam.end1 = (locCurve.Curve as Line).GetEndPoint(1); beam.startOffset = e.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).AsDouble(); beam.endOffset = e.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).AsDouble(); beam.refLevel = doc.GetElement(e.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsElementId()) as Level; beam.zOffset = e.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE).AsDouble(); beam.startConn = e.get_Parameter(BuiltInParameter.STRUCT_CONNECTION_BEAM_START).AsElementId(); beam.endConn = e.get_Parameter(BuiltInParameter.STRUCT_CONNECTION_BEAM_END).AsElementId(); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // 获取相关文档 UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = commandData.Application.ActiveUIDocument.Document; Reference reference = uidoc.Selection.PickObject(ObjectType.Element); Element element = doc.GetElement(reference); Wall wall = element as Wall; LocationCurve locationCurve = (LocationCurve)wall.Location; Curve curve = locationCurve.Curve; XYZ startPoint = curve.GetEndPoint(0); XYZ endPoint = curve.GetEndPoint(1); TaskDialog.Show("hello, revit2020", startPoint.ToString() + "\n" + endPoint.ToString()); return(Result.Succeeded); }
/// <summary> /// Returns the end point of a Curve based Element. /// </summary> /// <typeparam name="T">The type of the Element in question.</typeparam> /// <param name="obj">The Element where to extract the end point.</param> /// <param name="trf">The transform of the Origo.</param> /// <returns>The end point of the Element's Curve as XYZ.</returns> private static XYZ EndPoint <T>(T obj, Transform trf) where T : Element { if (obj == null) { return(null); } if (obj is FamilyInstance) { FamilyInstance fi = obj as FamilyInstance; LocationCurve loc = fi.Location as LocationCurve; return(trf.OfPoint(loc.Curve.GetEndPoint(1))); } if (obj is CurveElement) { CurveElement cu = obj as CurveElement; return(trf.OfPoint(cu.GeometryCurve.GetEndPoint(1))); } throw new Exception("Type not handled!"); }
/// <summary> /// Return the control points from the connected curve elements. /// </summary> /// <param name="rvtDoc">Revit Document</param> /// <param name="crvElements">Connected curve element</param> /// <returns>Control points</returns> public static IList <XYZ> CalculateControlPoints(Document rvtDoc, IList <ElementId> crvElements) { double maxOffset = 0.0; // All the elements should be line base. for (int i = 0; i < crvElements.Count; i++) { Element curve = rvtDoc.GetElement(crvElements[i]); LocationCurve locationCrv = curve.Location as LocationCurve; if (locationCrv == null || !(locationCrv.Curve is Line)) { throw new ArgumentException("The input elements are not Line base."); } if (Math.Abs(locationCrv.Curve.GetEndPoint(0).Z - locationCrv.Curve.GetEndPoint(1).Z) > 1.0e-9) { throw new AggregateException( "The input curve elements are not in the same elevation plane."); } if (curve is Wall) { maxOffset = Math.Max(maxOffset, ((Wall)curve).Width * 0.5); } } IList <XYZ> controlPoints = CalculateControlPoints2(rvtDoc, crvElements); if (controlPoints.Count == 0) { throw new ArgumentException("The input curve elements are not continues."); } if (!CheckOrientation(controlPoints)) { throw new ArgumentException( "The input curve elements should have the same orientation: CW or CCW."); } if (maxOffset > 0.0) { controlPoints = CalculateOffset(controlPoints, maxOffset); } return(controlPoints); }
/// <summary> /// create beam of certain type in certain position /// </summary> /// <param name="point2D1">one point of the location line in 2D</param> /// <param name="point2D2">another point of the location line in 2D</param> /// <param name="baseLevel">the base level of the beam</param> /// <param name="topLevel">the top level of the beam</param> /// <param name="beamType">type of beam</param> /// <returns>nothing</returns> private void PlaceBeam(UV point2D1, UV point2D2, Level baseLevel, Level topLevel, FamilySymbol beamType) { // create start and end points for beam double height = topLevel.Elevation; XYZ startPoint = m_doc.Document.Application.Create.NewXYZ(point2D1.U, point2D1.V, height); XYZ endPoint = m_doc.Document.Application.Create.NewXYZ(point2D2.U, point2D2.V, height); ElementId topLevelId = topLevel.Id; STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Beam; FamilyInstance beam = m_doc.Document.Create.NewFamilyInstance(startPoint, beamType, topLevel, structuralType); LocationCurve beamCurve = beam.Location as LocationCurve; if (null != beamCurve) { Line line = Line.CreateBound(startPoint, endPoint); beamCurve.Curve = line; } }
public void MapFromDTO(JObject sourceJSON, Autodesk.Revit.DB.Wall dest) { LMAStudio.StreamVR.Common.Models.Wall source = sourceJSON.ToObject <LMAStudio.StreamVR.Common.Models.Wall>(); LocationCurve curve = (dest.Location) as LocationCurve; curve.Curve = Line.CreateBound( new Autodesk.Revit.DB.XYZ( source.Endpoint0.X, source.Endpoint0.Y, source.Endpoint0.Z ), new Autodesk.Revit.DB.XYZ( source.Endpoint1.X, source.Endpoint1.Y, source.Endpoint1.Z ) ); }
private double getDelta_0(Document doc, Rebar myRebar) { //UIDocument uiDoc = this.ActiveUIDocument; //Document doc = uiDoc.Document; //Get diameter of rebar RebarBarType myRbType = doc.GetElement(myRebar.GetTypeId()) as RebarBarType; double myRebarDiameter = myRbType.BarDiameter; // Get host of rebar ElementId myBeamId = myRebar.GetHostId(); Element myBeam = doc.GetElement(myBeamId); if (myBeam.Category.Name != "Structural Framing") { TaskDialog.Show("Loi!", "Hay chon 1 rebar co host la 1 Structural Framing"); return(10000000); } else { //Get location curve of beam LocationCurve lc = myBeam.Location as LocationCurve; Line line = lc.Curve as Line; //Get vector of location cuver beam XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = q - p; // Vector equation of line XYZ middlePoint = myRebar.get_BoundingBox(null).Max.Add(myRebar.get_BoundingBox(null).Min) / 2; // NOTE LAM TRON SO // middlePoint = new XYZ(middlePoint.X,middlePoint.Y), // Math.Round(middlePoint.Z,1)); double delta_0 = Math.Sqrt(Math.Pow(middlePoint.X - p.X, 2) + Math.Pow(middlePoint.Y - p.Y, 2)) - myRebarDiameter / 2; return(delta_0); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; View acview = uidoc.ActiveView; UIView acuiview = uidoc.ActiveUiview(); Transaction ts = new Transaction(doc, "******"); try { ts.Start(); //点选指定执行的元素, 本次按只能选择墙考虑 Reference pickedEleReference = sel.PickObject(ObjectType.Element); //通过引用取到选中的元素 Wall wall = doc.GetElement(pickedEleReference) as Wall; if (null != wall) { LocationCurve wallLine = wall.Location as LocationCurve; XYZ newPlace = new XYZ(100, 200, 0); wallLine.Move(newPlace); } ts.Commit(); } catch (Exception) { if (ts.GetStatus() == TransactionStatus.Started) { ts.RollBack(); } } return(Result.Succeeded); }
public List <List <ElementId> > SortZ(ICollection <ElementId> toSort, Document doc, double dMax) { List <ElementId> zAbove = new List <ElementId>(); List <ElementId> zBelow = new List <ElementId>(); List <ElementId> zRow = new List <ElementId>(); foreach (ElementId eid in toSort) { LocationCurve cLine = doc.GetElement(eid).Location as LocationCurve; double checkZ = cLine.Curve.Evaluate(0.5, true).Z; bool row = true; foreach (ElementId compEid in toSort) { if (eid.IntegerValue == compEid.IntegerValue) { continue; } LocationCurve compLine = doc.GetElement(compEid).Location as LocationCurve; double diffZ = checkZ - compLine.Curve.Evaluate(0.5, true).Z; if (Math.Abs(diffZ) > dMax / 2) { if (diffZ > 0) { zAbove.Add(eid); row = false; break; } else { zBelow.Add(eid); row = false; break; } } } if (row) { zRow.Add(eid); } } List <List <ElementId> > zSorted = new List <List <ElementId> > { zAbove, zBelow, zRow }; return(zSorted); }
private Wall FindIntersectionWall(List <Wall> walls, Wall comparisonWall) { LocationCurve locationCurve = comparisonWall.Location as LocationCurve; Curve wallCurve = locationCurve.Curve as Line; foreach (Wall wall in walls) { LocationCurve lc = wall.Location as LocationCurve; Curve c = lc.Curve; SetComparisonResult intersection = wallCurve.Intersect(c, out IntersectionResultArray resultArray); if (intersection == SetComparisonResult.Equal || intersection == SetComparisonResult.Overlap || intersection == SetComparisonResult.Subset || intersection == SetComparisonResult.Superset) { return(wall); } } return(null); }
/// <summary> /// Get the Insulation Layer of Left hand joined Walls /// </summary> public Curve handleJoinsLeft(Document doc, LocationCurve wallLocCurve, Curve lower, ref List<int> bannedWalls) { if (lower.GetType() == typeof(Arc) || lower.GetType() == typeof(NurbSpline)) return lower; XYZ IntersectionPoint = null; ElementArray elems = wallLocCurve.get_ElementsAtJoin(0); if (elems == null || elems.Size == 0) return lower; foreach (Element elem in elems) { if (elem.GetType() == typeof(Wall)) { Wall wnext = (Wall)elem; if (!bannedWalls.Contains(wnext.Id.IntegerValue)) { Tuple<Curve, Curve> curves = getInsulationLayer(doc, wnext); Curve lowerunbound = lower.Clone(); lowerunbound.MakeUnbound(); Curve upper = curves.Item1.Clone(); upper.MakeUnbound(); IntersectionResultArray result = new IntersectionResultArray(); lowerunbound.Intersect(upper, out result); if (result != null && result.Size == 1) { IntersectionPoint = result.get_Item(0).XYZPoint; } } } } if (IntersectionPoint == null) return lower; Line l = Line.CreateBound(IntersectionPoint, lower.GetEndPoint(1)); return l; }
/// <summary> /// Get the Insulation Layer of Right hand joined Walls /// </summary> public Tuple<Curve, Curve> handleJoinsRight(Document doc, LocationCurve wallLocCurve, Curve lower, Curve upper, ref List<int> bannedWalls) { Tuple<Curve, Curve> existing = new Tuple<Curve, Curve>(upper, lower); if (lower.GetType() == typeof(Arc) || lower.GetType() == typeof(NurbSpline)) return existing; if (upper.GetType() == typeof(Arc) || upper.GetType() == typeof(NurbSpline)) return existing; XYZ IntersectionPointLower = null; XYZ IntersectionPointUpper = null; ElementArray elems = wallLocCurve.get_ElementsAtJoin(1); if (elems == null || elems.Size == 0) return existing; foreach (Element elem in elems) { if (elem.GetType() == typeof(Wall)) { Wall wnext = (Wall)elem; if (!bannedWalls.Contains(wnext.Id.IntegerValue)) { Tuple<Curve, Curve> curves = getInsulationLayer(doc, wnext); Curve lowerunbound = lower.Clone(); lowerunbound.MakeUnbound(); Curve upperunbound = upper.Clone(); upperunbound.MakeUnbound(); Curve lowernext = curves.Item2.Clone(); lowernext.MakeUnbound(); IntersectionResultArray result = new IntersectionResultArray(); lowerunbound.Intersect(lowernext, out result); if (result != null && result.Size == 1) { IntersectionPointLower = result.get_Item(0).XYZPoint; } upperunbound.Intersect(lowernext, out result); if (result != null && result.Size == 1) { IntersectionPointUpper = result.get_Item(0).XYZPoint; } } } } if (IntersectionPointLower == null || IntersectionPointUpper == null) return existing; return new Tuple<Curve, Curve>(Line.CreateBound(upper.GetEndPoint(0), IntersectionPointUpper), Line.CreateBound(lower.GetEndPoint(0), IntersectionPointLower)); }
/// <summary> /// Checks a single linear wall for embedded columns. /// </summary> /// <param name="wall">The wall to check.</param> /// <param name="locationCurve">The location curve extracted from this wall.</param> /// <param name="wallCurve">The profile of the wall.</param> private void CheckLinearWallForEmbeddedColumns(Wall wall, LocationCurve locationCurve, Curve wallCurve) { double bottomHeight = GetElevationForRay(wall); FindColumnsOnEitherSideOfWall(wall, locationCurve, wallCurve, 0, bottomHeight, wallCurve.Length); }
private void Stream(ArrayList data, LocationCurve locCrv) { data.Add(new Snoop.Data.ClassSeparator(typeof(LocationCurve))); data.Add(new Snoop.Data.Object("Curve", locCrv.Curve)); }
/// <summary> /// Finds columns on either side of the given wall. /// </summary> /// <param name="wall">The wall.</param> /// <param name="locationCurve">The location curve of the wall.</param> /// <param name="wallCurve">The profile of the wall.</param> /// <param name="parameter">The normalized parameter along the wall profile which is being evaluated.</param> /// <param name="elevation">The elevation at which the rays are cast.</param> /// <param name="within">The maximum distance away that columns may be found.</param> private void FindColumnsOnEitherSideOfWall(Wall wall, LocationCurve locationCurve, Curve wallCurve, double parameter, double elevation, double within) { XYZ rayDirection = GetTangentAt(wallCurve, parameter); XYZ wallLocation = wallCurve.Evaluate(parameter, true); XYZ wallDelta = GetWallDeltaAt(wall, locationCurve, parameter); XYZ rayStart = new XYZ(wallLocation.X + wallDelta.X, wallLocation.Y + wallDelta.Y, elevation); FindColumnsByDirection(rayStart, rayDirection, within, wall); rayStart = new XYZ(wallLocation.X - wallDelta.X, wallLocation.Y - wallDelta.Y, elevation); FindColumnsByDirection(rayStart, rayDirection, within, wall); }
/// <summary> /// Finds the normal to the wall centerline at the given parameter. /// </summary> /// <param name="wall">The wall.</param> /// <param name="curve">The location curve of the wall.</param> /// <param name="parameter">The normalized parameter.</param> /// <returns>The normalized normal vector.</returns> private XYZ GetNormalToWallAt(Wall wall, LocationCurve curve, double parameter) { Curve wallCurve = curve.Curve; // There is no normal at a given point for a line. We need to get the normal based on the tangent of the wall location curve. if (wallCurve is Line) { XYZ wallDirection = GetTangentAt(wallCurve, 0); XYZ wallNormal = new XYZ(wallDirection.Y, wallDirection.X, 0); return wallNormal; } else { Transform t = wallCurve.ComputeDerivatives(parameter, true); // For non-linear curves, BasisY is the normal vector to the curve. return t.BasisY.Normalize(); } }
/// <summary> /// Obtains the offset to the wall at a given location along the wall's profile. /// </summary> /// <param name="wall">The wall.</param> /// <param name="locationCurve">The location curve of the wall.</param> /// <param name="parameter">The normalized parameter along the location curve of the wall.</param> /// <returns>An XY vector representing the offset from the wall centerline.</returns> private XYZ GetWallDeltaAt(Wall wall, LocationCurve locationCurve, double parameter) { XYZ wallNormal = GetNormalToWallAt(wall, locationCurve, parameter); double wallWidth = wall.Width; // The LocationCurve is always the wall centerline, regardless of the setting for the wall Location Line. // So the delta to place the ray just outside the wall extents is always 1/2 the wall width + a little extra. XYZ wallDelta = new XYZ(wallNormal.X * wallWidth / 2 + WALL_EPSILON, wallNormal.Y * wallWidth / 2 + WALL_EPSILON, 0); return wallDelta; }
/// <summary> /// Check wall's two ends in three states /// </summary> /// <param name="wall">The wall to be checked</param> /// <param name="locationCurve">The wall's location curve</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <param name="endnode">Result XML node</param> /// <returns>The check result</returns> private XElement checkWallEnd(Wall wall, LocationCurve locationCurve, int end, XElement endnode) { // Initial state XElement stateNode = new XElement("Initial", new XAttribute("Name", "Initial")); endnode.Add(GetState(wall, locationCurve, end, stateNode)); // Disallow join WallUtils.DisallowWallJoinAtEnd(wall, end); // After DisallowWallJoinAtEnd Evoked state stateNode = new XElement("After_DisallowWallJoinAtEnd_Evoked", new XAttribute("Name", "After_DisallowWallJoinAtEnd_Evoked")); endnode.Add(GetState(wall, locationCurve, end, stateNode)); // Allow join WallUtils.AllowWallJoinAtEnd(wall, end); // After AllowWallJoinAtEnd Evoked state stateNode = new XElement("After_DisallowWallJoinAtEnd_Evoked", new XAttribute("Name", "After_DisallowWallJoinAtEnd_Evoked")); endnode.Add(GetState(wall, locationCurve, end, stateNode)); return endnode; }
/// <summary> /// Get wall's one end state /// </summary> /// <param name="wall">The wall to be checked</param> /// <param name="locationCurve">The wall's location curve</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <param name="statenode">Result XML node</param> /// <returns>The check result</returns> private XElement GetState(Wall wall, LocationCurve locationCurve, int end, XElement statenode) { // Get geometry information statenode.Add(GetGeometryInfo(locationCurve, end)); // Get IsWallJoinAllowedAtEnd API method's result statenode.Add(GetIsWallJoinAllowedAtEnd(wall, end)); // Get all joined walls statenode.Add(GetJoinedWalls(locationCurve, end)); return statenode; }
/// <summary> /// Get wall's one end all joined walls /// </summary> /// <param name="locationCurve">The wall's location curve</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <returns>The check result</returns> private XElement GetJoinedWalls(LocationCurve locationCurve, int end) { // retrieve joined elements ElementArray array = locationCurve.get_ElementsAtJoin(end); XElement joinedwallsNode = new XElement("JoinedWalls", new XAttribute("Count", array.Size.ToString())); // output array foreach (Element ele in array) { if (ele is Wall) { joinedwallsNode.Add(new XElement("JoinedWall", new XAttribute("Name", ele.Name))); } } return joinedwallsNode; }
/// <summary> /// Get wall's one end geometry information /// </summary> /// <param name="locationCurve">The wall's location curve</param> /// <param name="end">The index indicates the start or end of this wall</param> /// <returns>The check result</returns> private XElement GetGeometryInfo(LocationCurve locationCurve, int end) { XElement geometryinfoNode = new XElement("GeometryInfo"); // Output LocationCurve end point coordinate XYZ endpoint = locationCurve.Curve.get_EndPoint(end); geometryinfoNode.Add(new XElement("PointCoordinate", new XAttribute("X", Math.Round(endpoint.X, 9).ToString()), new XAttribute("Y", Math.Round(endpoint.Y, 9).ToString()), new XAttribute("Z", Math.Round(endpoint.Z, 9).ToString()))); return geometryinfoNode; }