/// <summary> /// Creates trusses along a specific ridge edge and stores them on a list of truss info /// </summary> /// <param name="currentRidgeEdgeInfo">The specific edge ridge to create trusses</param> /// <param name="doc">The target document to create the trusses</param> /// <param name="tType">The target truss type to be used on creation</param> /// <returns>The list of info of the created trusses</returns> private IList <TrussInfo> CreateTrussInfoList(EdgeInfo currentRidgeEdgeInfo, Document doc, TrussType tType) { IList <TrussInfo> trussInfoList = new List <TrussInfo>(); if (currentRidgeEdgeInfo.RoofLineType == RoofLineType.RidgeSinglePanel || currentRidgeEdgeInfo.RoofLineType == RoofLineType.Ridge) { Line currentRidgeLineShortenedBySupports = currentRidgeEdgeInfo.Curve as Line; if (currentRidgeLineShortenedBySupports == null) { return(trussInfoList); } IList <EdgeInfo> startConditions = currentRidgeEdgeInfo.GetEndConditions(0); IList <EdgeInfo> endConditions = currentRidgeEdgeInfo.GetEndConditions(1); currentRidgeLineShortenedBySupports = ShortenRidgeIfNecessary(currentRidgeLineShortenedBySupports, startConditions, endConditions); Tuple <int, double> iterations = Utils.Utils.EstabilishIterations(currentRidgeLineShortenedBySupports.ApproximateLength, trussDistance); int numPoints = iterations.Item1; double distance = iterations.Item2; for (int i = 0; i <= numPoints; i++) { double currentParam = i * distance; XYZ currentPointOnRidge = currentRidgeLineShortenedBySupports.Evaluate(currentRidgeLineShortenedBySupports.GetEndParameter(0) + currentParam, false); TrussInfo currentTrussInfo = TrussInfo.BuildTrussAtRidge(currentPointOnRidge, currentRidgeEdgeInfo, null); if (currentTrussInfo != null) { SketchPlane stkP = SketchPlane.Create(doc, currentRidgeEdgeInfo.CurrentRoof.LevelId); double levelHeight = currentRidgeEdgeInfo.GetCurrentRoofHeight(); XYZ firstPoint = new XYZ(currentTrussInfo.FirstPoint.X, currentTrussInfo.FirstPoint.Y, levelHeight); XYZ secondPoint = new XYZ(currentTrussInfo.SecondPoint.X, currentTrussInfo.SecondPoint.Y, levelHeight); Truss currentTruss = Truss.Create(doc, tType.Id, stkP.Id, Line.CreateBound(firstPoint, secondPoint)); currentTruss.get_Parameter(BuiltInParameter.TRUSS_HEIGHT).Set(currentTrussInfo.Height); trussInfoList.Add(currentTrussInfo); } #region DEBUG ONLY else { #if DEBUG FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint")).FirstOrDefault() as FamilySymbol; fs.Activate(); doc.Create.NewFamilyInstance(currentPointOnRidge, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); #endif } #endregion } } return(trussInfoList); }
public static FamilySymbol GetFamilySymbol(this Document doc, string familyName, string name) { FamilySymbol symbol = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)) .OfType <FamilySymbol>() .FirstOrDefault(x => x.FamilyName == familyName && x.Name == name); if (symbol != null && !symbol.IsActive) { symbol.Activate(); } return(symbol); }
private string LoadWindowOpenning(Transaction transaction) { FamilySymbol symbol = new FilteredElementCollector(_document).OfCategory(BuiltInCategory.OST_Windows) .OfClass(typeof(FamilySymbol)) .FirstOrDefault(x => x.Name.Equals(_openningName)) as FamilySymbol; List <Wall> walls = GetWallContainOpening(_origin, _direction, _height, out Line cuttingLine); if (walls != null && walls.Count > 0) { //Loc wall Wall wall = walls[0]; XYZ locationIntersecWithWall = GetPointIntersecWithWall(wall, cuttingLine, out bool isOvelapWithAnotherWindown); if (!isOvelapWithAnotherWindown) { if (locationIntersecWithWall != null) { ElementId id = null; // create wall opening transaction.Start("Create Opening"); symbol.Activate(); Parameter parameterBase = wall.LookupParameter("Base Constraint"); Level level = _document.GetElement(parameterBase.AsElementId()) as Level; /*GetNearestLevelByDirection(locationIntersecWithWall);*/ //MessageBox.Show(level.Name); FamilyInstance instance = _document.Create.NewFamilyInstance(locationIntersecWithWall, symbol, wall, level, StructuralType.UnknownFraming); id = instance.Id; transaction.Commit(); // update opening if (Common.CanUpdateNewOpening(_document, transaction, id)) { transaction.Start("UpDate"); UpdateGeometryAndDirection(instance); transaction.Commit(); if (Common.CanUpdateNewOpening(_document, transaction, id)) { _comparionCoupleElement.IdRevitElement = instance.UniqueId; } } return(instance.UniqueId); } } } if (!Common.IsValidGuid(_comparionCoupleElement.IdRevitElement)) { _comparionCoupleElement.IdRevitElement = new Guid().ToString(); } return(""); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; FamilySymbol columnType = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Columns).OfClass(typeof(FamilySymbol)).FirstOrDefault(x => x.Name == "457 x 475mm") as FamilySymbol; Level level = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).OfClass(typeof(Level)).FirstOrDefault(x => x.Name == "标高 1") as Level; List <XYZ> xyzlist = new List <XYZ>(); for (int i = 0; i < 72; i++) { double x = 10 * (2 * Math.Cos(2 * Math.PI / 72 * i) - Math.Cos(2 * 2 * Math.PI / 72 * i)); double y = 10 * (2 * Math.Sin(2 * Math.PI / 72 * i) - Math.Sin(2 * 2 * Math.PI / 72 * i)); XYZ start = new XYZ(x, y, 0); xyzlist.Add(start); } double height = 15 / 0.3048; double offset = 0; List <FamilyInstance> familyInstances = new List <FamilyInstance>(); Transaction trans = new Transaction(doc, "创建多个柱子"); foreach (XYZ item in xyzlist) { trans.Start(); columnType.Activate(); FamilyInstance column = doc.Create.NewFamilyInstance(item, columnType, level, StructuralType.NonStructural); trans.Commit(); System.Windows.Forms.Application.DoEvents(); Thread.Sleep(100); familyInstances.Add(column); } Transaction transRotate = new Transaction(doc, "创建多个柱子"); for (int j = 0; j < 100; j++) { transRotate.Start(); for (int k = 0; k < xyzlist.Count; k++) { Line line = Line.CreateBound(xyzlist[k], new XYZ(xyzlist[k].X, xyzlist[k].Y, 10)); ElementTransformUtils.RotateElement(doc, familyInstances[k].Id, line, Math.PI / 6.0); } transRotate.Commit(); System.Windows.Forms.Application.DoEvents(); } return(Result.Succeeded); }
public void Create(Document doc) { FamilySymbol neocube = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(q => q.Name == "cube").First() as FamilySymbol; if (!neocube.IsActive) { neocube.Activate(); } FamilyInstance unit = doc.Create.NewFamilyInstance(new XYZ(), neocube, StructuralType.NonStructural); unit.setP("g_pos", out_Pos); unit.setP("g_gost", out_Gost); unit.setP("g_name", out_Name); unit.setP("g_num", out_Kol_vo); unit.setP("g_mass", out_Mass); unit.setP("g_other", out_Other); unit.setP("g_group", out_Group); unit.setP("g_snos", out_Snos); //unit.LookupParameter("g_sort").Set(this.Prior).ToString(); unit.setP("g_sort", Prior.ToString()); }
internal static List <(FamilyInstance, RevitPlacmenElement)> PlaceRevitFamilies(List <RevitPlacmenElement> RevitPlacmentPoints, UIDocument uiDoc, string FamilyPath, string TypeName, ElementTransformParams transform) { List <(FamilyInstance, RevitPlacmenElement)> CreatedInstances = new List <(FamilyInstance, RevitPlacmenElement)>(); string FamilyName = string.Empty; RevitPlacmentPoints = RevitPlacmentPoints.Distinct(new ComparePlacmentPoints()).ToList(); RevitPlacmentPoints.Sort(delegate(RevitPlacmenElement c1, RevitPlacmenElement c2) { return(c1.Station.CompareTo(c2.Station)); }); using (Transaction T = new Transaction(uiDoc.Document, "Place Objects")) { T.Start(); try { uiDoc.Document.LoadFamily(FamilyPath); FamilyName = System.IO.Path.GetFileNameWithoutExtension(FamilyPath); } catch (Exception) { } try { FamilySymbol Fam = new FilteredElementCollector(uiDoc.Document).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().FirstOrDefault(F => F.Name == TypeName && F.FamilyName == FamilyName); Fam.Activate(); if (transform.StationToStartFrom != default(double)) { RevitPlacmentPoints.RemoveAll(E => E.Station < transform.StationToStartFrom); } if (transform.StationToEndAt != default(double)) { RevitPlacmentPoints.RemoveAll(E => E.Station > transform.StationToEndAt); } for (int i = 0; i < RevitPlacmentPoints.Count; i++) { FamilyInstance FamIns = uiDoc.Document.Create.NewFamilyInstance(RevitPlacmenElement.ConvertPointToInternal(RevitPlacmentPoints[i].PlacementPoint), Fam, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); RevitPlacmentPoints[i].FillAttributes(FamIns); CreatedInstances.Add((FamIns, RevitPlacmentPoints[i]));
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; if ((uidoc.ActiveView as View3D) == null) { message = "Por favor, rode este comando em uma vista 3d"; return(Result.Failed); } Reference currentReference = uidoc.Selection.PickObject(ObjectType.Edge); FootPrintRoof currentFootPrintRoof = doc.GetElement(currentReference.ElementId) as FootPrintRoof; Edge edge = currentFootPrintRoof.GetGeometryObjectFromReference(currentReference) as Edge; IList <PlanarFace> pfaces = new List <PlanarFace>(); Support.IsListOfPlanarFaces(HostObjectUtils.GetBottomFaces(currentFootPrintRoof).Union(HostObjectUtils.GetTopFaces(currentFootPrintRoof)).ToList() , currentFootPrintRoof, out pfaces); RoofClasses.EdgeInfo currentInfo = Support.GetCurveInformation(currentFootPrintRoof, edge.AsCurve(), pfaces); using (Transaction t = new Transaction(doc, "Test")) { t.Start(); FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint")).FirstOrDefault() as FamilySymbol; fs.Activate(); doc.Create.NewFamilyInstance((currentInfo.Curve as Line).Direction, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(-90), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); doc.Create.NewFamilyInstance(((currentInfo.Curve as Line).Direction).Rotate(45), fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); t.Commit(); } return(Result.Succeeded); }
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; PhaseArray xcom = doc.Phases; Phase lastPhase = xcom.get_Item(xcom.Size - 1); FilterableValueProvider providerRoom = new ParameterValueProvider(new ElementId((int)BuiltInParameter.ROOM_PHASE_ID)); FilterableValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.PHASE_CREATED)); FilterNumericRuleEvaluator evaluator = new FilterNumericEquals(); double FT = 0.3048; ElementId idPhase = lastPhase.Id; FilterElementIdRule rRule = new FilterElementIdRule(providerRoom, evaluator, idPhase); FilterElementIdRule fRule = new FilterElementIdRule(provider, evaluator, idPhase); ElementParameterFilter room_filter = new ElementParameterFilter(rRule); ElementParameterFilter door_filter = new ElementParameterFilter(fRule); IList <Element> rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms) .WhereElementIsNotElementType() .WherePasses(room_filter) .ToElements(); IList <FamilyInstance> doors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors) .WhereElementIsNotElementType() .WherePasses(door_filter).Cast <FamilyInstance>().ToList(); IList <FamilyInstance> windows = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Windows) .WhereElementIsNotElementType() .WherePasses(door_filter).Cast <FamilyInstance>().ToList(); FamilySymbol neocube = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(q => q.Name == "cube").First() as FamilySymbol; IList <XYZ> a = new List <XYZ>(); IList <String> b = new List <String>(); //Room two = rooms[0] as Room; int g = 0; FilterStringRuleEvaluator cubeEval = new FilterStringEquals(); FilterableValueProvider cubeProv = new ParameterValueProvider(new ElementId((int)BuiltInParameter.ALL_MODEL_TYPE_NAME)); FilterStringRule cubeRule = new FilterStringRule(cubeProv, cubeEval, "cube", false); ElementParameterFilter cubeFilter = new ElementParameterFilter(cubeRule); List <FamilyInstance> existCubes = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsNotElementType().WherePasses(cubeFilter).Cast <FamilyInstance>().ToList(); using (Transaction tr = new Transaction(doc, "creating")) { tr.Start(); foreach (FamilyInstance i in existCubes) { doc.Delete(i.Id); } foreach (Element i in rooms) { for (int ind = 0; ind < doors.Count; ind++) { FamilyInstance dr = doors[ind]; try { if (dr.get_FromRoom(lastPhase).Id == i.Id | dr.get_ToRoom(lastPhase).Id == i.Id) { BoundingBoxXYZ bBox = i.get_BoundingBox(null); LocationPoint origin = (LocationPoint)i.Location; XYZ center = origin.Point; if (!neocube.IsActive) { neocube.Activate(); } FamilyInstance cubeIns = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); cubeIns.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); cubeIns.LookupParameter("MainText").Set(dr.Symbol.LookupParameter("ADSK_Марка").AsString()); cubeIns.setType(); b.Append("ok"); //dr.LookupParameter("ADSK_Марка").AsValueString()); doors.Remove(dr); ind--; } } catch (Exception) { } } /* * foreach (FamilyInstance dr in doors) * { * try * { * if (dr.get_FromRoom(lastPhase).Id == i.Id | dr.get_ToRoom(lastPhase).Id == i.Id) * { * * BoundingBoxXYZ bBox = i.get_BoundingBox(null); * LocationPoint origin = (LocationPoint)i.Location; * * XYZ center = origin.Point; * if (!neocube.IsActive) * neocube.Activate(); * FamilyInstance cubeIns = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); * cubeIns.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); * cubeIns.LookupParameter("MainText").Set(dr.Symbol.LookupParameter("ADSK_Марка").AsString()); * cubeIns.LookupParameter("isAreo").Set(0); * * b.Append("ok");//dr.LookupParameter("ADSK_Марка").AsValueString()); * * } * } * catch (Exception) * { * * } * } */ foreach (FamilyInstance dr in windows) { try { if (dr.get_FromRoom(lastPhase).Id == i.Id) { LocationPoint origin = (LocationPoint)i.Location; XYZ center = origin.Point; if (!neocube.IsActive) { neocube.Activate(); } FamilyInstance cubeIns = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); cubeIns.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); cubeIns.LookupParameter("MainText").Set(dr.Symbol.LookupParameter("ADSK_Марка").AsString()); cubeIns.setType(); FamilyInstance winOtkos = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); winOtkos.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); winOtkos.LookupParameter("MainText").Set("Площадь откосов: "); winOtkos.LookupParameter("Area").Set(dr.LookupParameter("ADSK_Откосы_Глубина").AsDouble() * (dr.LookupParameter("VIDNAL_Высота проема").AsDouble() * 2 + dr.LookupParameter("VIDNAL_Ширина проема").AsDouble())); winOtkos.setType("area"); FamilyInstance winPodok = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); winPodok.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); String output = String.Format("Подоконник {0:f2}x{1:f2}", dr.LookupParameter("VIDNAL_Ширина проема").AsDouble() * FT, dr.LookupParameter("ADSK_Откосы_Глубина").AsDouble() * FT); winPodok.LookupParameter("MainText").Set(output); winPodok.setType(); FamilyInstance winUgol = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); winUgol.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); winUgol.LookupParameter("MainText").Set("ПВХ уголок 60х60"); winUgol.LookupParameter("dlina").Set(dr.LookupParameter("VIDNAL_Высота проема").AsDouble() * 2 + dr.LookupParameter("VIDNAL_Ширина проема").AsDouble()); winUgol.setType("len"); } } catch (Exception) { } } } foreach (Element i in rooms) { if (i.LookupParameter("ЗаменаПокрытияПола").AsInteger() == 1) { LocationPoint origin = (LocationPoint)i.Location; XYZ center = origin.Point; if (!neocube.IsActive) { neocube.Activate(); } FamilyInstance cubeIns = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); cubeIns.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); cubeIns.LookupParameter("MainText").Set(i.LookupParameter("snosF").AsString()); cubeIns.LookupParameter("Area").Set(i.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble()); cubeIns.setType("area"); if (cubeIns.LookupParameter("MainText").AsString() == "") { doc.Delete(cubeIns.Id); } } if (i.LookupParameter("НоваяОтделка").AsInteger() == 1) { LocationPoint origin = (LocationPoint)i.Location; XYZ center = origin.Point; if (!neocube.IsActive) { neocube.Activate(); } FamilyInstance cubeIns = doc.Create.NewFamilyInstance(center, neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); cubeIns.LookupParameter("RoomNum").Set(i.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()); cubeIns.LookupParameter("MainText").Set("Демонтаж штукатурки"); cubeIns.LookupParameter("Area").Set(i.LookupParameter("WallS").AsDouble()); cubeIns.setType("area"); } } tr.Commit(); } //XYZ origin = new XYZ(0,0,0); /* * using (Transaction tr = new Transaction(doc,"creating")) * { * tr.Start(); * * for (int i = 0; i < a.Count; i++) * { * if (!neocube.IsActive) * neocube.Activate(); * FamilyInstance cubeIns = doc.Create.NewFamilyInstance(a[i], neocube, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); * cubeIns.LookupParameter("MainText").Set(b[i]); * } * * * tr.Commit(); * * } */ //FamilySymbol elt = doors[0].Symbol; //FamilySymbol one=elt as FamilySymbol; TaskDialog msg = new TaskDialog("Info"); msg.MainInstruction = g.ToString(); msg.Show(); return(Result.Succeeded); }
public Result setup_joists() { using (Transaction t = new Transaction(doc, "Joists")) { t.Start(); Family f = null; //FIXME : move to a function that's called only once string familyPath = @"C:\ProgramData\Autodesk\RVT 2019\Libraries\US Imperial\Structural Framing\Wood\Plywood Web Joist.rfa"; doc.LoadFamily(familyPath, out f); XYZ pt0 = XYZ.Zero; Line directionLine = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 5, -joist_offset)); SketchPlane sp = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, new XYZ(0, 40, -joist_offset))); BeamSystem bs = BeamSystem.Create(doc, joistCurves, sp, directionLine.Direction, false); //get the layoutRule of the beamsystem Autodesk.Revit.DB.LayoutRule layoutRule = bs.LayoutRule; //create a new instance of the LayoutRuleClearSpacing class LayoutRuleClearSpacing myLayoutRuleClearSpacing = new LayoutRuleClearSpacing(2.0, BeamSystemJustifyType.Beginning); //set the new layoutRule to the beamsystem bs.LayoutRule = myLayoutRuleClearSpacing; t.Commit(); } // Metal beam double offset_from_floor = 80 / 12.0; XYZ startPoint = new XYZ(0.0, 183 / 12.0, level.Elevation + offset_from_floor); XYZ endPoint = new XYZ(472 / 12.0, 183 / 12.0, level.Elevation + offset_from_floor); FamilySymbol beamSymbol = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>() .First(q => q.Family.FamilyCategory.Name == "Structural Framing" && q.Family.Name == "W Shapes" && q.Name == "W12X26"); using (Transaction t = new Transaction(doc)) { t.Start("Activate beam"); if (!beamSymbol.IsActive) { beamSymbol.Activate(); // doc.Regenerate(); } t.Commit(); } // try to insert an instance using (Transaction tx = new Transaction(doc)) { tx.Start("insert beam"); FamilyInstance fi = doc.Create.NewFamilyInstance(XYZ.Zero, beamSymbol, StructuralType.Beam); (fi.Location as LocationCurve).Curve = Line.CreateBound(startPoint, endPoint);; tx.Commit(); } return(Result.Succeeded); }
public Result insert_windows(XYZ[] windows_locations, Level level) { FamilySymbol wfs = new FilteredElementCollector(doc) .OfClass(typeof(FamilySymbol)) .Cast <FamilySymbol>().FirstOrDefault(q => q.Name == "48\" x 60\""); using (Transaction t = new Transaction(doc)) { t.Start("Activate window"); if (!wfs.IsActive) { wfs.Activate(); doc.Regenerate(); } t.Commit(); } foreach (XYZ location in windows_locations) { DoorOperations orientation = (DoorOperations)location.Z; XYZ window_location = new XYZ(location.X, location.Y, level.Elevation + 2.5); // Windows should be at 30" from the ground #region Find the hosting Wall (nearest wall to the insertion point) FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(Wall)); List <Wall> walls = collector.Cast <Wall>().Where(wl => wl.LevelId == level.Id).ToList(); Wall w_ = null; double distance = double.MaxValue; foreach (Wall w in walls) { double proximity = (w.Location as LocationCurve).Curve.Distance(window_location); if (proximity < distance) { distance = proximity; w_ = w; } } #endregion using (Transaction t = new Transaction(doc)) { t.Start("Create window"); FamilyInstance window = doc.Create.NewFamilyInstance(window_location, wfs, w_, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); if ((orientation & DoorOperations.Should_flip) != 0) { window.flipFacing(); } if ((orientation & DoorOperations.Should_rotate) != 0) { window.flipHand(); } t.Commit(); } } return(Result.Succeeded); }
public Result insert_doors(XYZ[] doors_locations, Level level) { FamilySymbol fs = new FilteredElementCollector(doc) .OfClass(typeof(FamilySymbol)) .Cast <FamilySymbol>().FirstOrDefault(q => q.Name == "36\" x 84\""); using (Transaction t = new Transaction(doc)) { t.Start("Activate door"); if (!fs.IsActive) { fs.Activate(); doc.Regenerate(); } t.Commit(); } foreach (XYZ location in doors_locations) { DoorOperations orientation = (DoorOperations)location.Z; XYZ door_location = new XYZ(location.X, location.Y, level.Elevation); #region Find the hosting Wall (nearest wall to the insertion point) FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(Wall)); List <Wall> walls = collector.Cast <Wall>().Where(wl => wl.LevelId == level.Id).ToList(); Wall w_ = null; double distance = double.MaxValue; foreach (Wall w in walls) { double proximity = (w.Location as LocationCurve).Curve.Distance(door_location); if (proximity < distance) { distance = proximity; w_ = w; } } #endregion using (Transaction t = new Transaction(doc)) { t.Start("Create door"); FamilyInstance door = doc.Create.NewFamilyInstance(door_location, fs, w_, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); // Doors probably face up by default. Or maybe it depends on the wall direction? // E-W wall = door N by default if ((orientation & DoorOperations.Should_flip) != 0) { door.flipFacing(); } if ((orientation & DoorOperations.Should_rotate) != 0) { door.flipHand(); } t.Commit(); } } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Path of file string filePath = null; // Using Windows form to get file path using (Data form = new Data()) { OpenFileDialog browserDialog = new OpenFileDialog(); browserDialog.ShowDialog(); if (browserDialog.FileName != null) { filePath = browserDialog.FileName; } else { return(Result.Cancelled); } } // Get Dxf document DxfDocument document = DxfDocument.Load(filePath); // Get Revit UI document UIDocument uIDocument = commandData.Application.ActiveUIDocument; // Get Revit document Document rvtDocument = uIDocument.Document; //Get Level of revit file List <Level> levels = new FilteredElementCollector(rvtDocument) .OfCategory(BuiltInCategory.OST_Levels) .WhereElementIsNotElementType().Cast <Level>().ToList(); // Get Wall Type var wallType = new FilteredElementCollector(rvtDocument) .OfCategory(BuiltInCategory.OST_Walls) .WhereElementIsElementType() .Cast <WallType>() .FirstOrDefault(); // Get Layers of dxf file List <Layer> layers = document.Layers.ToList(); // Declear variables string base_level_name = null; string top_level_name = null; string column_layer = null; string wall_layer = null; string floor_layer = null; // Get Data from user by form using (Data form = new Data()) { // Set dxf layers to comboBoxs form.ComboBox_wall_layer.Items.AddRange(layers.Select(layer => (object)layer).ToArray()); form.ComboBox_col_layer.Items.AddRange(layers.Select(layer => (object)layer).ToArray()); form.ComboBox_floor_layer.Items.AddRange(layers.Select(layer => (object)layer).ToArray()); // Set levels to ComboBoxs form.ComboBox_base_level.Items.AddRange(levels.Select(l => (object)l.Name).ToArray()); form.ComboBox_top_level.Items.AddRange(levels.Select(l => (object)l.Name).ToArray()); form.ShowDialog(); if (form.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return(Result.Cancelled); } else if (form.Button_ok.DialogResult == System.Windows.Forms.DialogResult.OK) { //Get Data from ComboBoxs base_level_name = form.ComboBox_base_level.SelectedItem.ToString(); top_level_name = form.ComboBox_top_level.SelectedItem.ToString(); wall_layer = form.ComboBox_wall_layer.SelectedItem.ToString(); column_layer = form.ComboBox_col_layer.SelectedItem.ToString(); floor_layer = form.ComboBox_floor_layer.SelectedItem.ToString(); } } // Get Data of vertix and its layer by sending document and layers Dxf_Vertices vertices = new Dxf_Vertices(document, column_layer, wall_layer, floor_layer); // Get Column Vertix Dxf_Column columns = new Dxf_Column(vertices); // Get Walls Vertix Dxf_Wall walls = new Dxf_Wall(vertices); // Get Floor Vertix Dxf_Floor floor = new Dxf_Floor(vertices); RVT_Col rVT_Col = new RVT_Col(columns.Points); RVT_Wall rVT_Wall = new RVT_Wall(walls.Walls_center); RVT_Floor rVT_Floor = new RVT_Floor(floor.Floor_boundary); Level base_level = GetLEVEL(rvtDocument, base_level_name); Level top_level = GetLEVEL(rvtDocument, top_level_name); FamilySymbol symbol; using (Transaction t = new Transaction(rvtDocument, "Load")) { t.Start(); bool ff = rvtDocument.LoadFamily($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\Concrete-Rectangular-Column.rfa"); symbol = new FilteredElementCollector(rvtDocument).OfClass(typeof(FamilySymbol)) .WhereElementIsElementType() .Cast <FamilySymbol>() .First(x => x.Name == "12 x 18"); symbol.Activate(); t.Commit(); } using (Transaction t = new Transaction(rvtDocument, "Create ")) { t.Start(); WallType newWallType = CreateWallType(rvtDocument, wallType, 300); rVT_Col.CreateColumns(rvtDocument, symbol, base_level, top_level); rVT_Wall.CreateWalls(rvtDocument, newWallType, base_level, top_level); rVT_Floor.CreateFloor(rvtDocument, top_level); t.Commit(); } return(Result.Succeeded); }
// Creates a generic model instance in a project or family doc public string BlockInstanceToNative(BlockInstance instance, Document familyDoc = null) { string result = null; // Base point var basePoint = PointToNative(instance.insertionPoint); // Get or make family from block definition FamilySymbol familySymbol = new FilteredElementCollector(Doc) .OfClass(typeof(Family)) .OfType <Family>() .FirstOrDefault(f => f.Name.Equals("SpeckleBlock_" + instance.blockDefinition.name)) ?.GetFamilySymbolIds() .Select(id => Doc.GetElement(id)) .OfType <FamilySymbol>() .First(); if (familySymbol == null) { var familyPath = BlockDefinitionToNative(instance.blockDefinition); if (familyDoc != null) { if (familyDoc.LoadFamily(familyPath, new FamilyLoadOption(), out var fam)) { ; } familySymbol = familyDoc.GetElement(fam.GetFamilySymbolIds().First()) as DB.FamilySymbol; } else { if (Doc.LoadFamily(familyPath, new FamilyLoadOption(), out var fam)) { familySymbol = Doc.GetElement(fam.GetFamilySymbolIds().First()) as DB.FamilySymbol; } } familySymbol.Activate(); //File.Delete(familyPath); } // see if this is a nested family instance or to be inserted in project FamilyInstance _instance = null; if (familyDoc != null) { _instance = familyDoc.FamilyCreate.NewFamilyInstance(basePoint, familySymbol, DB.Structure.StructuralType.NonStructural); familyDoc.Regenerate(); } else { _instance = Doc.Create.NewFamilyInstance(basePoint, familySymbol, DB.Structure.StructuralType.NonStructural); Doc.Regenerate(); } // transform if (_instance != null) { if (MatrixDecompose(instance.transform, out double rotation)) { try { // some point based families don't have a rotation, so keep this in a try catch if (rotation != (_instance.Location as LocationPoint).Rotation) { var axis = DB.Line.CreateBound(new XYZ(basePoint.X, basePoint.Y, 0), new XYZ(basePoint.X, basePoint.Y, 1000)); (_instance.Location as LocationPoint).Rotate(axis, rotation - (_instance.Location as LocationPoint).Rotation); } } catch { } } SetInstanceParameters(_instance, instance); result = "success"; } return(result); }