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 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); }
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 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 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 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 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; } } }
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); }
/// <summary> /// 从 CompoundStructure 中获取标注信息 /// </summary> /// <param name="doc"></param> /// <param name="compoundStructure"></param> /// <returns></returns> public static List <string> FetchTextsFromCompoundStructure(this CSAModel model, Document doc, CompoundStructure compoundStructure) { var layers = compoundStructure.GetLayers(); var texts = new List <string>(); foreach (var layer in layers) { string name = ""; var material = doc.GetElement(layer.MaterialId); if (material == null) { name = "<按类别>"; } else { name = doc.GetElement(layer.MaterialId).Name; } texts.Add(UnitHelper.ConvertFromFootTo(layer.Width, VLUnitType.millimeter) + "厚" + name); } model.Texts = texts; return(texts); }
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 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); } }
/***************************************************/ /**** 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())); }
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())); }
{//---------------------------------------------------------- public static void parameter_and_material_type(Document doc, ElementType type, ListView thong_tin_kich_thuoc, ObservableCollection <data_parameters> my_parameters, ListView thong_tin_cong_tac_vat_lieu, ObservableCollection <data_materials> my_materials, ObservableCollection <data_material> my_material, string unit_length) { try { var TypeOftype = type.GetType(); CompoundStructure compound = null; if (TypeOftype.Name == "WallType") { var wall = type as WallType; compound = wall.GetCompoundStructure(); } if (TypeOftype.Name == "FloorType") { var wall = type as FloorType; compound = wall.GetCompoundStructure(); } if (TypeOftype.Name == "RoofType") { var wall = type as RoofType; compound = wall.GetCompoundStructure(); } if (TypeOftype.Name == "CeilingType") { var wall = type as CeilingType; compound = wall.GetCompoundStructure(); } IList <CompoundStructureLayer> getlayer = compound.GetLayers(); foreach (var layer in getlayer) { my_parameters.Add(new data_parameters() { ten_parameter = layer.Function.ToString(), gia_tri_parameter = Math.Round(layer.Width * Source.units_document.First(x => x.name == unit_length).value, 0).ToString(), group_parameter = "Dimensions", layer = layer, compound = compound }); } thong_tin_kich_thuoc.ItemsSource = my_parameters; ListCollectionView view_kich_thuoc = CollectionViewSource.GetDefaultView(thong_tin_kich_thuoc.ItemsSource) as ListCollectionView; PropertyGroupDescription groupDescription1 = new PropertyGroupDescription("group_parameter"); view_kich_thuoc.GroupDescriptions.Add(groupDescription1); view_kich_thuoc.CustomSort = new sort_data_parameters(); //--------------------------------------------------------------------------------------------------------------------- foreach (var layer in getlayer) { string ten = "<By Category>"; string ma = ""; if (layer.MaterialId.IntegerValue != -1) { ten = doc.GetElement(layer.MaterialId).Name; ma = F_GetSchema.Check_Para_And_Get_Para(doc.GetElement(layer.MaterialId) as Material, Source.MCT[1], Source.MCT[0]); } my_materials.Add(new data_materials() { ten_cong_tac = layer.Function.ToString(), ten_vat_lieu_list = my_material, ten_vat_lieu = my_material.First(x => x.name == ten), layer = layer, compound = compound }); } thong_tin_cong_tac_vat_lieu.ItemsSource = my_materials; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(thong_tin_cong_tac_vat_lieu.ItemsSource); view.SortDescriptions.Add(new SortDescription("ten_cong_tac", ListSortDirection.Ascending)); } catch (Exception) { thong_tin_kich_thuoc.ItemsSource = new ObservableCollection <data_parameters>(); thong_tin_cong_tac_vat_lieu.ItemsSource = new ObservableCollection <data_materials>(); } }
//---------------------------------------------------------- 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); }
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 Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; UIDocument uidoc = app.ActiveUIDocument; Document doc = app.ActiveUIDocument.Document; // Retrieve selected walls, or all walls, // if nothing is selected: List <Element> walls = new List <Element>(); if (!Util.GetSelectedElementsOrAll( walls, uidoc, typeof(Wall))) { Selection sel = uidoc.Selection; message = (0 < sel.GetElementIds().Count) ? "Please select some wall elements." : "No wall elements found."; return(Result.Failed); } //int i; // 2011 int n; double halfThickness, layerOffset; //Creator creator = new Creator( doc ); XYZ lcstart, lcend, v, w, p, q; using (Transaction tx = new Transaction(doc)) { tx.Start("Draw wall layer sepearation lines"); foreach (Wall wall in walls) { string desc = Util.ElementDescription(wall); LocationCurve curve = wall.Location as LocationCurve; if (null == curve) { message = desc + ": No wall curve found."; return(Result.Failed); } // Wall centre line and thickness: lcstart = curve.Curve.GetEndPoint(0); lcend = curve.Curve.GetEndPoint(1); halfThickness = 0.5 * wall.WallType.Width; v = lcend - lcstart; v = v.Normalize(); // one foot long w = XYZ.BasisZ.CrossProduct(v).Normalize(); if (wall.Flipped) { w = -w; } p = lcstart - 2 * v; q = lcend + 2 * v; Creator.CreateModelLine(doc, p, q); q = p + halfThickness * w; Creator.CreateModelLine(doc, p, q); // Exterior edge p = lcstart - v + halfThickness * w; q = lcend + v + halfThickness * w; Creator.CreateModelLine(doc, p, q); //CompoundStructure structure = wall.WallType.CompoundStructure; // 2011 CompoundStructure structure = wall.WallType.GetCompoundStructure(); // 2012 if (null == structure) { message = desc + ": No compound structure " + "found. Is this a stacked wall?"; return(Result.Failed); } //CompoundStructureLayerArray layers = structure.Layers; // 2011 IList <CompoundStructureLayer> layers = structure.GetLayers(); // 2012 //i = 0; // 2011 //n = layers.Size; // 2011 n = layers.Count; // 2012 Debug.Print( "{0} with thickness {1}" + " has {2} layer{3}{4}", desc, Util.MmString(2 * halfThickness), n, Util.PluralSuffix(n), Util.DotOrColon(n)); if (0 == n) { // Interior edge p = lcstart - v - halfThickness * w; q = lcend + v - halfThickness * w; Creator.CreateModelLine(doc, p, q); } else { layerOffset = halfThickness; foreach (CompoundStructureLayer layer in layers) { Debug.Print( " Layer {0}: function {1}, " + "thickness {2}", //++i, // 2011 layers.IndexOf(layer), // 2012 layer.Function, Util.MmString(layer.Width)); //layerOffset -= layer.Thickness; // 2011 layerOffset -= layer.Width; // 2012 p = lcstart - v + layerOffset * w; q = lcend + v + layerOffset * w; Creator.CreateModelLine(doc, p, q); } } tx.Commit(); } } return(Result.Succeeded); }
/// <summary> /// Cumulate the compound wall layer volumes for the given wall. /// </summary> void GetWallLayerVolumes( Wall wall, ref MapLayerToVolume totalVolumes) { WallType wt = wall.WallType; //CompoundStructure structure= wt.CompoundStructure; // 2011 CompoundStructure structure = wt.GetCompoundStructure(); // 2012 //CompoundStructureLayerArray layers = structure.Layers; // 2011 IList <CompoundStructureLayer> layers = structure.GetLayers(); // 2012 //int i, n = layers.Size; // 2011 int i, n = layers.Count; // 2012 double area = GetWallParameter(wall, _bipArea); double volume = GetWallParameter(wall, _bipVolume); double thickness = wt.Width; string desc = Util.ElementDescription(wall); Debug.Print( "{0} with thickness {1}" + " and volume {2}" + " has {3} layer{4}{5}", desc, Util.MmString(thickness), Util.RealString(volume), n, Util.PluralSuffix(n), Util.DotOrColon(n)); // volume for entire wall: string key = wall.WallType.Name; totalVolumes.Cumulate(key, volume); // volume for compound wall layers: if (0 < n) { i = 0; double total = 0.0; double layerVolume; foreach (CompoundStructureLayer layer in layers) { key = wall.WallType.Name + " : " + layer.Function; //layerVolume = area * layer.Thickness; // 2011 layerVolume = area * layer.Width; // 2012 totalVolumes.Cumulate(key, layerVolume); total += layerVolume; Debug.Print( " Layer {0}: function {1}, " + "thickness {2}, volume {3}", ++i, layer.Function, Util.MmString(layer.Width), Util.RealString(layerVolume)); } Debug.Print("Wall volume = {0}," + " total layer volume = {1}", Util.RealString(volume), Util.RealString(total)); if (!Util.IsEqual(volume, total)) { Debug.Print("Wall host volume parameter" + " value differs from sum of all layer" + " volumes: {0}", volume - total); } } }
public void Execute(UpdaterData updateData) { try { var document = updateData.GetDocument(); var edits = updateData.GetModifiedElementIds(); var collection = CSAContext.GetCollection(document); if (CSAContext.IsEditing == true) { CSAContext.IsEditing = false; return; } List <int> movedEntities = new List <int>(); foreach (var changeId in edits) { CSAModel model = null; if (VLConstraintsForCSA.Doc == null) { VLConstraintsForCSA.Doc = document; } #region 根据Target重新生成 var targetMoved = collection.Data.FirstOrDefault(c => c.TargetId.IntegerValue == changeId.IntegerValue); if (targetMoved != null) { model = targetMoved; if (movedEntities.Contains(model.TargetId.IntegerValue)) { continue; } var creater = CSAContext.Creator; var target = document.GetElement(model.TargetId);//标注主体失效时删除 if (target == null) { collection.Data.Remove(model); continue; } CSAContext.Creator.Regenerate(document, model, target, new XYZ(0, 0, 0)); movedEntities.Add(model.TargetId.IntegerValue); CSAContext.IsEditing = true; } #endregion #region 根据Text重新生成 var textMoved = collection.Data.FirstOrDefault(c => c.TextNoteIds.FirstOrDefault(p => p.IntegerValue == changeId.IntegerValue) != null); if (textMoved != null) { model = textMoved; if (movedEntities.Contains(model.TargetId.IntegerValue)) { continue; } var creater = CSAContext.Creator; var target = document.GetElement(model.TargetId);//标注主体失效时删除 if (target == null) { collection.Data.Remove(model); continue; } //文本更改处理 var index = model.TextNoteIds.IndexOf(changeId); var newText = (document.GetElement(changeId) as TextNote).Text; if (model.Texts[index] != newText) { CompoundStructure compoundStructure = null; HostObjAttributes hoster = null; if (target is Wall) { hoster = (HostObjAttributes)((target as Wall).WallType); compoundStructure = hoster.GetCompoundStructure(); } if (target is Floor) { hoster = (HostObjAttributes)((target as Floor).FloorType); compoundStructure = hoster.GetCompoundStructure(); } if (target is RoofBase)//屋顶有多种类型 { hoster = (HostObjAttributes)((target as RoofBase).RoofType); compoundStructure = hoster.GetCompoundStructure(); } if (compoundStructure == null) { throw new NotImplementedException("关联更新失败,未获取有效的CompoundStructure类型"); } var layers = compoundStructure.GetLayers(); string pattern = @"([\d+\.]+)厚(.+)[\r]?"; Regex regex = new Regex(pattern); var match = regex.Match(newText); if (!match.Success) { PMMessageBox.ShowError("关联更新失败,文本不符合规范"); return; } var length = match.Groups[1].Value; var lengthFoot = UnitHelper.ConvertToFoot(Convert.ToDouble(length), VLUnitType.millimeter); var materialName = match.Groups[2].Value; var material = new FilteredElementCollector(document).OfClass(typeof(Material)) .FirstOrDefault(c => c.Name == materialName); if (material == null) { PMMessageBox.ShowError("关联更新失败,未获取到对应名称的材质"); return; } //更新 layers[index].Width = lengthFoot; layers[index].MaterialId = material.Id; compoundStructure.SetLayers(layers); IDictionary <int, CompoundStructureError> report = null; IDictionary <int, int> errorMap; try { compoundStructure.IsValid(document, out report, out errorMap); hoster.SetCompoundStructure(compoundStructure); } catch (Exception ex) { PMMessageBox.ShowError("材质设置失败,错误详情:" + (report != null ? string.Join(",", report.Select(c => c.Value)) : "")); throw ex; } ////报错This operation is valid only for non-vertically compound structures //layer = layers[index]; //layer.MaterialId = material.Id; ////compoundStructure.SetLayer(index, layer); } else { var textNote = document.GetElement(changeId) as TextNote; if (model.TextNoteTypeElementId.IntegerValue != textNote.TextNoteType.Id.IntegerValue) { model.TextNoteTypeElementId = textNote.TextNoteType.Id; CSAContext.Creator.Regenerate(document, model, target, new XYZ(0, 0, 0)); } else { //文本偏移处理 //var index = model.TextNoteIds.IndexOf(changeId); //var offset = (document.GetElement(changeId) as TextNote).Coord - model.TextLocations[index]; //CompoundStructureAnnotationContext.Creater.Regenerate(document, model, target, offset); //CSAContext.IsEditing = true;//移动会导致偏移 从而二次触发 } } movedEntities.Add(model.TargetId.IntegerValue); } #endregion #region 根据Line重新生成 var lineMoved = collection.Data.FirstOrDefault(c => c.LineId.IntegerValue == changeId.IntegerValue); if (lineMoved != null) { model = lineMoved; if (movedEntities.Contains(model.TargetId.IntegerValue)) { continue; } var creater = CSAContext.Creator; var target = document.GetElement(model.TargetId); if (target == null) { collection.Data.Remove(model); continue; } CSAContext.Creator.Regenerate(document, model, target); movedEntities.Add(model.TargetId.IntegerValue); CSAContext.IsEditing = true; } #endregion } CSAContext.Save(document); } catch (Exception ex) { VLLogHelper.Error(ex); } }
Stream(ArrayList data, CompoundStructure compStruct) { data.Add(new Snoop.Data.ClassSeparator(typeof(CompoundStructure))); data.Add(new Snoop.Data.Enumerable("Layers", compStruct.GetLayers())); }
Stream(ArrayList data, CompoundStructure compStruct) { data.Add(new Snoop.Data.ClassSeparator(typeof(CompoundStructure))); data.Add(new Snoop.Data.Enumerable("Layers", compStruct.GetLayers())); }
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); }
private void compoundStructureLayeToJson(DesignAutomationData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } Application rvtApp = data.RevitApp; if (rvtApp == null) { throw new InvalidDataException(nameof(rvtApp)); } string modelPath = data.FilePath; if (String.IsNullOrWhiteSpace(modelPath)) { throw new InvalidDataException(nameof(modelPath)); } Document doc = data.RevitDoc; if (doc == null) { throw new InvalidOperationException("Could not open document."); } JArray wallInfoResult = new JArray(); FilteredElementCollector wallCollector = new FilteredElementCollector(doc).OfClass(typeof(Wall)).WhereElementIsNotElementType(); foreach (Element e in wallCollector) { Wall w = e as Wall; WallType wtype = w.WallType; //CURTAIN WALL doesn't contain compound structure layers if (wtype != null && !wtype.Name.Contains("Curtain")) { CompoundStructure compoundStruct = wtype.GetCompoundStructure(); IList <CompoundStructureLayer> compoundStructLayers = compoundStruct.GetLayers() as IList <CompoundStructureLayer>; if (compoundStructLayers.Count == 0) { continue; } dynamic wallLayersInfo = new JObject(); wallLayersInfo.uniqueId = w.UniqueId; wallLayersInfo.layers = new JArray(); foreach (CompoundStructureLayer compoundStructLayer in compoundStructLayers) { dynamic layerInfo = new JObject(); layerInfo.function = compoundStructLayer.Function.ToString(); layerInfo.material = ((Material)doc.GetElement(compoundStructLayer.MaterialId)).Name; layerInfo.width = compoundStructLayer.Width; wallLayersInfo.layers.Add(layerInfo); } wallInfoResult.Add(wallLayersInfo); } } // save all to a .json file using (StreamWriter file = File.CreateText("result.json")) using (JsonTextWriter writer = new JsonTextWriter(file)) { wallInfoResult.WriteTo(writer); } }