static Material GetMaterial(Document doc, Floor floor) { FloorType aFloorType = floor.FloorType; if (!aFloorType.IsFoundationSlab) { CompoundStructure comStruct = aFloorType.GetCompoundStructure(); Categories allCategories = doc.Settings.Categories; Category floorCategory = allCategories.get_Item(BuiltInCategory.OST_Floors); Material floorMat = floorCategory.Material; foreach (var structLayer in comStruct.GetLayers()) { var layerMat = ElementFilterUtils.GetElement(doc, structLayer.MaterialId) as Material; if (layerMat == null) { switch (structLayer.Function) { case MaterialFunctionAssignment.Structure: layerMat = allCategories.get_Item(BuiltInCategory.OST_FloorsStructure).Material; break; } } if (layerMat != null) { floorMat = layerMat; break; } } return(floorMat); } return(null); }
public FloorType GetFloorType(Document doc, FloorSlab floor) { FloorType f = new FilteredElementCollector(doc).OfClass(typeof(FloorType)) .Where(ft => ft is FloorType) .FirstOrDefault(e => { CompoundStructure comp = (e as FloorType).GetCompoundStructure(); if (comp.GetLayerWidth(0) == Util.MmToFoot(floor.Depth)) { return true; } return false; }) as FloorType; if (f != null) return f; f = new FilteredElementCollector(doc).OfClass(typeof(FloorType)).FirstOrDefault(e => e.Name == "Generic - 12\"") as FloorType; f = f.Duplicate(String.Format("Floor {0} CM", floor.Depth / 10)) as FloorType; CompoundStructure compound = f.GetCompoundStructure(); compound.SetLayerWidth(0, Util.MmToFoot(floor.Depth)); f.SetCompoundStructure(compound); return f; }
/// <summary> /// 获取 CompoundStructure 对象 /// </summary> /// <param name="element"></param> /// <returns></returns> public static CompoundStructure GetCompoundStructure(this CSAModel model, Element element) { CompoundStructure compoundStructure = null; if (element is Wall) { compoundStructure = (element as Wall).WallType.GetCompoundStructure(); model.TargetType = TargetType.Wall; } else if (element is Floor) { compoundStructure = (element as Floor).FloorType.GetCompoundStructure(); model.TargetType = TargetType.Floor; } else if (element is RoofBase) { compoundStructure = (element as RoofBase).RoofType.GetCompoundStructure(); model.TargetType = TargetType.RoofBase; } else { throw new NotImplementedException("暂不支持该类型的对象,未能成功获取CompoundStructure"); } return(compoundStructure); }
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 static CompoundStructure set_compound_structure(CompoundStructure compound, ObservableCollection <data_materials> mydata_materials, ObservableCollection <data_parameters> mydata_parameters, string unit_length) { CompoundStructure compound_new = compound; try { IList <CompoundStructureLayer> cslayers = compound_new.GetLayers(); for (int i = 0; i < cslayers.Count; i++) { compound_new.SetLayerWidth(mydata_parameters[i].layer.LayerId, Convert.ToDouble(mydata_parameters[i].gia_tri_parameter) / Source.units_document.First(x => x.name == unit_length).value); if (mydata_materials[i].ten_vat_lieu.name != "<By Category>") { compound_new.SetMaterialId(mydata_materials[i].layer.LayerId, mydata_materials[i].ten_vat_lieu.vat_lieu.Id); } else { compound_new.SetMaterialId(mydata_materials[i].layer.LayerId, new ElementId(-1)); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(compound_new); }
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); }
/// <summary> /// Gets the material Id of the first layer of the host object. /// </summary> /// <param name="hostObject">The host object.</param> /// <returns>The material id.</returns> public static ElementId GetFirstLayerMaterialId(HostObject hostObject) { ElementId typeElemId = hostObject.GetTypeId(); HostObjAttributes hostObjAttr = hostObject.Document.GetElement(typeElemId) as HostObjAttributes; if (hostObjAttr == null) { return(ElementId.InvalidElementId); } CompoundStructure cs = hostObjAttr.GetCompoundStructure(); if (cs != null) { ElementId matId = cs.LayerCount > 0 ? cs.GetMaterialId(0) : ElementId.InvalidElementId; if (matId != ElementId.InvalidElementId) { return(matId); } else { return(CategoryUtil.GetBaseMaterialIdForElement(hostObject)); }; } return(ElementId.InvalidElementId); }
internal static Material GetMaterial(Document doc, Wall wall) { WallType aWallType = wall.WallType; if (WallKind.Basic == aWallType.Kind) { CompoundStructure comStruct = aWallType.GetCompoundStructure(); Categories allCategories = doc.Settings.Categories; // Get the category OST_Walls default Material; // use if that layer's default Material is <By Category> Category wallCategory = allCategories.get_Item(BuiltInCategory.OST_Walls); Material wallMaterial = wallCategory.Material; foreach (CompoundStructureLayer structLayer in comStruct.GetLayers()) { var layerMaterial = ElementFilterUtils.GetElement(doc, structLayer.MaterialId) as Material; if (layerMaterial == null) { switch (structLayer.Function) { case MaterialFunctionAssignment.Structure: layerMaterial = allCategories.get_Item(BuiltInCategory.OST_WallsStructure).Material; break; } } if (layerMaterial != null) { wallMaterial = layerMaterial; break; } } return(wallMaterial); } return(null); }
public void ChangeElementMaterial(Element element, Material material) { Wall w = (Wall)element; WallType wt = w.WallType; WallType nwt; IList <WallType> desiredType = new FilteredElementCollector(doc) .OfClass(typeof(WallType)) .Cast <WallType>() .Where <WallType>(wallType => wallType.Name.Equals("MyWall")).ToList <WallType>(); if (desiredType.Count == 0) { nwt = wt.Duplicate("MyWall") as WallType; CompoundStructure cs = nwt.GetCompoundStructure(); IList <CompoundStructureLayer> layers = nwt.GetCompoundStructure().GetLayers(); int layerIndex = 0; foreach (CompoundStructureLayer l in layers) { cs.SetMaterialId(layerIndex, material.Id); layerIndex++; } nwt.SetCompoundStructure(cs); } else { nwt = desiredType.First(); } w.WallType = nwt; }
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 Generate(Document doc, CSAModel model, Element element, XYZ offset) { CompoundStructure compoundStructure = model.GetCompoundStructure(element);//获取文本载体 if (compoundStructure == null) { return; } var texts = model.FetchTextsFromCompoundStructure(doc, compoundStructure);//获取文本数据 if (texts.Count == 0) { return; } if (texts.Count == 1) { TaskDialog.Show("警告", "暂不支持单层的结构做法标注"); } else { model.TargetId = element.Id; //主体 var lineFamilySymbol = VLConstraintsForCSA.GetMultipleTagSymbol(doc); //获取线标注类型 bool isRegenerate = offset != null; FamilyInstance line; if (isRegenerate) { line = doc.GetElement(model.LineId) as FamilyInstance; model.CalculateLocations(element, line, offset); //计算内容定位 Clear(doc, model); line = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), lineFamilySymbol, doc.ActiveView); //生成 线 } else { line = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), lineFamilySymbol, doc.ActiveView); //生成 线 model.CalculateLocations(element, line, offset); //计算内容定位 } var lineLocation = model.LineLocation; var textLocations = model.TextLocations; ElementTransformUtils.MoveElement(doc, line.Id, lineLocation); //线定位 LocationPoint locationPoint = line.Location as LocationPoint; //线 旋转处理 locationPoint.RotateByXY(lineLocation, model.VerticalVector); model.LineId = line.Id; model.UpdateLineParameters(line, model.LineHeight, model.LineWidth, model.LineSpace, model.Texts.Count()); //线参数设置 List <TextNote> textNotes = new List <TextNote>(); foreach (var text in model.Texts) //生成 文本 { var textLocation = model.TextLocations[model.Texts.IndexOf(text)]; var textNote = TextNote.Create(doc, doc.ActiveView.Id, textLocation, text, model.TextNoteTypeElementId); textNotes.Add(textNote); textNote.Location.RotateByXY(textLocation, model.VerticalVector); } model.TextNoteIds = textNotes.Select(c => c.Id).ToList(); //测试用 //GraphicsDisplayerManager.Display(@"E:\WorkingSpace\Outputs\Images\1023结构做法标注.png", lines, Model.TextLocations); } }
internal static void UpdateTag(ElementId modifiedElmId, Autodesk.Revit.DB.Document doc) { StringBuilder strBld = new StringBuilder(); int rows = 0; int shelfLength = 0; Element modifiedElm = doc.GetElement(modifiedElmId); switch (modifiedElm.Category.Name) { case "Walls": Wall wl = modifiedElm as Wall; WallType wlType = wl.WallType; CompoundStructure cmpStr_wl = wlType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_wl, doc, out shelfLength); rows = wlType.GetCompoundStructure().LayerCount; break; case "Floors": Floor fl = modifiedElm as Floor; FloorType flType = fl.FloorType; CompoundStructure cmpStr_fl = flType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_fl, doc, out shelfLength); rows = flType.GetCompoundStructure().LayerCount; break; case "Ceilings": Ceiling cl = modifiedElm as Ceiling; CeilingType clType = doc.GetElement(cl.GetTypeId()) as CeilingType; CompoundStructure cmpStr_cl = clType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_cl, doc, out shelfLength); rows = clType.GetCompoundStructure().LayerCount; break; case "Roofs": RoofBase rf = modifiedElm as RoofBase; RoofType rfType = rf.RoofType; CompoundStructure cmpStr_rf = rfType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_rf, doc, out shelfLength); rows = rfType.GetCompoundStructure().LayerCount; break; } FamilyInstance tag = doc.GetElement(new ElementId(modifiedElm.LookupParameter("LinkedTag").AsInteger())) as FamilyInstance; try { tag.LookupParameter("multilineText").Set(strBld.ToString()); tag.LookupParameter("# of Rows").Set(rows); tag.LookupParameter("Shelf Length").Set(ToFt(shelfLength)); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } }
CollectEvent(object sender, CollectorEventArgs e) { // cast the sender object to the SnoopCollector we are expecting Collector snoopCollector = sender as Collector; if (snoopCollector == null) { Debug.Assert(false); // why did someone else send us the message? return; } // see if it is a type we are responsible for AnalyticalModel aModel = e.ObjToSnoop as AnalyticalModel; if (aModel != null) { Stream(snoopCollector.Data(), aModel); return; } CompoundStructure compStruct = e.ObjToSnoop as CompoundStructure; if (compStruct != null) { Stream(snoopCollector.Data(), compStruct); return; } CompoundStructureLayer compStructLayer = e.ObjToSnoop as CompoundStructureLayer; if (compStructLayer != null) { Stream(snoopCollector.Data(), compStructLayer); return; } AnalyticalModelSupport supportData = e.ObjToSnoop as AnalyticalModelSupport; if (supportData != null) { Stream(snoopCollector.Data(), supportData); return; } RebarInSystem barDesc = e.ObjToSnoop as RebarInSystem; if (barDesc != null) { Stream(snoopCollector.Data(), barDesc); return; } }
private WallType DuplicateWallType(WallType wallType, Document doc) { WallType newWallType; //Select the wall type in the document IEnumerable <WallType> _wallTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(WallType)) let type = elem as WallType where type.Kind == WallKind.Basic select type; List <string> wallTypesNames = _wallTypes.Select(o => o.Name).ToList(); if (!wallTypesNames.Contains("newWallTypeName")) { newWallType = wallType.Duplicate("newWallTypeName") as WallType; } else { newWallType = wallType.Duplicate("newWallTypeName2") as WallType; } CompoundStructure cs = newWallType.GetCompoundStructure(); IList <CompoundStructureLayer> layers = cs.GetLayers(); int layerIndex = 0; foreach (CompoundStructureLayer csl in layers) { double layerWidth = csl.Width * 2; if (cs.GetRegionsAssociatedToLayer(layerIndex).Count == 1) { try { cs.SetLayerWidth(layerIndex, layerWidth); } catch { throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult)); } } else { throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult)); } layerIndex++; } newWallType.SetCompoundStructure(cs); return(newWallType); }
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 }; }
public static HostPartitionType ToSAM_HostPartitionType(this HostObjAttributes hostObjAttributes, ConvertSettings convertSettings) { if (hostObjAttributes == null) { return(null); } HostPartitionType result = convertSettings?.GetObject <HostPartitionType>(hostObjAttributes.Id); if (result != null) { return(result); } string name = hostObjAttributes.Name; List <MaterialLayer> materialLayers = Architectural.Revit.Create.MaterialLayers(hostObjAttributes.Document, hostObjAttributes.GetCompoundStructure()); if (materialLayers == null) { return(null); } if (hostObjAttributes is Autodesk.Revit.DB.WallType) { result = new WallType(name); } else if (hostObjAttributes is Autodesk.Revit.DB.RoofType) { result = new RoofType(name); } else if (hostObjAttributes is Autodesk.Revit.DB.FloorType) { result = new FloorType(name); } CompoundStructure compoundStructure = hostObjAttributes.GetCompoundStructure(); if (compoundStructure != null) { compoundStructure.GetLayers(); } if (result != null) { result.UpdateParameterSets(hostObjAttributes); convertSettings?.Add(hostObjAttributes.Id, result); } return(result); }
public void Execute(UpdaterData updateData) { var doc = updateData.GetDocument(); var adds = updateData.GetAddedElementIds(); var edits = updateData.GetModifiedElementIds(); var deletes = updateData.GetDeletedElementIds(); if (edits.Count == 0) { return; } foreach (var editId in edits) { var element = doc.GetElement(editId); CompoundStructure compoundStructure = null; if (element is WallType) { compoundStructure = (element as WallType).GetCompoundStructure(); } if (element is FloorType) { compoundStructure = (element as FloorType).GetCompoundStructure(); } if (element is ExtrusionRoof)//屋顶有多种类型 { compoundStructure = (element as ExtrusionRoof).RoofType.GetCompoundStructure(); } if (compoundStructure == null) { return; } var layers = compoundStructure.GetLayers(); string text = ""; foreach (var layer in layers) { if (layer.MaterialId.IntegerValue < 0) { continue; } var material = doc.GetElement(layer.MaterialId); if (material == null) { continue; } text += layer.Width + doc.GetElement(layer.MaterialId).Name + System.Environment.NewLine; } } }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static List <BH.oM.Geometry.Line> CeilingPattern(this Ceiling ceiling, RevitSettings settings, PlanarSurface surface = null) { CeilingType ceilingType = ceiling.Document.GetElement(ceiling.GetTypeId()) as CeilingType; CompoundStructure comStruct = ceilingType.GetCompoundStructure(); Material material = null; if (comStruct != null && comStruct.GetLayers().Count > 0) { material = ceiling.Document.GetElement(comStruct.GetLayers().Last().MaterialId) as Material; } else { ElementId materialId = ceiling.GetMaterialIds(false)?.FirstOrDefault(); if (materialId != null) { material = ceiling.Document.GetElement(materialId) as Material; } } if (material == null) { BH.Engine.Reflection.Compute.RecordWarning(String.Format("Ceiling patterns could not be pulled because there is no material assigned to the ceiling. Revit ElementId: {0}", ceiling.Id)); return(new List <oM.Geometry.Line>()); } double rotation; XYZ alignment = ceiling.CeilingPatternAlignment(material, settings, out rotation); List <oM.Geometry.Line> result = new List <oM.Geometry.Line>(); if (surface == null) { //This would need to be extended to take openings from Values into account foreach (PlanarSurface srf in ceiling.PanelSurfaces(ceiling.FindInserts(true, true, true, true), settings).Keys) { result.AddRange(material.CeilingPattern(srf, settings, alignment, rotation)); } } else { result.AddRange(material.CeilingPattern(surface, settings, alignment, rotation)); } return(result); }
//---------------------------------------------------------- public void ChangeWallType(UIApplication uiapp, Document doc) { try { List <string> modelWallType = new List <string>(); List <string> qualityWallType = new List <string>(); var wallType = new FilteredElementCollector(doc).OfClass(typeof(WallType)).ToElements(); foreach (WallType type in wallType) { if (type.Name.Split('_').Count() > 0 && type.Name.Split('_')[0] == "S") { try { CompoundStructure compound = null; compound = type.GetCompoundStructure(); IList <CompoundStructureLayer> getlayer = compound.GetLayers(); ElementId materialId = new ElementId(-1); double thickness = 0; foreach (var layer in getlayer) { if (layer.Function == MaterialFunctionAssignment.Structure) { materialId = layer.MaterialId; thickness = layer.Width; } } //----------------------------------------------------------------------- var countLayer = compound.LayerCount; var layers = compound.GetLayers(); for (var i = 0; i < countLayer; i++) { layers.RemoveAt(0); } layers.Add(new CompoundStructureLayer(thickness, MaterialFunctionAssignment.Structure, materialId)); compound.SetLayers(layers); type.SetCompoundStructure(compound); } catch (Exception) { } } } } catch (Exception) { } }
private WallType CreateNewWallType(WallType wallType) { WallType newWallType; List <string> wallTypesNames = _wallTypes.Select(o => o.Name).ToList(); if (!wallTypesNames.Contains("newWallTypeName")) { newWallType = wallType.Duplicate("newWallTypeName") as WallType; } else { newWallType = wallType.Duplicate("newWallTypeName2") as WallType; } CompoundStructure cs = newWallType.GetCompoundStructure(); IList <CompoundStructureLayer> layers = cs.GetLayers(); int layerIndex = 0; foreach (CompoundStructureLayer csl in layers) { double layerWidth = csl.Width * 2; if (cs.GetRegionsAssociatedToLayer(layerIndex).Count == 1) { try { cs.SetLayerWidth(layerIndex, layerWidth); } catch { throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult)); } } else { throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult)); } layerIndex++; } newWallType.SetCompoundStructure(cs); return(newWallType); }
private static StringBuilder LayersAsString(CompoundStructure cmpStr, Autodesk.Revit.DB.Document doc, out int max) { StringBuilder strBld = new StringBuilder(); int[] intList = new int[] { 0 }; foreach (CompoundStructureLayer layer in cmpStr.GetLayers()) { string material = null; double layerWidth; string materialAndWidth; if (layer.MaterialId != ElementId.InvalidElementId) { material = doc.GetElement(layer.MaterialId).get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION).AsString(); layerWidth = ToMM(layer.Width); } else { material = "No Material"; layerWidth = ToMM(layer.Width); } materialAndWidth = material + " - " + layerWidth + "mm"; if (materialAndWidth.Length > intList[0]) { intList[0] = materialAndWidth.Length; } if (layer.Width != 0) { strBld.AppendLine(materialAndWidth); } else { strBld.AppendLine(material); } } max = intList[0] + 10; return(strBld); }
public static bool Recognization(RoofBase roof) { Level level = (Level)_doc.GetElement(roof.get_Parameter(BuiltInParameter.ROOF_BASE_LEVEL_PARAM).AsElementId()); double offset = roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM).AsDouble(); bool isFound; _floor = _myLevel.GetFloor(out isFound, level, offset); --_floor; if (MyLevel.GetLevelNum() - 2 < _floor || _floor < 0) { _abandonWriter.WriteAbandonment(roof, AbandonmentTable.LevelNotFound); return(false); } CompoundStructure cs = roof.RoofType.GetCompoundStructure(); try { IList <CompoundStructureLayer> layers = cs.GetLayers(); Material matl = (Material)_doc.GetElement(layers.First().MaterialId); if (matl.MaterialCategory == _addiInfo.materialTypes[(byte)PGMaterialType.ConcreteTile]) { _matlIndex = 1; } else if (matl.MaterialCategory == _addiInfo.materialTypes[(byte)PGMaterialType.ClayTile]) { _matlIndex = 2; } else { _abandonWriter.WriteAbandonment(roof, AbandonmentTable.Roof_MatlOOR); return(false); } } catch { _abandonWriter.WriteAbandonment(roof, AbandonmentTable.Roof_MatlOOR); return(false); } _area = roof.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble(); return(true); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; var elementReference = uiDoc.Selection.PickObject(ObjectType.Element, "选择要添加的构件"); if (elementReference == null) { return(Result.Cancelled); } var element = doc.GetElement(elementReference.ElementId); CompoundStructure compoundStructure = null; if (element is Wall) { compoundStructure = (element as Wall).WallType.GetCompoundStructure(); } if (element is Floor) { compoundStructure = (element as Floor).FloorType.GetCompoundStructure(); } if (element is ExtrusionRoof)//屋顶有多种类型 { compoundStructure = (element as ExtrusionRoof).RoofType.GetCompoundStructure(); } if (compoundStructure == null) { return(Result.Failed); } var layers = compoundStructure.GetLayers(); string text = ""; foreach (var layer in layers) { text += layer.Width + doc.GetElement(layer.MaterialId).Name + System.Environment.NewLine; } return(Result.Succeeded); }
public static List <MaterialLayer> MaterialLayers(this Document document, CompoundStructure compoundStructure) { if (document == null || compoundStructure == null) { return(null); } IEnumerable <CompoundStructureLayer> compoundStructureLayers = compoundStructure.GetLayers(); if (compoundStructureLayers == null) { return(null); } int count = compoundStructureLayers.Count(); List <MaterialLayer> result = new List <MaterialLayer>(); for (int i = 0; i < count; i++) { CompoundStructureLayer compoundStructureLayer = compoundStructureLayers.ElementAt(i); if (compoundStructureLayer == null) { continue; } Material material = document.GetElement(compoundStructureLayer.MaterialId) as Material; if (material == null) { continue; } double thickness = compoundStructure.GetLayerWidth(i); result.Add(new MaterialLayer(material.Name, thickness)); } return(result); }
public static List <Layer> GetLayers(Revit.Elements.WallType wallType) { Document document = DocumentManager.Instance.CurrentDBDocument; var wt = wallType.InternalElement as Autodesk.Revit.DB.WallType; CompoundStructure structure = wt.GetCompoundStructure(); int layerCount = structure.LayerCount; int strMaterialInd = structure.StructuralMaterialIndex; List <Layer> layers = new List <Layer>(); for (int i = 0; i < layerCount; i++) { layers.Add(new Layer(structure.GetLayerFunction(i).ToString(), document.GetElement(structure.GetMaterialId(i)) as Autodesk.Revit.DB.Material, UnitUtils.ConvertFromInternalUnits(structure.GetLayerWidth(i), DisplayUnitType.DUT_MILLIMETERS), i == strMaterialInd, structure.IsCoreLayer(i))); } return(layers); }
//---------------------------------------------------------- public static void get_data_compound(Document doc, CompoundStructure compound, List <data_element> my_element, Element element, string parameter_name) { try { IList <CompoundStructureLayer> getlayer = compound.GetLayers(); foreach (var layer in getlayer) { if (layer.MaterialId.IntegerValue != -1) { my_element.Add(new data_element() { parameter_value = doc.GetElement(layer.MaterialId).Name, element = element, parameter_name = parameter_name }); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Gets the material ids of finish function of the host object. /// </summary> /// <param name="hostObject">The host object.</param> /// <returns>The material ids.</returns> public static ISet <ElementId> GetFinishMaterialIds(HostObject hostObject) { HashSet <ElementId> matIds = new HashSet <ElementId>(); ElementId typeElemId = hostObject.GetTypeId(); HostObjAttributes hostObjAttr = hostObject.Document.GetElement(typeElemId) as HostObjAttributes; if (hostObjAttr == null) { return(matIds); } ElementId baseMatId = CategoryUtil.GetBaseMaterialIdForElement(hostObject); CompoundStructure cs = hostObjAttr.GetCompoundStructure(); if (cs != null) { for (int i = 0; i < cs.LayerCount; ++i) { MaterialFunctionAssignment function = cs.GetLayerFunction(i); if (function == MaterialFunctionAssignment.Finish1 || function == MaterialFunctionAssignment.Finish2) { ElementId matId = cs.GetMaterialId(i); if (matId != ElementId.InvalidElementId) { matIds.Add(matId); } else if (baseMatId != ElementId.InvalidElementId) { matIds.Add(baseMatId); } } } } return(matIds); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static oM.Physical.Constructions.Construction ConstructionFromRevit(this HostObjAttributes hostObjAttributes, string materialGrade = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); string refId = hostObjAttributes.Id.ReferenceIdentifier(materialGrade); oM.Physical.Constructions.Construction construction = refObjects.GetValue <oM.Physical.Constructions.Construction>(refId); if (construction != null) { return(construction); } List <BH.oM.Physical.Constructions.Layer> layers = new List <oM.Physical.Constructions.Layer>(); CompoundStructure compoundStructure = hostObjAttributes.GetCompoundStructure(); if (compoundStructure != null) { IEnumerable <CompoundStructureLayer> compoundStructureLayers = compoundStructure.GetLayers(); if (compoundStructureLayers != null) { foreach (CompoundStructureLayer layer in compoundStructureLayers) { layers.Add(layer.Layer(hostObjAttributes, materialGrade, settings, refObjects)); } } } construction = BH.Engine.Physical.Create.Construction(hostObjAttributes.FamilyTypeFullName(), layers); //Set identifiers, parameters & custom data construction.SetIdentifiers(hostObjAttributes); construction.CopyParameters(hostObjAttributes, settings.ParameterSettings); construction.SetProperties(hostObjAttributes, settings.ParameterSettings); refObjects.AddOrReplace(refId, construction); return(construction); }
Stream(ArrayList data, CompoundStructure compStruct) { data.Add(new Snoop.Data.ClassSeparator(typeof(CompoundStructure))); data.Add(new Snoop.Data.Enumerable("Layers", compStruct.GetLayers())); int structuralMaterialIdx = compStruct.StructuralMaterialIndex; data.Add(new Snoop.Data.Int("Structural Material Index", structuralMaterialIdx)); if (structuralMaterialIdx >= 0) { data.Add(new Snoop.Data.ElementId("Structural Material (using StructuralMaterialIndex)", compStruct.GetMaterialId(structuralMaterialIdx), m_activeDoc)); } else { data.Add(new Snoop.Data.ElementId("Structural Material (using StructuralMaterialIndex)", ElementId.InvalidElementId, m_activeDoc)); } data.Add(new Snoop.Data.Double("Width", compStruct.GetWidth())); data.Add(new Snoop.Data.Int("Variable Layer Index", compStruct.VariableLayerIndex)); data.Add(new Snoop.Data.Bool("Is vertically compound", compStruct.IsVerticallyCompound)); data.Add(new Snoop.Data.Bool("Is vertically homogeneous", compStruct.IsVerticallyHomogeneous())); }
/// <summary> /// Exports materials for host object. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="hostObject">The host object.</param> /// <param name="elemHnds">The host IFC handles.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <param name="levelId">The level id.</param> /// <param name="direction">The IFCLayerSetDirection.</param> /// <param name="containsBRepGeometry">True if the geometry contains BRep geoemtry. If so, we will export an IfcMaterialList</param> /// <returns>True if exported successfully, false otherwise.</returns> public static bool ExportHostObjectMaterials(ExporterIFC exporterIFC, HostObject hostObject, IList <IFCAnyHandle> elemHnds, GeometryElement geometryElement, ProductWrapper productWrapper, ElementId levelId, Toolkit.IFCLayerSetDirection direction, bool containsBRepGeometry) { if (hostObject == null) { return(true); //nothing to do } if (elemHnds == null || (elemHnds.Count == 0)) { return(true); //nothing to do } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { if (productWrapper != null) { productWrapper.ClearFinishMaterials(); } double scaledOffset = 0.0, scaledWallWidth = 0.0, wallHeight = 0.0; Wall wall = hostObject as Wall; if (wall != null) { scaledWallWidth = UnitUtil.ScaleLength(wall.Width); scaledOffset = -scaledWallWidth / 2.0; BoundingBoxXYZ boundingBox = wall.get_BoundingBox(null); if (boundingBox != null) { wallHeight = boundingBox.Max.Z - boundingBox.Min.Z; } } ElementId typeElemId = hostObject.GetTypeId(); IFCAnyHandle materialLayerSet = ExporterCacheManager.MaterialLayerSetCache.Find(typeElemId); // Roofs with no components are only allowed one material. We will arbitrarily choose the thickest material. IFCAnyHandle primaryMaterialHnd = ExporterCacheManager.MaterialLayerSetCache.FindPrimaryMaterialHnd(typeElemId); if (IFCAnyHandleUtil.IsNullOrHasNoValue(materialLayerSet)) { HostObjAttributes hostObjAttr = hostObject.Document.GetElement(typeElemId) as HostObjAttributes; if (hostObjAttr == null) { return(true); //nothing to do } List <ElementId> matIds = new List <ElementId>(); List <double> widths = new List <double>(); List <MaterialFunctionAssignment> functions = new List <MaterialFunctionAssignment>(); ElementId baseMatId = CategoryUtil.GetBaseMaterialIdForElement(hostObject); CompoundStructure cs = hostObjAttr.GetCompoundStructure(); if (cs != null) { //TODO: Vertically compound structures are not yet supported by export. if (!cs.IsVerticallyHomogeneous() && !MathUtil.IsAlmostZero(wallHeight)) { cs = cs.GetSimpleCompoundStructure(wallHeight, wallHeight / 2.0); } for (int i = 0; i < cs.LayerCount; ++i) { ElementId matId = cs.GetMaterialId(i); if (matId != ElementId.InvalidElementId) { matIds.Add(matId); } else { matIds.Add(baseMatId); } widths.Add(cs.GetLayerWidth(i)); // save layer function into ProductWrapper, // it's used while exporting "Function" of Pset_CoveringCommon functions.Add(cs.GetLayerFunction(i)); } } if (matIds.Count == 0) { matIds.Add(baseMatId); widths.Add(cs != null ? cs.GetWidth() : 0); functions.Add(MaterialFunctionAssignment.None); } // We can't create IfcMaterialLayers without creating an IfcMaterialLayerSet. So we will simply collate here. IList <IFCAnyHandle> materialHnds = new List <IFCAnyHandle>(); IList <int> widthIndices = new List <int>(); double thickestLayer = 0.0; for (int ii = 0; ii < matIds.Count; ++ii) { // Require positive width for IFC2x3 and before, and non-negative width for IFC4. if (widths[ii] < -MathUtil.Eps()) { continue; } bool almostZeroWidth = MathUtil.IsAlmostZero(widths[ii]); if (ExporterCacheManager.ExportOptionsCache.FileVersion != IFCVersion.IFC4 && almostZeroWidth) { continue; } if (almostZeroWidth) { widths[ii] = 0.0; } IFCAnyHandle materialHnd = CategoryUtil.GetOrCreateMaterialHandle(exporterIFC, matIds[ii]); if (primaryMaterialHnd == null || (widths[ii] > thickestLayer)) { primaryMaterialHnd = materialHnd; thickestLayer = widths[ii]; } widthIndices.Add(ii); materialHnds.Add(materialHnd); if ((productWrapper != null) && (functions[ii] == MaterialFunctionAssignment.Finish1 || functions[ii] == MaterialFunctionAssignment.Finish2)) { productWrapper.AddFinishMaterial(materialHnd); } } int numLayersToCreate = widthIndices.Count; if (numLayersToCreate == 0) { return(false); } if (!containsBRepGeometry) { IList <IFCAnyHandle> layers = new List <IFCAnyHandle>(numLayersToCreate); for (int ii = 0; ii < numLayersToCreate; ii++) { int widthIndex = widthIndices[ii]; double scaledWidth = UnitUtil.ScaleLength(widths[widthIndex]); IFCAnyHandle materialLayer = IFCInstanceExporter.CreateMaterialLayer(file, materialHnds[ii], scaledWidth, null); layers.Add(materialLayer); } string layerSetName = exporterIFC.GetFamilyName(); materialLayerSet = IFCInstanceExporter.CreateMaterialLayerSet(file, layers, layerSetName); ExporterCacheManager.MaterialLayerSetCache.Register(typeElemId, materialLayerSet); ExporterCacheManager.MaterialLayerSetCache.RegisterPrimaryMaterialHnd(typeElemId, primaryMaterialHnd); } else { foreach (IFCAnyHandle elemHnd in elemHnds) { CategoryUtil.CreateMaterialAssociations(exporterIFC, elemHnd, matIds); } } } // IfcMaterialLayerSetUsage is not supported for IfcWall, only IfcWallStandardCase. IFCAnyHandle layerSetUsage = null; for (int ii = 0; ii < elemHnds.Count; ii++) { IFCAnyHandle elemHnd = elemHnds[ii]; if (IFCAnyHandleUtil.IsNullOrHasNoValue(elemHnd)) { continue; } SpaceBoundingElementUtil.RegisterSpaceBoundingElementHandle(exporterIFC, elemHnd, hostObject.Id, levelId); if (containsBRepGeometry) { continue; } HashSet <IFCAnyHandle> relDecomposesSet = IFCAnyHandleUtil.GetRelDecomposes(elemHnd); IList <IFCAnyHandle> subElemHnds = null; if (relDecomposesSet != null && relDecomposesSet.Count == 1) { IFCAnyHandle relAggregates = relDecomposesSet.First(); if (IFCAnyHandleUtil.IsTypeOf(relAggregates, IFCEntityType.IfcRelAggregates)) { subElemHnds = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(relAggregates, "RelatedObjects"); } } bool hasSubElems = (subElemHnds != null && subElemHnds.Count != 0); bool isRoof = IFCAnyHandleUtil.IsTypeOf(elemHnd, IFCEntityType.IfcRoof); if (!hasSubElems && !isRoof && !IFCAnyHandleUtil.IsTypeOf(elemHnd, IFCEntityType.IfcWall)) { if (layerSetUsage == null) { bool flipDirSense = true; if (wall != null) { // if we have flipped the center curve on export, we need to take that into account here. // We flip the center curve on export if it is an arc and it has a negative Z direction. LocationCurve locCurve = wall.Location as LocationCurve; if (locCurve != null) { Curve curve = locCurve.Curve; Plane defPlane = new Plane(XYZ.BasisX, XYZ.BasisY, XYZ.Zero); bool curveFlipped = GeometryUtil.MustFlipCurve(defPlane, curve); flipDirSense = !(wall.Flipped ^ curveFlipped); } } else if (hostObject is Floor) { flipDirSense = false; } double offsetFromReferenceLine = flipDirSense ? -scaledOffset : scaledOffset; IFCDirectionSense sense = flipDirSense ? IFCDirectionSense.Negative : IFCDirectionSense.Positive; layerSetUsage = IFCInstanceExporter.CreateMaterialLayerSetUsage(file, materialLayerSet, direction, sense, offsetFromReferenceLine); } ExporterCacheManager.MaterialLayerRelationsCache.Add(layerSetUsage, elemHnd); } else { if (hasSubElems) { foreach (IFCAnyHandle subElemHnd in subElemHnds) { if (!IFCAnyHandleUtil.IsNullOrHasNoValue(subElemHnd)) { ExporterCacheManager.MaterialLayerRelationsCache.Add(materialLayerSet, subElemHnd); } } } else if (!isRoof) { ExporterCacheManager.MaterialLayerRelationsCache.Add(materialLayerSet, elemHnd); } else if (primaryMaterialHnd != null) { ExporterCacheManager.MaterialLayerRelationsCache.Add(primaryMaterialHnd, elemHnd); } } } tr.Commit(); return(true); } }
Stream(ArrayList data, CompoundStructure compStruct) { data.Add(new Snoop.Data.ClassSeparator(typeof(CompoundStructure))); data.Add(new Snoop.Data.Enumerable("Layers", compStruct.GetLayers())); }
private void Stream(ArrayList data, CompoundStructure compStruct) { data.Add(new Snoop.Data.ClassSeparator(typeof(CompoundStructure))); data.Add(new Snoop.Data.Enumerable("Layers", compStruct.GetLayers())); int structuralMaterialIdx = compStruct.StructuralMaterialIndex; data.Add(new Snoop.Data.Int("Structural Material Index", structuralMaterialIdx)); if (structuralMaterialIdx >= 0) data.Add(new Snoop.Data.ElementId("Structural Material (using StructuralMaterialIndex)", compStruct.GetMaterialId(structuralMaterialIdx), m_activeDoc)); else data.Add(new Snoop.Data.ElementId("Structural Material (using StructuralMaterialIndex)", ElementId.InvalidElementId, m_activeDoc)); data.Add(new Snoop.Data.Double("Width", compStruct.GetWidth())); data.Add(new Snoop.Data.Int("Variable Layer Index", compStruct.VariableLayerIndex)); data.Add(new Snoop.Data.Bool("Is vertically compound", compStruct.IsVerticallyCompound)); data.Add(new Snoop.Data.Bool("Is vertically homogeneous", compStruct.IsVerticallyHomogeneous())); }