public WallType CreateNewWallType(Document doc, Wall wall) { WallType wallType = wall.WallType; WallType NewWallType = null; Transaction t = new Transaction(doc, "Duplicate wall"); t.Start(); try { NewWallType = wallType.Duplicate("SW48") as WallType; CompoundStructure compoundStructure = NewWallType.GetCompoundStructure(); int layerIndex = compoundStructure.GetFirstCoreLayerIndex(); IList <CompoundStructureLayer> csLayers = compoundStructure.GetLayers(); foreach (CompoundStructureLayer csl in csLayers) { if (csl.Function.ToString() == "Structure") { compoundStructure.SetLayerWidth(layerIndex, 48 / 12); } layerIndex++; } NewWallType.SetCompoundStructure(compoundStructure); } catch {} t.Commit(); return(NewWallType); }
public WallType CreateWallType(Document document, WallType _wallType, double wallTypeThickness) { WallType wallType = null; try { wallType = _wallType.Duplicate($"Wall {Convert.ToInt32((wallTypeThickness )).ToString() }mm") as WallType; CompoundStructure compoundStructure = wallType.GetCompoundStructure(); int layerIndex = compoundStructure.GetFirstCoreLayerIndex(); IList <CompoundStructureLayer> clayers = compoundStructure.GetLayers(); foreach (CompoundStructureLayer csl in clayers) { if (csl.Function.ToString() == "Structure") { compoundStructure.SetLayerWidth(layerIndex, wallTypeThickness * _mm_to_feet); } layerIndex++; } wallType.SetCompoundStructure(compoundStructure); } catch { } return(wallType); }
public void CreateWalls (Document doc, HouseObject house, List <WallType> autoTypes, Level baseLevel) { foreach (A_Floor floor in house.Floors) { ///Create the walls. foreach (A_Wall wa in floor.Walls) { WallType currentWt = null; XYZ p1 = new XYZ(wa.P1.X, wa.P1.Y, 0); XYZ p2 = new XYZ(wa.P2.X, wa.P2.Y, 0); Curve c = Line.CreateBound(p1, p2); ///Find the right wall type. ///If the type doesnt exist,create a new one. try { currentWt = autoTypes .First(at => at.Width - wa.Thickness < 0.0001); } catch { ///Duplicate a new walltype; float wallWidthMm = Helper.Feet2Mm(wa.Thickness); currentWt = AutoWallTypes[0].Duplicate ("AutoWall-" + wallWidthMm) as WallType; ///Set the width of the new type; CompoundStructure cStru = CompoundStructure .CreateSingleLayerCompoundStructure (MaterialFunctionAssignment.Structure, wa.Thickness, currentWt.GetCompoundStructure().GetMaterialId(0)); currentWt.SetCompoundStructure(cStru); ///Add it to collection. AutoWallTypes.Add(currentWt); } ///Create the individual wall wa.Wall = Wall.Create(doc, c, currentWt.Id, baseLevel.Id, floor.Height, 0, false, true); ActiveForm.UpdateProgress(wallWorkLoad); } ///Create the floor. CurveArray floorCrv = new CurveArray(); foreach (A_Room outer in floor.Outers) { foreach (A_Contour con in outer.Meta.Contours) { floorCrv.Append(Line.CreateBound (new XYZ(con.P1.X, con.P1.Y, baseLevel.Elevation), new XYZ(con.P2.X, con.P2.Y, baseLevel.Elevation))); } doc.Create.NewFloor(floorCrv, false); } } }
public void CreateBaseWallType() { ///Create the default material. ElementId baseMaterialid = null; Material baseMaterial = null; Color colorGrey = new Color(80, 80, 80); ///First check if the material already exist. Material existMa = new FilteredElementCollector(ActiveDoc) .OfClass(typeof(Material)) .Select(e => e as Material).ToList() .Where(m => m.Name == "AutoWallMaterial") .FirstOrDefault(); baseMaterialid = (existMa != null) ? existMa.Id : Material.Create(ActiveDoc, "AutoWallMaterial"); baseMaterial = ActiveDoc.GetElement(baseMaterialid) as Material; ///Set the material color. baseMaterial.SurfaceForegroundPatternColor = colorGrey; baseMaterial.SurfaceBackgroundPatternColor = colorGrey; baseMaterial.Color = colorGrey; ///Create the default wall type. ///First check if it exist. WallType existWt = new FilteredElementCollector(ActiveDoc) .WhereElementIsElementType() .OfCategory(BuiltInCategory.OST_Walls) .Select(e => e as WallType) .Where(w => w.Name == "AutoWall-240") .ToList().FirstOrDefault(); ///If not exist,create a new one. WallType baseWt = (existWt != null) ? existWt : new FilteredElementCollector(ActiveDoc) .WhereElementIsElementType() .OfCategory(BuiltInCategory.OST_Walls) .Select(e => e as WallType) .Where(w => w.Kind == WallKind.Basic) .FirstOrDefault() .Duplicate("AutoWall-240") as WallType; ///Set the structure. baseWt.SetCompoundStructure( CompoundStructure.CreateSingleLayerCompoundStructure (MaterialFunctionAssignment.Structure, UnitUtils.ConvertToInternalUnits(240, DisplayUnitType.DUT_MILLIMETERS), baseMaterialid) ); ///Create the wallType list and add the base type. AutoWallTypes = new List <WallType> { baseWt }; }
/// <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); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; #if _2011 // // code for the Revit 2011 API: // Debug.Assert(false, "Currently, no new wall layer can be created, because" + "there is no creation method available for it."); foreach (WallType wallType in doc.WallTypes) { if (0 < wallType.CompoundStructure.Layers.Size) { CompoundStructureLayer oldLayer = wallType.CompoundStructure.Layers.get_Item(0); WallType newWallType = wallType.Duplicate("NewWallType") as WallType; CompoundStructure structure = newWallType.CompoundStructure; CompoundStructureLayerArray layers = structure.Layers; // from here on, nothing works, as expected: // in the Revir 2010 API, we could call the constructor // even though it is for internal use only. // in 2011, it is not possible to call it either. CompoundStructureLayer newLayer = null; // = new CompoundStructureLayer(); // for internal use only newLayer.DeckProfile = oldLayer.DeckProfile; //newLayer.DeckUsage = oldLayer.DeckUsage; // read-only //newLayer.Function = oldLayer.Function; // read-only newLayer.Material = oldLayer.Material; newLayer.Thickness = oldLayer.Thickness; newLayer.Variable = oldLayer.Variable; layers.Append(newLayer); } } #endif // _2011 //WallTypeSet wallTypes = doc.WallTypes; // 2013 FilteredElementCollector wallTypes = new FilteredElementCollector(doc) .OfClass(typeof(WallType)); // 2014 foreach (WallType wallType in wallTypes) { if (0 < wallType.GetCompoundStructure().GetLayers().Count) { CompoundStructureLayer oldLayer = wallType.GetCompoundStructure().GetLayers()[0]; WallType newWallType = wallType.Duplicate("NewWallType") as WallType; CompoundStructure structure = newWallType.GetCompoundStructure(); IList <CompoundStructureLayer> layers = structure.GetLayers(); // in Revit 2012, we can create a new layer: double width = 0.1; MaterialFunctionAssignment function = oldLayer.Function; ElementId materialId = oldLayer.MaterialId; CompoundStructureLayer newLayer = new CompoundStructureLayer(width, function, materialId); layers.Add(newLayer); structure.SetLayers(layers); newWallType.SetCompoundStructure(structure); } } return(Result.Succeeded); }
public void createWall() { try { //Wall.Create(Document document, Curve curve, ElementId wallTypeId, ElementId levelId, double wallHeight, double wallOffset, bool flip, bool structural) WallType yeniWallType = null; bool bulundu = false; FilteredElementCollector wallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType)); ElementId defaultElementTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.WallType); #region Informatik isimli duvar tipini ara, yoksa yarat foreach (WallType wt in wallTypes) { if (wt.Name == "Informatik") { informatikWallId = wt.Id; bulundu = true; break; } } if (bulundu == false) { foreach (WallType wt in wallTypes) { if (wt.Id == defaultElementTypeId) { using (Transaction transaction = new Transaction(doc, "DuplicateWallType")) { transaction.Start(); yeniWallType = wt.Duplicate("Informatik") as WallType; CompoundStructure cs = yeniWallType.GetCompoundStructure(); ElementId materialId = new ElementId(539); IList <CompoundStructureLayer> cslList = new List <CompoundStructureLayer>(); CompoundStructureLayer csl = new CompoundStructureLayer(20 * mmToFeet, MaterialFunctionAssignment.Finish1, materialId); cslList.Add(csl); csl = new CompoundStructureLayer(160 * mmToFeet, MaterialFunctionAssignment.Structure, materialId); cslList.Add(csl); csl = new CompoundStructureLayer(20 * mmToFeet, MaterialFunctionAssignment.Finish2, materialId); cslList.Add(csl); CompoundStructure yeniStructure = CompoundStructure.CreateSimpleCompoundStructure(cslList); yeniWallType.SetCompoundStructure(yeniStructure); doc.SetDefaultElementTypeId(ElementTypeGroup.WallType, yeniWallType.Id); transaction.Commit(); informatikWallId = yeniWallType.Id; } break; } } } #endregion #region levelId bul List <Level> levels = new List <Level>(); FilteredElementCollector filteredLevelCollector = new FilteredElementCollector(doc); filteredLevelCollector.OfClass(typeof(Level)); levels = filteredLevelCollector.Cast <Level>().ToList(); ElementId levelId = null; foreach (Level l in levels) { if (l.Name == "Level 0") { levelId = l.Id; break; } } #endregion #region cizgileri seçtirt uiApp.ActiveUIDocument.Selection.GetElementIds().Clear(); ISelectionFilter selFilter = new ModelLineSelectionFilter(); this.Hide(); IList <Reference> curves = uiApp.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, selFilter, "Select path Curve(s) for partition wall"); this.Show(); #endregion #region set computing options Options opt = new Options(); opt.ComputeReferences = true; opt.IncludeNonVisibleObjects = true; opt.View = doc.ActiveView; #endregion #region duvar yüksekliği ve offsetini belirle double wallHeight = 3000 * mmToFeet; double wallOffset = 0; #endregion List <Wall> yeniDuvarlar = new List <Wall>(); if (curves.Count > 0) { #region döngü for (int i = 0; i < curves.Count; i++) { XYZ globalPoint; Wall yeniDuvar = null; globalPoint = curves[i].GlobalPoint; Element tempCurve = doc.GetElement(curves[i]) as Element; Curve curve = null; if (tempCurve != null) { #region element geometrisinden Curve bulunabiliyor mu foreach (var geoObj in tempCurve.get_Geometry(opt)) { Curve cv = geoObj as Curve; if (cv != null) { curve = cv; break; } } #endregion #region duvar üret if (curve != null) { using (Transaction wallCreate = new Transaction(doc, "Duvar Yarat")) { wallCreate.Start(); yeniDuvar = Wall.Create(doc, curve, informatikWallId, levelId, wallHeight, wallOffset, false, false); if (yeniDuvar != null) { yeniDuvarlar.Add(yeniDuvar); } wallCreate.Commit(); } } #endregion } } #endregion //BuiltInParameter myParameter = BuiltInParameter.DIVIDED_SURFACE_DISPLAY_ORIGINAL_SURFACE; //Element myElement = yeniDuvar as Element; //myElement.get_Parameter(myParameter).Set(); #region parametreleri kontrol et if (yeniDuvarlar.Count > 0) { Wall yeniDuvar = yeniDuvarlar[0]; string s = string.Empty; foreach (Parameter p in yeniDuvar.Parameters) { s += "Name=" + p.Definition.Name + " StorageType=" + p.StorageType.ToString() + "\r\n"; } MessageBox.Show(s); } #endregion } if (curves.Count < 1) { TaskDialog.Show("Seçilmedi", "En az bir çizgi seçmelisiniz"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
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); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = commandData.Application.ActiveUIDocument.Document; View view = uidoc.ActiveView; ElementId levelid = view.GenLevel.Id; bool iscontinue = true; do { List <Element> eles = new List <Element>(); try { eles = GetSelected(uidoc); } catch { iscontinue = false; continue; } if (eles == null) { TaskDialog.Show("wrong", "选择的符号线的数量不为2."); continue; } //get line_closer & line_farther Line line1 = (eles[0] as DetailLine).GeometryCurve as Line; Line line2 = (eles[1] as DetailLine).GeometryCurve as Line; if (line1 == null || line2 == null) { TaskDialog.Show("wrong", "仅支持直线."); continue; } Line line1unbound = (eles[0] as DetailLine).GeometryCurve as Line; line1unbound.MakeUnbound(); Line line2unbound = (eles[1] as DetailLine).GeometryCurve as Line; line2unbound.MakeUnbound(); //get distance from origin IntersectionResult result1 = line1unbound.Project(new XYZ(-1000 / 304.8, -1000 / 304.8, line1.GetEndPoint(0).Z)); double distance1 = result1.Distance; IntersectionResult result2 = line2unbound.Project(new XYZ(-1000 / 304.8, -1000 / 304.8, line2.GetEndPoint(0).Z)); double distance2 = result2.Distance; if (IsAlmostEqual(distance1, distance2)) { TaskDialog.Show("wrong", "两条线间距太小."); continue; } Line line_closer = null; Line line_farther = null; Line line_closer_unbound = null; Line line_farther_unbound = null; if (distance1 > distance2) { line_closer = line2; line_farther = line1; line_closer_unbound = line2unbound; line_farther_unbound = line1unbound; } else { line_closer = line1; line_farther = line2; line_closer_unbound = line1unbound; line_farther_unbound = line2unbound; } //Determine parallel XYZ dir1 = line_closer.Direction; XYZ dir2 = line_farther.Direction; bool isparallel = dir1.IsAlmostEqualTo(dir2) || dir1.IsAlmostEqualTo(-dir2); if (!isparallel) { TaskDialog.Show("wrong", "请选择平行的线."); continue; } //get points //makeunbound XYZ startpoint_closerline = line_closer.GetEndPoint(0); XYZ endpoint_closerline = line_closer.GetEndPoint(1); XYZ startpoint_fartherline = line_farther.GetEndPoint(0); XYZ endpoint_fartherline = line_farther.GetEndPoint(1); //get width of wall IntersectionResult intersection = line_closer_unbound.Project(startpoint_fartherline); double distance = intersection.Distance; XYZ point_intersection = intersection.XYZPoint; Line normalline = Line.CreateBound(point_intersection, startpoint_fartherline); XYZ normallinedir = normalline.Direction; //offset Line wallline = null; if (line_closer.Length > line_farther.Length) { wallline = OffsetLine(line_closer, normallinedir, distance / 2); } else { wallline = OffsetLine(line_farther, -normallinedir, distance / 2); } //get material FilteredElementCollector materialcollector = new FilteredElementCollector(doc); materialcollector.OfCategory(BuiltInCategory.OST_Materials).OfClass(typeof(Material)); IEnumerable <Material> materials = from ele in materialcollector let material = ele as Material where material.Name == "BRIK" select material; if (materials.Count() == 0) { TaskDialog.Show("wrong", "未找到BRIK材质"); continue; } ElementId materialid = materials.First().Id; //get walltype FilteredElementCollector walltypecollector = new FilteredElementCollector(doc); walltypecollector.OfClass(typeof(WallType)).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType(); IEnumerable <WallType> walltypes = from element in walltypecollector let walltypetemp = element as WallType let para = walltypetemp.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM) where walltypetemp.Name.Contains("A-WALL-INTR") where walltypetemp.Kind == WallKind.Basic // where para.AsDouble() == distance where IsAlmostEqual(para.AsDouble(), distance) select walltypetemp; if (walltypecollector.Count() == 0) { TaskDialog.Show("wrong", "请先随意新建一个类型."); continue; } WallType typetemp = null; foreach (WallType type in walltypecollector) { if (type.Kind == WallKind.Basic) { typetemp = type; break; } } if (typetemp == null) { TaskDialog.Show("wrong", "请先随意新建一个内墙类型."); continue; } WallType walltype = null; if (walltypes.Count() == 0) { TaskDialog.Show("wrong", "未找到合适的类型,将新建一个类型"); using (Transaction createwalltype = new Transaction(doc)) { createwalltype.Start("新建墙类型"); walltype = typetemp.Duplicate("A-WALL-INTR-" + Convert.ToInt32((distance * 304.8)).ToString()) as WallType; CompoundStructure compoundstructure = CompoundStructure.CreateSingleLayerCompoundStructure(MaterialFunctionAssignment.Structure, distance, materialid); walltype.SetCompoundStructure(compoundstructure); createwalltype.Commit(); } } else { walltype = walltypes.First(); } //transaction using (Transaction transaction = new Transaction(doc)) { transaction.Start("生成墙"); Wall wall = Wall.Create(doc, wallline, walltype.Id, levelid, 10, 0, false, false); transaction.Commit(); } }while (iscontinue); return(Result.Succeeded); }
//---------------------------------------------------------- public string Duplicate_Type(UIApplication uiapp, Document doc) { string result = "F"; try { type_data item_type = (type_data)type.SelectedItem; material_data item_material = (material_data)material.SelectedItem; CultureInfo culture = CultureInfo.CreateSpecificCulture("eu-ES"); string specifier = "G"; if (item_type.type.Category.Name == myAll_Data.list_category_draw[3]) { WallType wall_Type = item_type.type.Duplicate("STB " + b.Text + " " + item_material.single_value) as WallType; CompoundStructure compound_new = wall_Type.GetCompoundStructure(); IList <CompoundStructureLayer> cslayers = compound_new.GetLayers(); for (int i = 0; i < cslayers.Count; i++) { compound_new.SetLayerWidth(cslayers[i].LayerId, Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]); compound_new.SetMaterialId(cslayers[i].LayerId, item_material.material.Id); } wall_Type.SetCompoundStructure(compound_new); my_type_data.Add(new type_data() { type = wall_Type, single_value = wall_Type.Name }); type.Items.Refresh(); type.SelectedItem = my_type_data.First(x => x.single_value == wall_Type.Name); double width = Math.Round(wall_Type.Width * myAll_Data.list_unit_value_data[6], 3); wall_Type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("h = " + width.ToString(specifier, culture) + " cm"); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[4]) { ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value); new_type.LookupParameter(myAll_Data.list_parameter_column[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]); new_type.LookupParameter(myAll_Data.list_parameter_column[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]); my_type_data.Add(new type_data() { type = new_type, single_value = new_type.Name }); type.Items.Refresh(); type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name); double width = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3); double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_column[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3); new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm"); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5]) { ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text + " " + item_material.single_value); new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]); new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]); my_type_data.Add(new type_data() { type = new_type, single_value = new_type.Name }); type.Items.Refresh(); type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name); double width = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[0]).AsDouble() * myAll_Data.list_unit_value_data[6], 3); double height = Math.Round(new_type.LookupParameter(myAll_Data.list_parameter_framing[1]).AsDouble() * myAll_Data.list_unit_value_data[6], 3); new_type.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS).Set("b/h = " + width.ToString(specifier, culture) + "/" + height.ToString(specifier, culture) + " cm"); } else if (item_type.type.Category.Name == myAll_Data.list_category_draw[1] || item_type.type.Category.Name == myAll_Data.list_category_draw[2]) { ElementType new_type = item_type.type.Duplicate(b.Text + "/" + h.Text); new_type.get_Parameter(BuiltInParameter.FAMILY_WIDTH_PARAM).Set(Convert.ToDouble(b.Text) / myAll_Data.list_unit_value_data[2]); new_type.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).Set(Convert.ToDouble(h.Text) / myAll_Data.list_unit_value_data[2]); my_type_data.Add(new type_data() { type = new_type, single_value = new_type.Name }); type.Items.Refresh(); type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name); Update_UK_MA(); } else { ElementType new_type = item_type.type.Duplicate(item_type.type.Name + " " + b.Text); my_type_data.Add(new type_data() { type = new_type, single_value = new_type.Name }); type.Items.Refresh(); type.SelectedItem = my_type_data.First(x => x.single_value == new_type.Name); Update_UK_MA(); } result = "S"; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }