//--啟用牆的分析模型 public void OpenWallStructuralSignificant(Wall wall) { try { wall.get_Parameter(BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT).Set(1); wall.get_Parameter(BuiltInParameter.STRUCTURAL_ANALYTICAL_MODEL).Set(1); //--修正分析牆對齊方式 AnalyticalModelSurface analyticalModelSurface = wall.GetAnalyticalModel() as AnalyticalModelSurface; if (analyticalModelSurface != null) { //--對齊方式改為投影 analyticalModelSurface.AlignmentMethod = AnalyticalAlignmentMethod.Projection; //--Z方向投影改為元素的中心 analyticalModelSurface.ProjectionZ = SurfaceElementProjectionZ.CenterOfElement; //--修正分析牆延伸方法投影 analyticalModelSurface.TopExtensionMethod = AnalyticalAlignmentMethod.Projection; analyticalModelSurface.BottomExtensionMethod = AnalyticalAlignmentMethod.Projection; } } catch (Exception ex) { MessageBox.Show($"啟用牆的分析物件發生錯誤\n{ex}", "錯誤訊息"); throw; } }
Stream(ArrayList data, AnalyticalModelSurface aModel) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModelSurface))); try { data.Add(new Snoop.Data.ElementId("BottomExtensionPlaneId", aModel.BottomExtensionPlaneId, aModel.Document)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("BottomExtensionPlaneId", ex)); } try { data.Add(new Snoop.Data.ElementId("TopExtensionPlaneId", aModel.TopExtensionPlaneId, aModel.Document)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("TopExtensionPlaneId", ex)); } try { data.Add(new Snoop.Data.String("ProjectionZ", aModel.ProjectionZ.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("ProjectionZ", ex)); } try { data.Add(new Snoop.Data.String("BottomExtension", aModel.BottomExtension.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("BottomExtension", ex)); } try { data.Add(new Snoop.Data.String("TopExtension", aModel.TopExtension.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("TopExtension", ex)); } try { data.Add(new Snoop.Data.String("AlignmentMethod", aModel.AlignmentMethod.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("AlignmentMethod", ex)); } // data.Add(new Snoop.Data.Enumerable("Outer Loops", aModel.GetLoops(AnalyticalLoopType.External))); data.Add(new Snoop.Data.Enumerable("Inner Loops", aModel.GetLoops(AnalyticalLoopType.Internal))); System.Collections.Generic.ICollection <ElementId> openingIds = new System.Collections.Generic.List <ElementId>(); aModel.GetOpenings(out openingIds); data.Add(new Snoop.Data.Enumerable("Openings", openingIds)); System.Collections.Generic.ICollection <ElementId> hiddenOpeningIds = new System.Collections.Generic.List <ElementId>(); aModel.GetHiddenOpenings(out hiddenOpeningIds); data.Add(new Snoop.Data.Enumerable("Hidden Openings", hiddenOpeningIds)); }
//--取出分析模型的內側邊界 public IList <CurveLoop> GetInternalBoundary(Floor floor) { //--得到分析模型的表面 AnalyticalModelSurface analyticalModelSurface = floor.GetAnalyticalModel() as AnalyticalModelSurface; //--得到分析模型表面的IList<CurveLoop> IList <CurveLoop> analyticalFloorLoops = analyticalModelSurface.GetLoops(AnalyticalLoopType.Internal); return(analyticalFloorLoops); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { Debug.Assert(false, "This has not been tested since Revit 2010!"); UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; Autodesk.Revit.Creation.Application ca = app.Application.Create; Autodesk.Revit.Creation.Document cd = doc.Create; // determine line load symbol to use: FilteredElementCollector symbols = new FilteredElementCollector(doc); symbols.OfClass(typeof(LineLoadType)); LineLoadType loadSymbol = symbols.FirstElement() as LineLoadType; // sketch plane and arrays of forces and moments: //Plane plane = ca.NewPlane( XYZ.BasisZ, XYZ.Zero ); // 2016 Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); // 2017 using (Transaction t = new Transaction(doc)) { t.Start("Create New Line Load"); //SketchPlane skplane = cd.NewSketchPlane( plane ); // 2013 SketchPlane skplane = SketchPlane.Create(doc, plane); // 2014 XYZ forceA = new XYZ(0, 0, 5); XYZ forceB = new XYZ(0, 0, 10); List <XYZ> forces = new List <XYZ>(); forces.Add(forceA); forces.Add(forceB); XYZ momentA = new XYZ(0, 0, 0); XYZ momentB = new XYZ(0, 0, 0); List <XYZ> moments = new List <XYZ>(); moments.Add(momentA); moments.Add(momentB); BuiltInCategory bic = BuiltInCategory.OST_StructuralFraming; FilteredElementCollector beams = Util.GetElementsOfType( doc, typeof(FamilyInstance), bic); XYZ p1 = new XYZ(0, 0, 0); XYZ p2 = new XYZ(3, 0, 0); //List<XYZ> points = new List<XYZ>(); //points.Add( p1 ); //points.Add( p2 ); // create a new unhosted line load on points: //LineLoad lineLoadNoHost = cd.NewLineLoad( // points, forces, moments, // false, false, false, // loadSymbol, skplane ); // 2015 LineLoad lineLoadNoHost = LineLoad.Create(doc, p1, p2, forces[0], moments[0], loadSymbol, skplane); // 2016 Debug.Print("Unhosted line load works."); // create new line loads on beam: foreach (Element e in beams) { try { //LineLoad lineLoad = cd.NewLineLoad( // e, forces, moments, // false, false, false, // loadSymbol, skplane ); // 2015 AnalyticalModelSurface amsurf = e.GetAnalyticalModel() as AnalyticalModelSurface; LineLoad lineLoad = LineLoad.Create(doc, amsurf, 0, forces[0], moments[0], loadSymbol); // 2016 Debug.Print("Hosted line load on beam works."); } catch (Exception ex) { Debug.Print("Hosted line load on beam fails: " + ex.Message); } FamilyInstance i = e as FamilyInstance; AnalyticalModel am = i.GetAnalyticalModel(); foreach (Curve curve in am.GetCurves(AnalyticalCurveType.ActiveCurves)) { try { //LineLoad lineLoad = cd.NewLineLoad( // curve.Reference, forces, moments, // false, false, false, // loadSymbol, skplane ); // 2015 AnalyticalModelStick amstick = e.GetAnalyticalModel() as AnalyticalModelStick; LineLoad lineLoad = LineLoad.Create(doc, amstick, forces[0], moments[0], loadSymbol); // 2016 Debug.Print("Hosted line load on " + "AnalyticalModelFrame curve works."); } catch (Exception ex) { Debug.Print("Hosted line load on " + "AnalyticalModelFrame curve fails: " + ex.Message); } } } t.Commit(); } return(Result.Succeeded); }
private void Stream(ArrayList data, AnalyticalModelSurface aModel) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModelSurface))); try { data.Add(new Snoop.Data.ElementId("BottomExtensionPlaneId", aModel.BottomExtensionPlaneId, aModel.Document)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("BottomExtensionPlaneId", ex)); } try { data.Add(new Snoop.Data.ElementId("TopExtensionPlaneId", aModel.TopExtensionPlaneId, aModel.Document)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("TopExtensionPlaneId", ex)); } try { data.Add(new Snoop.Data.String("ProjectionZ", aModel.ProjectionZ.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("ProjectionZ", ex)); } try { data.Add(new Snoop.Data.String("BottomExtension", aModel.BottomExtension.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("BottomExtension", ex)); }try { data.Add(new Snoop.Data.String("TopExtension", aModel.TopExtension.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("TopExtension", ex)); } try { data.Add(new Snoop.Data.String("AlignmentMethod", aModel.AlignmentMethod.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("AlignmentMethod", ex)); } // data.Add(new Snoop.Data.Enumerable("Outer Loops", aModel.GetLoops(AnalyticalLoopType.External))); data.Add(new Snoop.Data.Enumerable("Inner Loops", aModel.GetLoops(AnalyticalLoopType.Internal))); System.Collections.Generic.ICollection<ElementId> openingIds = new System.Collections.Generic.List<ElementId>(); aModel.GetOpenings(out openingIds); data.Add(new Snoop.Data.Enumerable("Openings", openingIds)); System.Collections.Generic.ICollection<ElementId> hiddenOpeningIds = new System.Collections.Generic.List<ElementId>(); aModel.GetHiddenOpenings(out hiddenOpeningIds); data.Add(new Snoop.Data.Enumerable("Hidden Openings", hiddenOpeningIds)); }
public static List <SpeckleObject> ToSpeckle(this AnalyticalModelSurface mySurface) { var returnObjects = new List <SpeckleObject>(); if (!mySurface.IsEnabled()) { return(new List <SpeckleObject>()); } // Get the family var myRevitElement = Doc.GetElement(mySurface.GetElementId()); var type = Structural2DElementType.Generic; if (myRevitElement is Floor) { type = Structural2DElementType.Slab; } else if (myRevitElement is Wall) { type = Structural2DElementType.Wall; } // Voids first var voidLoops = mySurface.GetLoops(AnalyticalLoopType.Void); foreach (var loop in voidLoops) { var coor = new List <double>(); foreach (var curve in loop) { var points = curve.Tessellate(); foreach (var p in points.Skip(1)) { coor.Add(p.X / Scale); coor.Add(p.Y / Scale); coor.Add(p.Z / Scale); } } returnObjects.Add(new Structural2DVoid(coor.ToArray(), null)); } var polylines = new List <double[]>(); var loops = mySurface.GetLoops(AnalyticalLoopType.External); foreach (var loop in loops) { var coor = new List <double>(); foreach (var curve in loop) { var points = curve.Tessellate(); foreach (var p in points.Skip(1)) { coor.Add(p.X / Scale); coor.Add(p.Y / Scale); coor.Add(p.Z / Scale); } } polylines.Add(coor.ToArray()); } var coordinateSystem = mySurface.GetLocalCoordinateSystem(); var axis = coordinateSystem == null ? null : new StructuralAxis( new StructuralVectorThree(new double[] { coordinateSystem.BasisX.X, coordinateSystem.BasisX.Y, coordinateSystem.BasisX.Z }), new StructuralVectorThree(new double[] { coordinateSystem.BasisY.X, coordinateSystem.BasisY.Y, coordinateSystem.BasisY.Z }), new StructuralVectorThree(new double[] { coordinateSystem.BasisZ.X, coordinateSystem.BasisZ.Y, coordinateSystem.BasisZ.Z }) ); // Property string sectionID = null; try { var mySection = new Structural2DProperty(); mySection.Name = Doc.GetElement(myRevitElement.GetTypeId()).Name; mySection.ApplicationId = Doc.GetElement(myRevitElement.GetTypeId()).UniqueId; if (myRevitElement is Floor) { var myFloor = myRevitElement as Floor; mySection.Thickness = myFloor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM).AsDouble() / Scale; } else if (myRevitElement is Wall) { var myWall = myRevitElement as Wall; mySection.Thickness = myWall.WallType.Width / Scale; } try { // Material Material myMat = null; StructuralAsset matAsset = null; if (myRevitElement is Floor) { var myFloor = myRevitElement as Floor; myMat = Doc.GetElement(myFloor.FloorType.StructuralMaterialId) as Material; } else if (myRevitElement is Wall) { var myWall = myRevitElement as Wall; myMat = Doc.GetElement(myWall.WallType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()) as Material; } SpeckleObject myMaterial = null; matAsset = ((PropertySetElement)Doc.GetElement(myMat.StructuralAssetId)).GetStructuralAsset(); var matType = myMat.MaterialClass; switch (matType) { case "Concrete": var concMat = new StructuralMaterialConcrete(); concMat.ApplicationId = myMat.UniqueId; concMat.Name = Doc.GetElement(myMat.StructuralAssetId).Name; concMat.YoungsModulus = matAsset.YoungModulus.X; concMat.ShearModulus = matAsset.ShearModulus.X; concMat.PoissonsRatio = matAsset.PoissonRatio.X; concMat.Density = matAsset.Density; concMat.CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X; concMat.CompressiveStrength = matAsset.ConcreteCompression; concMat.MaxStrain = 0; concMat.AggragateSize = 0; myMaterial = concMat; break; case "Steel": var steelMat = new StructuralMaterialSteel(); steelMat.ApplicationId = myMat.UniqueId; steelMat.Name = Doc.GetElement(myMat.StructuralAssetId).Name; steelMat.YoungsModulus = matAsset.YoungModulus.X; steelMat.ShearModulus = matAsset.ShearModulus.X; steelMat.PoissonsRatio = matAsset.PoissonRatio.X; steelMat.Density = matAsset.Density; steelMat.CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X; steelMat.YieldStrength = matAsset.MinimumYieldStress; steelMat.UltimateStrength = matAsset.MinimumTensileStrength; steelMat.MaxStrain = 0; myMaterial = steelMat; break; default: var defMat = new StructuralMaterialSteel(); defMat.ApplicationId = myMat.UniqueId; defMat.Name = Doc.GetElement(myMat.StructuralAssetId).Name; myMaterial = defMat; break; } myMaterial.GenerateHash(); mySection.MaterialRef = (myMaterial as SpeckleObject).ApplicationId; returnObjects.Add(myMaterial); } catch { } mySection.GenerateHash(); sectionID = mySection.ApplicationId; returnObjects.Add(mySection); } catch { } var counter = 0; foreach (var coor in polylines) { var dummyMesh = new Structural2DElementMesh(coor, null, type, null, null, null); var numFaces = 0; for (var i = 0; i < dummyMesh.Faces.Count(); i++) { numFaces++; i += dummyMesh.Faces[i] + 3; } var mesh = new Structural2DElementMesh(); mesh.Vertices = dummyMesh.Vertices; mesh.Faces = dummyMesh.Faces; mesh.Colors = dummyMesh.Colors; mesh.ElementType = type; if (sectionID != null) { mesh.PropertyRef = sectionID; } if (axis != null) { mesh.Axis = Enumerable.Repeat(axis, numFaces).ToList(); } mesh.Offset = Enumerable.Repeat(0.0, numFaces).Cast <double>().ToList(); //TODO mesh.GenerateHash(); mesh.ApplicationId = mySurface.UniqueId + "_" + (counter++).ToString(); returnObjects.Add(mesh); } return(returnObjects); }
private Element2D AnalyticalSurfaceToSpeckle(AnalyticalModelSurface revitSurface) { if (!revitSurface.IsEnabled()) { return(new Element2D()); } var speckleElement2D = new Element2D(); var structuralElement = Doc.GetElement(revitSurface.GetElementId()); var mark = GetParamValue <string>(structuralElement, BuiltInParameter.ALL_MODEL_MARK); speckleElement2D.name = mark; var edgeNodes = new List <Node> { }; var loops = revitSurface.GetLoops(AnalyticalLoopType.External); var displayLine = new Polycurve(); foreach (var loop in loops) { var coor = new List <double>(); foreach (var curve in loop) { var points = curve.Tessellate(); foreach (var p in points.Skip(1)) { var vertex = PointToSpeckle(p); var edgeNode = new Node(vertex, null, null, null); edgeNodes.Add(edgeNode); } displayLine.segments.Add(CurveToSpeckle(curve)); } } speckleElement2D.topology = edgeNodes; speckleElement2D["displayValue"] = displayLine; var voidNodes = new List <List <Node> > { }; var voidLoops = revitSurface.GetLoops(AnalyticalLoopType.Void); foreach (var loop in voidLoops) { var loopNodes = new List <Node>(); foreach (var curve in loop) { var points = curve.Tessellate(); foreach (var p in points.Skip(1)) { var vertex = PointToSpeckle(p); var voidNode = new Node(vertex, null, null, null); loopNodes.Add(voidNode); } } voidNodes.Add(loopNodes); } //speckleElement2D.voids = voidNodes; //var mesh = new Geometry.Mesh(); //var solidGeom = GetElementSolids(structuralElement); //(mesh.faces, mesh.vertices) = GetFaceVertexArrFromSolids(solidGeom); //speckleElement2D.baseMesh = mesh; var prop = new Property2D(); // Material DB.Material structMaterial = null; double thickness = 0; var memberType = MemberType2D.Generic2D; if (structuralElement is DB.Floor) { var floor = structuralElement as DB.Floor; structMaterial = Doc.GetElement(floor.FloorType.StructuralMaterialId) as DB.Material; thickness = GetParamValue <double>(structuralElement, BuiltInParameter.STRUCTURAL_FLOOR_CORE_THICKNESS); memberType = MemberType2D.Slab; } else if (structuralElement is DB.Wall) { var wall = structuralElement as DB.Wall; structMaterial = Doc.GetElement(wall.WallType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()) as DB.Material; thickness = ScaleToSpeckle(wall.WallType.Width); memberType = MemberType2D.Wall; } var materialAsset = ((PropertySetElement)Doc.GetElement(structMaterial.StructuralAssetId)).GetStructuralAsset(); var materialType = structMaterial.MaterialClass; Structural.Materials.Material speckleMaterial = null; switch (materialType) { case "Concrete": var concreteMaterial = new Concrete { name = Doc.GetElement(structMaterial.StructuralAssetId).Name, //type = Structural.MaterialType.Concrete, grade = null, designCode = null, codeYear = null, elasticModulus = materialAsset.YoungModulus.X, compressiveStrength = materialAsset.ConcreteCompression, tensileStrength = 0, flexuralStrength = 0, maxCompressiveStrain = 0, maxTensileStrain = 0, maxAggregateSize = 0, lightweight = materialAsset.Lightweight, poissonsRatio = materialAsset.PoissonRatio.X, shearModulus = materialAsset.ShearModulus.X, density = materialAsset.Density, thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, dampingRatio = 0 }; speckleMaterial = concreteMaterial; break; case "Steel": var steelMaterial = new Steel { name = Doc.GetElement(structMaterial.StructuralAssetId).Name, //type = Structural.MaterialType.Steel, grade = materialAsset.Name, designCode = null, codeYear = null, elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter yieldStrength = materialAsset.MinimumYieldStress, // Newtons per foot meter ultimateStrength = materialAsset.MinimumTensileStrength, // Newtons per foot meter maxStrain = 0, poissonsRatio = materialAsset.PoissonRatio.X, shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter density = materialAsset.Density, // kilograms per cubed feet thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin dampingRatio = 0 }; speckleMaterial = steelMaterial; break; case "Wood": var timberMaterial = new Timber { name = Doc.GetElement(structMaterial.StructuralAssetId).Name, //type = Structural.MaterialType.Timber, grade = materialAsset.WoodGrade, designCode = null, codeYear = null, elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter poissonsRatio = materialAsset.PoissonRatio.X, shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter density = materialAsset.Density, // kilograms per cubed feet thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin species = materialAsset.WoodSpecies, dampingRatio = 0 }; timberMaterial["bendingStrength"] = materialAsset.WoodBendingStrength; timberMaterial["parallelCompressionStrength"] = materialAsset.WoodParallelCompressionStrength; timberMaterial["parallelShearStrength"] = materialAsset.WoodParallelShearStrength; timberMaterial["perpendicularCompressionStrength"] = materialAsset.WoodPerpendicularCompressionStrength; timberMaterial["perpendicularShearStrength"] = materialAsset.WoodPerpendicularShearStrength; speckleMaterial = timberMaterial; break; default: var defaultMaterial = new Structural.Materials.Material { name = Doc.GetElement(structMaterial.StructuralAssetId).Name }; speckleMaterial = defaultMaterial; break; } prop.material = speckleMaterial; prop.name = Doc.GetElement(revitSurface.GetElementId()).Name; //prop.type = memberType; //prop.analysisType = Structural.AnalysisType2D.Shell; prop.thickness = thickness; speckleElement2D.property = prop; GetAllRevitParamsAndIds(speckleElement2D, revitSurface); //speckleElement2D.displayMesh = GetElementDisplayMesh(Doc.GetElement(revitSurface.GetElementId()), // new Options() { DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false }); return(speckleElement2D); }