private double CalculateFAR(AreaProperties ap) { double far = 0; try { double sum = 0; foreach (int massId in ap.MassIDs) { if (massDictionary.ContainsKey(massId)) { MassProperties mp = massDictionary[massId]; sum = sum + mp.GrossFloorArea; } } if (sum != 0) { far = sum / ap.Area; } return(far); } catch (Exception ex) { MessageBox.Show("Failed to calculate FAR.\n" + ex.Message, "FARCalculator:CalculateFAR", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(far); } }
static public void BuildArea(string area) { Area = AreaPropertiesReader.GetAreaProperties(AreasFolder + area); BuildMaps(); // BuildBackgrounds(); }
//异步计算并更新界面 private async void computeAreaAndVolume(bool all = false) { await Task.Run(() => { int count = 0; AreaProperties ap = computeArea(out count, all); VolumeProperties vp = computeVolume(out count, all); areaTextBox.Text = " " + string.Format("{0:F3}", ap.Area) + " spuare " + model.Units.ToString().ToLower(); volumnTextBox.Text = " " + string.Format("{0:F3}", vp.Volume) + " cubic " + model.Units.ToString().ToLower(); }); }
private List <int> FindMass(AreaProperties ap) { List <int> massIds = new List <int>(); try { Outline outline = new Outline(minXYZ, maxXYZ); BoundingBoxIntersectsFilter intersectFilter = new BoundingBoxIntersectsFilter(outline); BoundingBoxIsInsideFilter insideFilter = new BoundingBoxIsInsideFilter(outline); LogicalOrFilter orFilter = new LogicalOrFilter(intersectFilter, insideFilter); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfCategory(BuiltInCategory.OST_Mass); IList <Element> elements = collector.WherePasses(orFilter).ToElements(); foreach (Element element in elements) { #if RELEASE2015 || RELEASE2016 || RELEASE2017 Parameter parameter = element.LookupParameter("Building Function"); #else Parameter parameter = element.get_Parameter("Building Function"); #endif if (null != parameter) { MassProperties mp = new MassProperties(element); if (mp.GrossFloorArea != 0 && null != mp.Centroid) { if (null != ap.BaseFace.Project(mp.Centroid)) { mp.AreaId = ap.AreaId; mp.PlotCode = ap.PlotCode; mp.DistricCode = ap.DistricCode; if (!massDictionary.ContainsKey(mp.MassId)) { massDictionary.Add(mp.MassId, mp); } massIds.Add(mp.MassId); } } } } } catch (Exception ex) { MessageBox.Show("Failed to find mass instances within an area object.\n" + ex.Message, "FARCacalculator:FindMass", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(massIds); }
//计算选中模型面积 private AreaProperties computeArea(out int count, bool all = false) { AreaProperties ap = new AreaProperties(); count = 0; var blockReferenceNotScaled = true; for (int i = 0; i < model.Entities.Count && blockReferenceNotScaled; i++) { Entity ent = model.Entities[i]; count += AddAreaProperty(ap, ent, out blockReferenceNotScaled, all); } return(ap); }
public static AreaProperties Load(string areaPath) { TextAsset xml = Resources.Load <TextAsset>(areaPath); if (xml == null) { ErrorLogger.Log("Area Xml not found: " + areaPath + ".xml", "When using AreaBuilder.BuildArea, make sure you have that name.xml file in your Area Data directory"); } XmlSerializer serializer = new XmlSerializer(typeof(AreaProperties)); StringReader reader = new StringReader(xml.text); AreaProperties properties = serializer.Deserialize(reader) as AreaProperties; reader.Close(); return(properties); }
//异步 private async void exportDetail() { await Task.Run(() => { int count; AreaProperties area = computeArea(out count, true); VolumeProperties volume = computeVolume(out count, true); //导出操作 //调用selection功能更新界面操作状态 for (int i = 0; i < selectionGroup.Controls.Count; i++) { if (selectionGroup.Controls[i] is RadioButton) { RadioButton radio = (RadioButton)selectionGroup.Controls[i]; changeSelectionStatus(radio.Name); } } }); }
//导出 private void exportDetailButton_Click(object sender, EventArgs e) { if (transform) { transform = false; if (transforming) { transforming = false; model.ObjectManipulator.Cancel(); model.Invalidate(); } openButton.Enabled = false; importButton.Enabled = false; exportDetailButton.Enabled = false; } //exportDetail(); //var x = model.Viewports[model.Viewports.Count - 1]; int entities, vertices, triangles, count; model.Entities.GetStats(model.Blocks, out entities, out vertices, out triangles); AreaProperties ap = computeArea(out count, true); VolumeProperties vp = computeVolume(out count, true); HtmlGenerator generator = new HtmlGenerator(); generator.Units = model.Units.ToString().ToLower(); generator.SetTable(entities, vertices, triangles, ap.Area, vp.Volume); Bitmap bitmap; bitmap = printScreen(); generator.SetImage(bitmap); generator.Generate(); }
public bool MapMassToArea() { bool mapped = false; try { List <Element> areas = settings.SelectedElements; if (areas.Count > 0) { foreach (Element element in areas) { progressBar.PerformStep(); Area area = element as Area; if (area.Area == 0) { continue; } #if RELEASE2015 || RELEASE2016 || RELEASE2017 if (null == area.LookupParameter("Plot Code")) { MessageBox.Show("Cannot find a parameter named Plot Code in Area elements\n Please add required parameters in both Area and Mass to calculate FAR." , "Missing Parameter: Plot Code", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } string plotCode = area.LookupParameter("Plot Code").AsString(); #else if (null == area.get_Parameter("Plot Code")) { MessageBox.Show("Cannot find a parameter named Plot Code in Area elements\n Please add required parameters in both Area and Mass to calculate FAR." , "Missing Parameter: Plot Code", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } string plotCode = area.get_Parameter("Plot Code").AsString(); #endif if (plotCode == null || plotCode == "0") { continue; } minXYZ = new XYZ(); maxXYZ = new XYZ(); IList <CurveLoop> profiles = CreateProfiles(area); Solid extrusion = null; if (profiles.Count > 0) { try { extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(profiles, XYZ.BasisZ, 100); } catch { extrusion = null; return(false); } } if (null != extrusion && !areaDictionary.ContainsKey(area.Id.IntegerValue)) { AreaProperties ap = new AreaProperties(area); ap.SolidArea = extrusion; ap.BaseFace = GetBottomFace(extrusion); ap.MassIDs = FindMass(ap); ap.FAR = CalculateFAR(ap); ap.FARParameter = ap.FAR; areaDictionary.Add(ap.AreaId, ap); } } } mapped = true; } catch (Exception ex) { MessageBox.Show("Failed to map between areas and mass object to write plot codes.\n" + ex.Message, "FARCalcuator:MapMassToArea", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(mapped); }
public bool AnalysisByElements() { bool result = false; try { if (areaDictionary.Count > 0) { int resultIndex = FindIndexOfResult(sfm); bool firstLoop = true; foreach (int areaId in areaDictionary.Keys) { AreaProperties ap = areaDictionary[areaId]; List <double> dblList = new List <double>(); //double values to be displayed on the face. Face face = ap.BaseFace; dblList.Add(ap.FAR); if (dblList.Count != sfm.NumberOfMeasurements) { continue; } int index = sfm.AddSpatialFieldPrimitive(face, Transform.Identity); IList <UV> uvPts = new List <UV>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); BoundingBoxUV bb = face.GetBoundingBox(); UV faceCenter = (bb.Min + bb.Max) / 2; //only collect a center point. uvPts.Add(faceCenter); valList.Add(new ValueAtPoint(dblList)); //dblList.Clear(); FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPts); FieldValues values = new FieldValues(valList); AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription); resultSchema.SetUnits(unitNames, multipliers); if (unitNames.Contains(settings.Units)) { resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units); } if (overwriteResult) { sfm.SetResultSchema(resultIndex, resultSchema); } else if (firstLoop) { resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false; } else { sfm.SetResultSchema(resultIndex, resultSchema); } sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex); } SetCurrentStyle(); result = true; } } catch (Exception ex) { MessageBox.Show("Failed to visulaize the FAR data. \n" + ex.Message, "FARCalculator : AnalysisByElements", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(result); }
//累加模型面积 private int AddAreaProperty(AreaProperties ap, Entity ent, out bool blockReferenceNotScaled, bool isParentSelected = false, bool all = false) { int count = 0; blockReferenceNotScaled = true; if (all || ent.Selected || isParentSelected) { if (ent is IFace) { IFace itfFace = (IFace)ent; Mesh[] meshes = itfFace.GetPolygonMeshes(); foreach (Mesh mesh in meshes) { ap.Add(mesh.Vertices, mesh.Triangles); } count++; } else if (ent is BlockReference) { var br = (BlockReference)ent; if (br.GetScaleFactorX() != 1 && br.GetScaleFactorY() != 1 && br.GetScaleFactorZ() != 1) { blockReferenceNotScaled = false; return(count); } foreach (var e in br.GetEntities(model.Blocks)) { count += AddAreaProperty(ap, e, out blockReferenceNotScaled, true); if (!blockReferenceNotScaled) { return(count); } } } else { ICurve itfCurve = (ICurve)ent; if (itfCurve.IsClosed) { ap.Add(ent.Vertices); } count++; } } else if (ent is Brep) { Brep brep = (Brep)ent; for (int j = 0; j < brep.Faces.Length; j++) { Brep.Face sf = brep.Faces[j]; Mesh[] faceTessellation = sf.Tessellation; if (brep.GetFaceSelection(j)) { foreach (Mesh m in faceTessellation) { ap.Add(m.Vertices, m.Triangles); } count++; } } } return(count); }
static public AreaProperties GetAreaProperties(string areaPath) { return(AreaProperties.Load(areaPath)); }
private void areaButton_Click(object sender, EventArgs e) { AreaProperties ap = new AreaProperties(); int count = 0; var blockReferenceNotScaled = true; for (int i = 0; i < model1.Entities.Count && blockReferenceNotScaled; i++) { Entity ent = model1.Entities[i]; count += AddAreaProperty(ap, ent, out blockReferenceNotScaled); } StringBuilder text = new StringBuilder(); if (blockReferenceNotScaled) { text.AppendLine(count + " entity(ies) selected"); text.AppendLine("---------------------"); if (ap.Centroid != null) { double x, y, z; double xx, yy, zz, xy, zx, yz; MomentOfInertia world, centroid; ap.GetResults(ap.Area, ap.Centroid, out x, out y, out z, out xx, out yy, out zz, out xy, out zx, out yz, out world, out centroid); text.AppendLine("Cumulative area: " + ap.Area + " square " + model1.Units.ToString().ToLower()); text.AppendLine("Cumulative centroid: " + ap.Centroid); text.AppendLine("Cumulative area moments:"); text.AppendLine(" First moments"); text.AppendLine(" x: " + x.ToString("g6")); text.AppendLine(" y: " + y.ToString("g6")); text.AppendLine(" z: " + z.ToString("g6")); text.AppendLine(" Second moments"); text.AppendLine(" xx: " + xx.ToString("g6")); text.AppendLine(" yy: " + yy.ToString("g6")); text.AppendLine(" zz: " + zz.ToString("g6")); text.AppendLine(" Product moments"); text.AppendLine(" xy: " + xx.ToString("g6")); text.AppendLine(" yz: " + yy.ToString("g6")); text.AppendLine(" zx: " + zz.ToString("g6")); text.AppendLine(" Area Moments of Inertia about World Coordinate Axes"); text.AppendLine(" Ix: " + world.Ix.ToString("g6")); text.AppendLine(" Iy: " + world.Iy.ToString("g6")); text.AppendLine(" Iz: " + world.Iz.ToString("g6")); text.AppendLine(" Area Radii of Gyration about World Coordinate Axes"); text.AppendLine(" Rx: " + world.Rx.ToString("g6")); text.AppendLine(" Ry: " + world.Ry.ToString("g6")); text.AppendLine(" Rz: " + world.Rz.ToString("g6")); text.AppendLine(" Area Moments of Inertia about Centroid Coordinate Axes:"); text.AppendLine(" Ix: " + centroid.Ix.ToString("g6")); text.AppendLine(" Iy: " + centroid.Iy.ToString("g6")); text.AppendLine(" Iz: " + centroid.Iz.ToString("g6")); text.AppendLine(" Area Radii of Gyration about Centroid Coordinate Axes"); text.AppendLine(" Rx: " + centroid.Rx.ToString("g6")); text.AppendLine(" Ry: " + centroid.Ry.ToString("g6")); text.AppendLine(" Rz: " + centroid.Rz.ToString("g6")); } } else { text.AppendLine("Error: scaled BlockReference is not supported."); text.AppendLine("---------------------"); } DetailsForm rf = new DetailsForm(); rf.Text = "Area Properties"; rf.textBox1.Text = text.ToString(); rf.Show(); }
private void areaButton_OnClick(object sender, RoutedEventArgs e) { AreaProperties ap = new AreaProperties(); int count = 0; for (int i = 0; i < model1.Entities.Count; i++) { Entity ent = model1.Entities[i]; if (ent.Selected) { ICurve itfCurve = (ICurve)ent; if (itfCurve.IsClosed) { ap.Add(ent.Vertices); } count++; } } StringBuilder text = new StringBuilder(); text.AppendLine(count + " entity(ies) selected"); text.AppendLine("---------------------"); if (ap.Centroid != null) { double x, y, z; double xx, yy, zz, xy, zx, yz; MomentOfInertia world, centroid; ap.GetResults(ap.Area, ap.Centroid, out x, out y, out z, out xx, out yy, out zz, out xy, out zx, out yz, out world, out centroid); text.AppendLine("Cumulative area: " + ap.Area + " square " + model1.Units.ToString().ToLower()); text.AppendLine("Cumulative centroid: " + ap.Centroid); text.AppendLine("Cumulative area moments:"); text.AppendLine(" First moments"); text.AppendLine(" x: " + x.ToString("g6")); text.AppendLine(" y: " + y.ToString("g6")); text.AppendLine(" z: " + z.ToString("g6")); text.AppendLine(" Second moments"); text.AppendLine(" xx: " + xx.ToString("g6")); text.AppendLine(" yy: " + yy.ToString("g6")); text.AppendLine(" zz: " + zz.ToString("g6")); text.AppendLine(" Product moments"); text.AppendLine(" xy: " + xx.ToString("g6")); text.AppendLine(" yz: " + yy.ToString("g6")); text.AppendLine(" zx: " + zz.ToString("g6")); text.AppendLine(" Area Moments of Inertia about World Coordinate Axes"); text.AppendLine(" Ix: " + world.Ix.ToString("g6")); text.AppendLine(" Iy: " + world.Iy.ToString("g6")); text.AppendLine(" Iz: " + world.Iz.ToString("g6")); text.AppendLine(" Area Radii of Gyration about World Coordinate Axes"); text.AppendLine(" Rx: " + world.Rx.ToString("g6")); text.AppendLine(" Ry: " + world.Ry.ToString("g6")); text.AppendLine(" Rz: " + world.Rz.ToString("g6")); text.AppendLine(" Area Moments of Inertia about Centroid Coordinate Axes:"); text.AppendLine(" Ix: " + centroid.Ix.ToString("g6")); text.AppendLine(" Iy: " + centroid.Iy.ToString("g6")); text.AppendLine(" Iz: " + centroid.Iz.ToString("g6")); text.AppendLine(" Area Radii of Gyration about Centroid Coordinate Axes"); text.AppendLine(" Rx: " + centroid.Rx.ToString("g6")); text.AppendLine(" Ry: " + centroid.Ry.ToString("g6")); text.AppendLine(" Rz: " + centroid.Rz.ToString("g6")); } DetailsWindow rf = new DetailsWindow(); rf.Title = "Area Properties"; rf.contentTextBox.Text = text.ToString(); rf.Show(); }