public static List <Revit.Elements.Element> CreateWallSweep(List <Revit.Elements.Wall> Walls, Revit.Elements.Element TypeElement, string SweepOrReveal, bool IsVertical, double Offset = 1000) { var doc = DocumentManager.Instance.CurrentDBDocument; var WallSweeps = new List <Revit.Elements.Element>(); var wallSweepTypes = new Dictionary <string, Autodesk.Revit.DB.WallSweepType>(); wallSweepTypes.Add("Sweep", WallSweepType.Sweep); wallSweepTypes.Add("Reveal", WallSweepType.Reveal); var wallSweepTypeId = TypeElement.InternalElement.Id; WallSweepInfo wallSweepInfo = new WallSweepInfo(wallSweepTypes[SweepOrReveal], IsVertical); wallSweepInfo.Distance = Offset / 304.8; TransactionManager.Instance.EnsureInTransaction(doc); foreach (var w in Walls) { var wall = w.InternalElement as Autodesk.Revit.DB.Wall; WallSweep wallSweep = WallSweep.Create(wall, wallSweepTypeId, wallSweepInfo); WallSweeps.Add(wallSweep.ToDSType(true)); } TransactionManager.Instance.TransactionTaskDone(); return(WallSweeps); }
/// <summary> /// Setting the WallSweepInfo for sweep and reveal. /// </summary> /// <param name="wallSweepInfo">The WallSweepInfo.</param> /// <param name="distance">The distance from either the top or base of the wall</param> private void PrepareWallSweepInfo(WallSweepInfo wallSweepInfo, double distance) { wallSweepInfo.DistanceMeasuredFrom = DistanceMeasuredFrom.Base; wallSweepInfo.Distance = distance; wallSweepInfo.WallSide = WallSide.Exterior; wallSweepInfo.Id = -1; wallSweepInfo.WallOffset = -0.1; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Selection selection = uidoc.Selection; View acview = uidoc.ActiveView; try { Reference reff = selection.PickObject(ObjectType.Element, new MySelectionFilter <Room>(), "select a room"); Room room = doc.GetElement(reff) as Room; ElementType wallSweepType = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Cornices).WhereElementIsElementType().Cast <ElementType>().FirstOrDefault(); if (wallSweepType != null) { using (Transaction ts = new Transaction(doc, "创建踢脚线")) { ts.Start(); ElementType type = wallSweepType.Duplicate("踢脚线2"); SpatialElementBoundaryOptions opts = new SpatialElementBoundaryOptions(); opts.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish; IList <IList <Autodesk.Revit.DB.BoundarySegment> > boundList = room.GetBoundarySegments(opts); foreach (IList <BoundarySegment> bs in boundList) { foreach (BoundarySegment bs1 in bs) { Wall wall = doc.GetElement(bs1.ElementId) as Wall; if (wall != null) { WallSweepInfo info = new WallSweepInfo(WallSweepType.Sweep, false); // 墙的正反或者里面 info.WallSide = WallSide.Exterior; // 距离墙底的高度 info.Distance = 10 / 304.8; // 偏移距离 info.WallOffset = 0; WallSweep.Create(wall, type.Id, info); } } } ts.Commit(); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } return(Result.Succeeded); }
/// <summary> /// Creates wall's belt. /// </summary> /// <param name="wallTypeId"></param> /// <param name="sweep"></param> /// <param name="doc"></param> public static void CreateWallBelt(this Document doc, ElementId wallTypeId, BeltData sweep) { if (doc is null) { return; } if (wallTypeId is null) { return; } if (sweep is null) { return; } if (doc.GetElement(wallTypeId) is WallType wallType) { var cs = wallType.GetCompoundStructure(); var sweepInfo = new WallSweepInfo(true, WallSweepType.Sweep) { Id = sweep.Index + 1 }; if (sweep.MaterialId != null) { sweepInfo.MaterialId = sweep.MaterialId; } if (sweep.ProfileId != null) { sweepInfo.ProfileId = sweep.ProfileId; } sweepInfo.Distance = sweep.Offset; sweepInfo.IsProfileFlipped = sweep.Flip; cs.AddWallSweep(sweepInfo); wallType.SetCompoundStructure(cs); } }
/// <summary> /// Exports a wall swepp. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="wallSweep">The WallSweep.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, WallSweep wallSweep, GeometryElement geometryElement, ProductWrapper productWrapper) { WallSweepInfo wallSweepInfo = wallSweep.GetWallSweepInfo(); //Reveals are exported as openings with wall exporter. if (wallSweepInfo.WallSweepType == WallSweepType.Reveal) { return; } if (!ProxyElementExporter.Export(exporterIFC, wallSweep, geometryElement, productWrapper)) { return; } HostObjectExporter.ExportHostObjectMaterials(exporterIFC, wallSweep, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis2, null); }
/// <summary> /// Create vertical CompoundStructure for wall: new layers, split new region, new sweep and new reveal. /// </summary> /// <param name="wall">The wall applying the new CompoundStructure.</param> public void CreateCSforWall(Wall wall) { // Get CompoundStructure WallType wallType = wall.WallType; //wallType.Name = wallType.Name + "_WithNewCompoundStructure"; CompoundStructure wallCS = wallType.GetCompoundStructure(); // Get material for CompoundStructureLayer Material masonry_Brick = CreateSampleBrickMaterial(); Material concrete = CreateSampleConcreteMaterial(); // Create CompoundStructureLayers and add the materials created above to them. List <CompoundStructureLayer> csLayers = new List <CompoundStructureLayer>(); CompoundStructureLayer finish1Layer = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish1, masonry_Brick.Id); CompoundStructureLayer substrateLayer = new CompoundStructureLayer(0.1, MaterialFunctionAssignment.Substrate, ElementId.InvalidElementId); CompoundStructureLayer structureLayer = new CompoundStructureLayer(0.5, MaterialFunctionAssignment.Structure, concrete.Id); CompoundStructureLayer membraneLayer = new CompoundStructureLayer(0, MaterialFunctionAssignment.Membrane, ElementId.InvalidElementId); CompoundStructureLayer finish2Layer = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish2, concrete.Id); csLayers.Add(finish1Layer); csLayers.Add(substrateLayer); csLayers.Add(structureLayer); csLayers.Add(membraneLayer); csLayers.Add(finish2Layer); // Set the created layers to CompoundStructureLayer wallCS.SetLayers(csLayers); //Set which layer is used for structural analysis wallCS.StructuralMaterialIndex = 2; // Set shell layers and wrapping. wallCS.SetNumberOfShellLayers(ShellLayerType.Interior, 2); wallCS.SetNumberOfShellLayers(ShellLayerType.Exterior, 1); wallCS.SetParticipatesInWrapping(0, false); // Points for adding wall sweep and reveal. UV sweepPoint = UV.Zero; UV revealPoint = UV.Zero; // split the region containing segment 0. int segId = wallCS.GetSegmentIds()[0]; foreach (int regionId in wallCS.GetAdjacentRegions(segId)) { // Get the end points of segment 0. UV endPoint1 = UV.Zero; UV endPoint2 = UV.Zero; wallCS.GetSegmentEndPoints(segId, regionId, out endPoint1, out endPoint2); // Split a new region in split point and orientation. RectangularGridSegmentOrientation splitOrientation = (RectangularGridSegmentOrientation)(((int)(wallCS.GetSegmentOrientation(segId)) + 1) % 2); UV splitUV = (endPoint1 + endPoint2) / 2.0; int newRegionId = wallCS.SplitRegion(splitUV, splitOrientation); bool isValidRegionId = wallCS.IsValidRegionId(newRegionId); // Find the enclosing region and the two segments intersected by a line through the split point int segId1; int segId2; int findRegionId = wallCS.FindEnclosingRegionAndSegments(splitUV, splitOrientation, out segId1, out segId2); // Get the end points of finding segment 1 and compute the wall sweep point. UV eP1 = UV.Zero; UV eP2 = UV.Zero; wallCS.GetSegmentEndPoints(segId1, findRegionId, out eP1, out eP2); sweepPoint = (eP1 + eP2) / 4.0; // Get the end points of finding segment 2 and compute the wall reveal point. UV ep3 = UV.Zero; UV ep4 = UV.Zero; wallCS.GetSegmentEndPoints(segId2, findRegionId, out ep3, out ep4); revealPoint = (ep3 + ep4) / 2.0; } // Create a WallSweepInfo for wall sweep WallSweepInfo sweepInfo = new WallSweepInfo(true, WallSweepType.Sweep); PrepareWallSweepInfo(sweepInfo, sweepPoint.V); // Set sweep profile: Sill-Precast : 8" Wide sweepInfo.ProfileId = GetProfile("8\" Wide").Id; sweepInfo.Id = 101; wallCS.AddWallSweep(sweepInfo); // Create a WallSweepInfo for wall reveal WallSweepInfo revealInfo = new WallSweepInfo(true, WallSweepType.Reveal); PrepareWallSweepInfo(revealInfo, revealPoint.U); revealInfo.Id = 102; wallCS.AddWallSweep(revealInfo); // Set the new wall CompoundStructure to the type of wall. wallType.SetCompoundStructure(wallCS); }
/// <summary> /// Create vertical CompoundStructure for wall: new layers, split new region, new sweep and new reveal. /// </summary> /// <param name="wall">The wall applying the new CompoundStructure.</param> public void CreateCSforWall(Wall wall) { // Get CompoundStructure CompoundStructure wallCS = wall.WallType.GetCompoundStructure(); // Get material for CompoundStructureLayer Material masonry_Brick = GetMaterial("Masonry - Brick"); Material concrete = GetMaterial("Concrete"); // Create CompoundStructureLayers List<CompoundStructureLayer> csLayers = new List<CompoundStructureLayer>(); CompoundStructureLayer finish1Layer = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish1, masonry_Brick.Id); CompoundStructureLayer substrateLayer = new CompoundStructureLayer(0.1, MaterialFunctionAssignment.Substrate, ElementId.InvalidElementId); CompoundStructureLayer structureLayer = new CompoundStructureLayer(0.5, MaterialFunctionAssignment.Structure, concrete.Id); CompoundStructureLayer membraneLayer = new CompoundStructureLayer(0, MaterialFunctionAssignment.Membrane, ElementId.InvalidElementId); CompoundStructureLayer finish2Layer = new CompoundStructureLayer(0.2, MaterialFunctionAssignment.Finish2, masonry_Brick.Id); csLayers.Add(finish1Layer); csLayers.Add(substrateLayer); csLayers.Add(structureLayer); csLayers.Add(membraneLayer); csLayers.Add(finish2Layer); // Set the created layers to CompoundStructureLayer wallCS.SetLayers(csLayers); // Set shell layers and wrapping. wallCS.SetNumberOfShellLayers(ShellLayerType.Interior, 2); wallCS.SetNumberOfShellLayers(ShellLayerType.Exterior, 1); wallCS.SetParticipatesInWrapping(0, false); // Points for adding wall sweep and reveal. UV sweepPoint = UV.Zero; UV revealPoint = UV.Zero; // split the region containing segment 0. int segId = wallCS.GetSegmentIds()[0]; foreach (int regionId in wallCS.GetAdjacentRegions(segId)) { // Get the end points of segment 0. UV endPoint1 = UV.Zero; UV endPoint2 = UV.Zero; wallCS.GetSegmentEndPoints(segId, regionId, out endPoint1, out endPoint2); // Split a new region in splited point and orientation. RectangularGridSegmentOrientation splitOrientation = (RectangularGridSegmentOrientation)(((int)(wallCS.GetSegmentOrientation(segId)) + 1) % 2); UV splitUV = (endPoint1 + endPoint2) / 2.0; int newRegionId = wallCS.SplitRegion(splitUV, splitOrientation); bool isValidRegionId = wallCS.IsValidRegionId(newRegionId); // Find the enclosing region and the two segments intersected by a line through the split point int segId1; int segId2; int findRegionId = wallCS.FindEnclosingRegionAndSegments(splitUV, splitOrientation, out segId1, out segId2); // Get the end points of finding segment 1 and compute the wall sweep point. UV eP1 = UV.Zero; UV eP2 = UV.Zero; wallCS.GetSegmentEndPoints(segId1, findRegionId, out eP1, out eP2); sweepPoint = (eP1 + eP2) / 4.0; // Get the end points of finding segment 2 and compute the wall reveal point. UV ep3 = UV.Zero; UV ep4 = UV.Zero; wallCS.GetSegmentEndPoints(segId2, findRegionId, out ep3, out ep4); revealPoint = (ep3 + ep4) / 2.0; } // Create a WallSweepInfo for wall sweep WallSweepInfo sweepInfo = new WallSweepInfo(true, WallSweepType.Sweep); PrepareWallSweepInfo(sweepInfo, sweepPoint.V); // Set sweep profile: Sill-Precast : 8" Wide sweepInfo.ProfileId = GetProfile("8\" Wide").Id; sweepInfo.Id = 101; wallCS.AddWallSweep(sweepInfo); // Create a WallSweepInfo for wall reveal WallSweepInfo revealInfo = new WallSweepInfo(true, WallSweepType.Reveal); PrepareWallSweepInfo(revealInfo, revealPoint.U); revealInfo.Id = 102; wallCS.AddWallSweep(revealInfo); // Set the new wall CompoundStructure to the type of wall. wall.WallType.SetCompoundStructure(wallCS); }
/// <summary> /// Setting the WallSweepInfo for sweep and reveal. /// </summary> /// <param name="wallSweepInfo">The WallSweepInfo.</param> /// <param name="distance">The distance from either the top or base of the wall</param> private void PrepareWallSweepInfo(WallSweepInfo wallSweepInfo, double distance) { wallSweepInfo.DistanceMeasuredFrom = DistanceMeasuredFrom.Base; wallSweepInfo.Distance = distance; wallSweepInfo.WallSide = WallSide.Exterior; wallSweepInfo.Id = -1; wallSweepInfo.WallOffset = -0.1; }
public Result setup_wall_struct(Document doc) { WallType wallType = null; // FIXME : replace with the material approach? FilteredElementCollector wallTypes = new FilteredElementCollector(doc) .OfClass(typeof(WallType)); foreach (WallType wt in wallTypes) { if (wt.Name.Equals("Generic - 8\"")) { wallType = wt; break; } } Material concrete = new FilteredElementCollector(doc) .OfClass(typeof(Material)) .Cast <Material>().FirstOrDefault(q => q.Name == "Concrete, Cast-in-Place gray"); Material insulation = new FilteredElementCollector(doc) .OfClass(typeof(Material)) .Cast <Material>().FirstOrDefault(q => q.Name == "EIFS, Exterior Insulation"); Material lumber = new FilteredElementCollector(doc) .OfClass(typeof(Material)) .Cast <Material>().FirstOrDefault(q => q.Name == "Softwood, Lumber"); Material gypsum = new FilteredElementCollector(doc) .OfClass(typeof(Material)) .Cast <Material>().FirstOrDefault(q => q.Name == "Gypsum Wall Board"); WallType newWallType = null; using (Transaction tx = new Transaction(doc)) { tx.Start("Basement exterior wall"); newWallType = wallType.Duplicate("Basement") as WallType; // FIXME : this layer should have the "structural material" parameter set CompoundStructureLayer l1 = new CompoundStructureLayer(8.0 / 12, MaterialFunctionAssignment.Structure, concrete.Id); CompoundStructureLayer newLayer = new CompoundStructureLayer(3.0 / 12, MaterialFunctionAssignment.Insulation, insulation.Id); CompoundStructureLayer newLayer2 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Finish1, lumber.Id); CompoundStructureLayer newLayer3 = new CompoundStructureLayer(.5 / 12, MaterialFunctionAssignment.Finish2, gypsum.Id); CompoundStructure structure = newWallType.GetCompoundStructure(); IList <CompoundStructureLayer> layers = structure.GetLayers(); layers.Add(l1); layers.Add(newLayer); layers.Add(newLayer2); layers.Add(newLayer3); structure.SetLayers(layers); structure.DeleteLayer(0); structure.SetNumberOfShellLayers(ShellLayerType.Interior, 3); newWallType.SetCompoundStructure(structure); tx.Commit(); } using (Transaction tx = new Transaction(doc)) { tx.Start("2x4 + Gypsum wall"); newWallType = wallType.Duplicate("2x4 + Gypsum") as WallType; CompoundStructureLayer l1 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Structure, lumber.Id); CompoundStructureLayer l2 = new CompoundStructureLayer(0.5 / 12, MaterialFunctionAssignment.Finish1, gypsum.Id); CompoundStructure structure = newWallType.GetCompoundStructure(); IList <CompoundStructureLayer> layers = structure.GetLayers(); layers.Add(l2); layers.Add(l1); layers.Add(l2); structure.SetLayers(layers); structure.DeleteLayer(0); structure.SetNumberOfShellLayers(ShellLayerType.Exterior, 1); structure.SetNumberOfShellLayers(ShellLayerType.Interior, 1); newWallType.SetCompoundStructure(structure); tx.Commit(); } using (Transaction tx = new Transaction(doc)) { tx.Start("2x4 + Gypsum wall with Exterior"); newWallType = wallType.Duplicate("2x4 + Gypsum wall with Exterior") as WallType; CompoundStructureLayer l1 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Structure, lumber.Id); CompoundStructureLayer l2 = new CompoundStructureLayer(0.5 / 12, MaterialFunctionAssignment.Finish1, gypsum.Id); CompoundStructure structure = newWallType.GetCompoundStructure(); IList <CompoundStructureLayer> layers = structure.GetLayers(); layers.Add(l2); layers.Add(l1); layers.Add(l2); structure.SetLayers(layers); structure.DeleteLayer(0); structure.SetNumberOfShellLayers(ShellLayerType.Exterior, 1); structure.SetNumberOfShellLayers(ShellLayerType.Interior, 1); ElementType wallSweepType = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_Cornices) .WhereElementIsElementType() .Cast <ElementType>().FirstOrDefault(); if (wallSweepType != null) { var wallSweepInfo = new WallSweepInfo(WallSweepType.Sweep, false); wallSweepInfo.Distance = 2; List <WallSweepInfo> ModSW = new List <WallSweepInfo>(); // structure.AddWallSweep(wallSweepInfo); } newWallType.SetCompoundStructure(structure); tx.Commit(); } return(Result.Succeeded); }