public List <ApplicationPlaceholderObject> AnalyticalStickToNative(Element1D speckleStick) { List <ApplicationPlaceholderObject> placeholderObjects = new List <ApplicationPlaceholderObject> { }; XYZ offset1 = VectorToNative(speckleStick.end1Offset); XYZ offset2 = VectorToNative(speckleStick.end2Offset); List <ApplicationPlaceholderObject> placeholders = new List <ApplicationPlaceholderObject> { }; switch (speckleStick.type) { case ElementType1D.Beam: RevitBeam revitBeam = new RevitBeam(); //This only works for CSIC sections now for sure. Need to test on other sections revitBeam.type = speckleStick.property.name.Replace('X', 'x'); revitBeam.baseLine = speckleStick.baseLine; //Beam beam = new Beam(speckleStick.baseLine); placeholders = BeamToNative(revitBeam); DB.FamilyInstance nativeRevitBeam = (DB.FamilyInstance)placeholders[0].NativeObject; AnalyticalModelStick analyticalModel = (AnalyticalModelStick)nativeRevitBeam.GetAnalyticalModel(); analyticalModel.SetReleases(true, Convert.ToBoolean(speckleStick.end1Releases.stiffnessX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end1Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZZ)); analyticalModel.SetReleases(false, Convert.ToBoolean(speckleStick.end2Releases.stiffnessX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end2Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZZ)); analyticalModel.SetOffset(AnalyticalElementSelector.StartOrBase, offset1); analyticalModel.SetOffset(AnalyticalElementSelector.EndOrTop, offset2); //analyticalModel. return(placeholders); case ElementType1D.Brace: RevitBrace revitBrace = new RevitBrace(); revitBrace.type = speckleStick.property.name.Replace('X', 'x'); revitBrace.baseLine = speckleStick.baseLine; //Brace brace = new Brace(speckleStick.baseLine); placeholders = BraceToNative(revitBrace); DB.FamilyInstance nativeRevitBrace = (DB.FamilyInstance)placeholders[0].NativeObject; analyticalModel = (AnalyticalModelStick)nativeRevitBrace.GetAnalyticalModel(); analyticalModel.SetReleases(true, Convert.ToBoolean(speckleStick.end1Releases.stiffnessX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end1Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZZ)); analyticalModel.SetReleases(false, Convert.ToBoolean(speckleStick.end2Releases.stiffnessX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end2Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZZ)); analyticalModel.SetOffset(AnalyticalElementSelector.StartOrBase, offset1); analyticalModel.SetOffset(AnalyticalElementSelector.EndOrTop, offset2); return(placeholders); case ElementType1D.Column: RevitColumn revitColumn = new RevitColumn(); revitColumn.type = speckleStick.property.name.Replace('X', 'x'); revitColumn.baseLine = speckleStick.baseLine; placeholders = ColumnToNative(revitColumn); DB.FamilyInstance nativeRevitColumn = (DB.FamilyInstance)placeholders[0].NativeObject; AnalyticalModelColumn analyticalModelCol = (AnalyticalModelColumn)nativeRevitColumn.GetAnalyticalModel(); analyticalModelCol.SetReleases(true, Convert.ToBoolean(speckleStick.end1Releases.stiffnessX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end1Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end1Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end1Releases.stiffnessZZ)); analyticalModelCol.SetReleases(false, Convert.ToBoolean(speckleStick.end2Releases.stiffnessX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZ), Convert.ToBoolean(speckleStick.end2Releases.stiffnessXX), Convert.ToBoolean(speckleStick.end2Releases.stiffnessYY), Convert.ToBoolean(speckleStick.end2Releases.stiffnessZZ)); analyticalModelCol.SetOffset(AnalyticalElementSelector.StartOrBase, offset1); analyticalModelCol.SetOffset(AnalyticalElementSelector.EndOrTop, offset2); return(placeholders); //Column column = new Column(speckleStick.baseLine); return(ColumnToNative(revitColumn)); } return(placeholderObjects); }
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 Element1D AnalyticalStickToSpeckle(AnalyticalModelStick revitStick) { if (!revitStick.IsEnabled()) { return(new Element1D()); } var speckleElement1D = new Element1D(); switch (revitStick.Category.Name) { case "Analytical Columns": speckleElement1D.type = ElementType1D.Column; break; case "Analytical Beams": speckleElement1D.type = ElementType1D.Beam; break; case "Analytical Braces": speckleElement1D.type = ElementType1D.Brace; break; default: speckleElement1D.type = ElementType1D.Other; break; } var curves = revitStick.GetCurves(AnalyticalCurveType.RigidLinkHead).ToList(); curves.AddRange(revitStick.GetCurves(AnalyticalCurveType.ActiveCurves)); curves.AddRange(revitStick.GetCurves(AnalyticalCurveType.RigidLinkTail)); if (curves.Count > 1) { speckleElement1D.baseLine = null; } else { speckleElement1D.baseLine = (Objects.Geometry.Line)CurveToSpeckle(curves[0]); } var coordinateSystem = revitStick.GetLocalCoordinateSystem(); if (coordinateSystem != null) { speckleElement1D.localAxis = new Geometry.Plane(PointToSpeckle(coordinateSystem.Origin), VectorToSpeckle(coordinateSystem.BasisZ), VectorToSpeckle(coordinateSystem.BasisX), VectorToSpeckle(coordinateSystem.BasisY)); } var startOffset = revitStick.GetOffset(AnalyticalElementSelector.StartOrBase); var endOffset = revitStick.GetOffset(AnalyticalElementSelector.EndOrTop); speckleElement1D.end1Offset = VectorToSpeckle(startOffset); speckleElement1D.end2Offset = VectorToSpeckle(endOffset); var startRelease = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_START_RELEASE_TYPE); var endRelease = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_END_RELEASE_TYPE); if (startRelease == 0) { speckleElement1D.end1Releases = new Restraint(RestraintType.Fixed); } else { var botReleaseX = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FX) == 1 ? "R" : "F"; var botReleaseY = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FY) == 1 ? "R" : "F"; var botReleaseZ = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FZ) == 1 ? "R" : "F"; var botReleaseXX = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MX) == 1 ? "R" : "F"; var botReleaseYY = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MY) == 1 ? "R" : "F"; var botReleaseZZ = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MZ) == 1 ? "R" : "F"; string botReleaseCode = botReleaseX + botReleaseY + botReleaseZ + botReleaseXX + botReleaseYY + botReleaseZZ; speckleElement1D.end1Releases = new Restraint(botReleaseCode); } if (endRelease == 0) { speckleElement1D.end2Releases = new Restraint(RestraintType.Fixed); } else { var topReleaseX = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_TOP_RELEASE_FX) == 1 ? "R" : "F"; var topReleaseY = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_TOP_RELEASE_FY) == 1 ? "R" : "F"; var topReleaseZ = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_TOP_RELEASE_FZ) == 1 ? "R" : "F"; var topReleaseXX = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_TOP_RELEASE_MX) == 1 ? "R" : "F"; var topReleaseYY = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_TOP_RELEASE_MY) == 1 ? "R" : "F"; var topReleaseZZ = GetParamValue <int>(revitStick, BuiltInParameter.STRUCTURAL_TOP_RELEASE_MZ) == 1 ? "R" : "F"; string topReleaseCode = topReleaseX + topReleaseY + topReleaseZ + topReleaseXX + topReleaseYY + topReleaseZZ; speckleElement1D.end2Releases = new Restraint(topReleaseCode); } var prop = new Property1D(); var stickFamily = (Autodesk.Revit.DB.FamilyInstance)Doc.GetElement(revitStick.GetElementId()); var section = stickFamily.Symbol.GetStructuralSection(); var speckleSection = new SectionProfile(); speckleSection.name = section.StructuralSectionShapeName; switch (section.StructuralSectionGeneralShape) { case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralI: // Double T structural sections var ISection = new ISection(); ISection.name = section.StructuralSectionShapeName; ISection.shapeType = Structural.ShapeType.I; ISection.depth = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("Height").GetValue(section); ISection.width = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("Width").GetValue(section); ISection.webThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("WebThickness").GetValue(section); ISection.flangeThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("FlangeThickness").GetValue(section); ISection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("SectionArea").GetValue(section); ISection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("NominalWeight").GetValue(section); ISection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); ISection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); ISection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralI).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = ISection; break; case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralT: // Tees structural sections var teeSection = new Tee(); teeSection.name = section.StructuralSectionShapeName; teeSection.shapeType = Structural.ShapeType.I; teeSection.depth = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("Height").GetValue(section); teeSection.width = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("Width").GetValue(section); teeSection.webThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("WebThickness").GetValue(section); teeSection.flangeThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("FlangeThickness").GetValue(section); teeSection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("SectionArea").GetValue(section); teeSection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("NominalWeight").GetValue(section); teeSection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); teeSection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); teeSection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralT).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = teeSection; break; case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralH: // Rectangular Pipe structural sections var rectSection = new Rectangular(); rectSection.name = section.StructuralSectionShapeName; rectSection.shapeType = Structural.ShapeType.I; rectSection.depth = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("Height").GetValue(section); rectSection.width = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("Width").GetValue(section); var wallThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("WallNominalThickness").GetValue(section); rectSection.webThickness = wallThickness; rectSection.flangeThickness = wallThickness; rectSection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("SectionArea").GetValue(section); rectSection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("NominalWeight").GetValue(section); rectSection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); rectSection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); rectSection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = rectSection; break; case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralR: // Pipe structural sections var circSection = new Circular(); circSection.name = section.StructuralSectionShapeName; circSection.shapeType = Structural.ShapeType.Circular; circSection.radius = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("Diameter").GetValue(section) / 2; circSection.wallThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("WallNominalThickness").GetValue(section); circSection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("SectionArea").GetValue(section); circSection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("NominalWeight").GetValue(section); circSection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); circSection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); circSection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = circSection; break; case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralF: // Flat Bar structural sections var flatRectSection = new Rectangular(); flatRectSection.name = section.StructuralSectionShapeName; flatRectSection.shapeType = Structural.ShapeType.I; flatRectSection.depth = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralF).GetProperty("Height").GetValue(section); flatRectSection.width = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralF).GetProperty("Width").GetValue(section); flatRectSection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralF).GetProperty("SectionArea").GetValue(section); flatRectSection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralF).GetProperty("NominalWeight").GetValue(section); flatRectSection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralF).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); flatRectSection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralF).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); flatRectSection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralF).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = flatRectSection; break; case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralS: // Round Bar structural sections var flatCircSection = new Circular(); flatCircSection.name = section.StructuralSectionShapeName; flatCircSection.shapeType = Structural.ShapeType.Circular; flatCircSection.radius = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralS).GetProperty("Diameter").GetValue(section) / 2; flatCircSection.wallThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralS).GetProperty("WallNominalThickness").GetValue(section); flatCircSection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralS).GetProperty("SectionArea").GetValue(section); flatCircSection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralS).GetProperty("NominalWeight").GetValue(section); flatCircSection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralS).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); flatCircSection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralS).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); flatCircSection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralS).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = flatCircSection; break; case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralW: // Angle structural sections var angleSection = new Angle(); angleSection.name = section.StructuralSectionShapeName; angleSection.shapeType = Structural.ShapeType.Angle; angleSection.depth = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("Height").GetValue(section); angleSection.width = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("Width").GetValue(section); angleSection.webThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("WebThickness").GetValue(section); angleSection.flangeThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("FlangeThickness").GetValue(section); angleSection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("SectionArea").GetValue(section); angleSection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("NominalWeight").GetValue(section); angleSection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); angleSection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); angleSection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralW).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = angleSection; break; case DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralU: // Channel structural sections var channelSection = new Channel(); channelSection.name = section.StructuralSectionShapeName; channelSection.shapeType = Structural.ShapeType.Channel; channelSection.depth = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("Height").GetValue(section); channelSection.width = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("Width").GetValue(section); channelSection.webThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("WebThickness").GetValue(section); channelSection.flangeThickness = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("FlangeThickness").GetValue(section); channelSection.area = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("SectionArea").GetValue(section); channelSection.weight = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("NominalWeight").GetValue(section); channelSection.Iyy = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("MomentOfInertiaStrongAxis").GetValue(section); channelSection.Izz = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("MomentOfInertiaWeakAxis").GetValue(section); channelSection.J = (double)typeof(DB.Structure.StructuralSections.StructuralSectionGeneralU).GetProperty("TorsionalMomentOfInertia").GetValue(section); speckleSection = channelSection; break; default: speckleSection.name = section.StructuralSectionShapeName; break; } var materialType = stickFamily.StructuralMaterialType; var structMat = (DB.Material)Doc.GetElement(stickFamily.StructuralMaterialId); if (structMat == null) { structMat = (DB.Material)Doc.GetElement(stickFamily.Symbol.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()); } var materialAsset = ((PropertySetElement)Doc.GetElement(structMat.StructuralAssetId)).GetStructuralAsset(); Structural.Materials.Material speckleMaterial = null; switch (materialType) { case StructuralMaterialType.Concrete: var concreteMaterial = new Concrete { name = Doc.GetElement(stickFamily.StructuralMaterialId).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 StructuralMaterialType.Steel: var steelMaterial = new Steel { name = Doc.GetElement(stickFamily.StructuralMaterialId).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 StructuralMaterialType.Wood: var timberMaterial = new Timber { name = Doc.GetElement(structMat.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 Objects.Structural.Materials.Material { name = Doc.GetElement(stickFamily.StructuralMaterialId).Name }; speckleMaterial = defaultMaterial; break; } prop.profile = speckleSection; prop.material = speckleMaterial; prop.name = Doc.GetElement(revitStick.GetElementId()).Name; var structuralElement = Doc.GetElement(revitStick.GetElementId()); var mark = GetParamValue <string>(structuralElement, BuiltInParameter.ALL_MODEL_MARK); if (revitStick is AnalyticalModelColumn) { speckleElement1D.type = ElementType1D.Column; //prop.memberType = MemberType.Column; var locationMark = GetParamValue <string>(structuralElement, BuiltInParameter.COLUMN_LOCATION_MARK); if (locationMark == null) { speckleElement1D.name = mark; } else { speckleElement1D.name = locationMark; } } else { prop.memberType = MemberType.Beam; speckleElement1D.name = mark; } speckleElement1D.property = prop; GetAllRevitParamsAndIds(speckleElement1D, revitStick); speckleElement1D.displayMesh = GetElementDisplayMesh(Doc.GetElement(revitStick.GetElementId())); return(speckleElement1D); }
private void Stream(ArrayList data, AnalyticalModelStick aModel) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModelStick))); try { data.Add(new Snoop.Data.String("GetAlignmentMethod-EndOrTop", aModel.GetAlignmentMethod(AnalyticalElementSelector.EndOrTop).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetAlignmentMethod-EndOrTop", ex)); } try { data.Add(new Snoop.Data.String("GetAlignmentMethod-StartOrBase", aModel.GetAlignmentMethod(AnalyticalElementSelector.StartOrBase).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetAlignmentMethod-StartOrBase", ex)); } try { data.Add(new Snoop.Data.String("GetAlignmentMethod-Whole ", aModel.GetAlignmentMethod(AnalyticalElementSelector.Whole).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetAlignmentMethod-Whole", ex)); } // try { data.Add(new Snoop.Data.String("GetProjectionY-EndOrTop", aModel.GetProjectionY(AnalyticalElementSelector.EndOrTop).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionY-EndOrTop", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionY-StartOrBase", aModel.GetProjectionY(AnalyticalElementSelector.StartOrBase).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionY-StartOrBase", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionY-Whole ", aModel.GetProjectionY(AnalyticalElementSelector.Whole).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionY-Whole", ex)); } // try { data.Add(new Snoop.Data.String("GetProjectionZ-EndOrTop", aModel.GetProjectionZ(AnalyticalElementSelector.EndOrTop).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionZ-EndOrTop", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionZ-StartOrBase", aModel.GetProjectionZ(AnalyticalElementSelector.StartOrBase).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionZ-StartOrBase", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionZ-Whole ", aModel.GetProjectionZ(AnalyticalElementSelector.Whole).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionZ-Whole", ex)); } if (aModel is AnalyticalModelColumn) Stream(data, (AnalyticalModelColumn)aModel); }
Stream(ArrayList data, AnalyticalModelStick aModel) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModelStick))); try { data.Add(new Snoop.Data.String("GetAlignmentMethod-EndOrTop", aModel.GetAlignmentMethod(AnalyticalElementSelector.EndOrTop).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetAlignmentMethod-EndOrTop", ex)); } try { data.Add(new Snoop.Data.String("GetAlignmentMethod-StartOrBase", aModel.GetAlignmentMethod(AnalyticalElementSelector.StartOrBase).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetAlignmentMethod-StartOrBase", ex)); } try { data.Add(new Snoop.Data.String("GetAlignmentMethod-Whole ", aModel.GetAlignmentMethod(AnalyticalElementSelector.Whole).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetAlignmentMethod-Whole", ex)); } // try { data.Add(new Snoop.Data.String("GetProjectionY-EndOrTop", aModel.GetProjectionY(AnalyticalElementSelector.EndOrTop).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionY-EndOrTop", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionY-StartOrBase", aModel.GetProjectionY(AnalyticalElementSelector.StartOrBase).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionY-StartOrBase", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionY-Whole ", aModel.GetProjectionY(AnalyticalElementSelector.Whole).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionY-Whole", ex)); } // try { data.Add(new Snoop.Data.String("GetProjectionZ-EndOrTop", aModel.GetProjectionZ(AnalyticalElementSelector.EndOrTop).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionZ-EndOrTop", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionZ-StartOrBase", aModel.GetProjectionZ(AnalyticalElementSelector.StartOrBase).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionZ-StartOrBase", ex)); } try { data.Add(new Snoop.Data.String("GetProjectionZ-Whole ", aModel.GetProjectionZ(AnalyticalElementSelector.Whole).ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GetProjectionZ-Whole", ex)); } if (aModel is AnalyticalModelColumn) { Stream(data, (AnalyticalModelColumn)aModel); } }
public static List <SpeckleObject> ToSpeckle(this AnalyticalModelStick myStick) { var returnObjects = new List <SpeckleObject>(); if (!myStick.IsEnabled()) { return(new List <SpeckleObject>()); } // Get the family var myFamily = (FamilyInstance)Doc.GetElement(myStick.GetElementId()); var myElement = new Structural1DElementPolyline { Value = new List <double>() }; var curves = myStick.GetCurves(AnalyticalCurveType.RigidLinkHead).ToList(); curves.AddRange(myStick.GetCurves(AnalyticalCurveType.ActiveCurves)); curves.AddRange(myStick.GetCurves(AnalyticalCurveType.RigidLinkTail)); foreach (var curve in curves) { var points = curve.Tessellate(); if (points.Count == 0) { continue; } if (myElement.Value.Count == 0) { myElement.Value.Add(points[0].X / Scale); myElement.Value.Add(points[0].Y / Scale); myElement.Value.Add(points[0].Z / Scale); } foreach (var p in points.Skip(1)) { myElement.Value.Add(p.X / Scale); myElement.Value.Add(p.Y / Scale); myElement.Value.Add(p.Z / Scale); } } myElement.ResultVertices = new List <double>(myElement.Value); var vertexCount = myElement.Value.Count / 3; var coordinateSystem = myStick.GetLocalCoordinateSystem(); if (coordinateSystem != null) { myElement.ZAxis = Enumerable.Repeat(new StructuralVectorThree(new double[] { coordinateSystem.BasisZ.X, coordinateSystem.BasisZ.Y, coordinateSystem.BasisZ.Z }), (vertexCount - 1)).ToList(); } try { var offset1 = myStick.GetOffset(AnalyticalElementSelector.StartOrBase); var offset2 = myStick.GetOffset(AnalyticalElementSelector.EndOrTop); // TODO: This should be linear interpolation? var fillerList = Enumerable.Repeat(new StructuralVectorThree(new double[] { 0, 0, 0 }), (vertexCount - 1) * 2 - 2).ToList(); myElement.Offset = new List <StructuralVectorThree>() { new StructuralVectorThree(new double[] { offset1.X / Scale, offset1.Y / Scale, offset1.Z / Scale }) } .Concat(fillerList) .Concat(new List <StructuralVectorThree>() { new StructuralVectorThree(new double[] { offset2.X / Scale, offset2.Y / Scale, offset2.Z / Scale }) }).ToList(); } catch { try { var offset = myStick.GetOffset(AnalyticalElementSelector.Whole); myElement.Offset = Enumerable.Repeat(new StructuralVectorThree(new double[] { offset.X / Scale, offset.Y / Scale, offset.Z / Scale }), (vertexCount - 1) * 2).ToList(); } catch { } } if (myStick is AnalyticalModelColumn) { StructuralVectorBoolSix endRelease1 = null, endRelease2 = null; switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_TYPE).AsInteger()) { case 0: endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }); break; case 1: endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true }); break; case 2: endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true }); break; case 3: endRelease1 = new StructuralVectorBoolSix(new bool[] { myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_FZ).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_BOTTOM_RELEASE_MZ).AsInteger() == 1, }); break; } switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_TYPE).AsInteger()) { case 0: endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }); break; case 1: endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true }); break; case 2: endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true }); break; case 3: endRelease2 = new StructuralVectorBoolSix(new bool[] { myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_FX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_FY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_FZ).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_MX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_MY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_TOP_RELEASE_MZ).AsInteger() == 1, }); break; } var fillerList = Enumerable.Repeat(new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }), (vertexCount - 1) * 2 - 2).ToList(); myElement.EndRelease = new List <StructuralVectorBoolSix>() { endRelease1 }.Concat(fillerList).Concat(new List <StructuralVectorBoolSix>() { endRelease2 }).ToList(); } else { StructuralVectorBoolSix endRelease1 = null, endRelease2 = null; switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_TYPE).AsInteger()) { case 0: endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }); break; case 1: endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true }); break; case 2: endRelease1 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true }); break; case 3: endRelease1 = new StructuralVectorBoolSix(new bool[] { myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_FX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_FY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_FZ).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_MX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_MY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_START_RELEASE_MZ).AsInteger() == 1, }); break; } switch (myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_TYPE).AsInteger()) { case 0: endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }); break; case 1: endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, true, true, true }); break; case 2: endRelease2 = new StructuralVectorBoolSix(new bool[] { false, false, false, false, true, true }); break; case 3: endRelease2 = new StructuralVectorBoolSix(new bool[] { myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_FX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_FY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_FZ).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_MX).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_MY).AsInteger() == 1, myStick.get_Parameter(BuiltInParameter.STRUCTURAL_END_RELEASE_MZ).AsInteger() == 1, }); break; } var fillerList = Enumerable.Repeat(new StructuralVectorBoolSix(new bool[] { false, false, false, false, false, false }), (vertexCount - 1) * 2 - 2).ToList(); myElement.EndRelease = new List <StructuralVectorBoolSix>() { endRelease1 }.Concat(fillerList).Concat(new List <StructuralVectorBoolSix>() { endRelease2 }).ToList(); } // Property try { var mySection = new Structural1DProperty { Name = Doc.GetElement(myStick.GetElementId()).Name, ApplicationId = myFamily.Symbol.UniqueId }; switch (myFamily.Symbol.GetStructuralSection().StructuralSectionGeneralShape) { case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralI: mySection.Shape = Structural1DPropertyShape.I; mySection.Hollow = false; break; case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralT: mySection.Shape = Structural1DPropertyShape.T; mySection.Hollow = false; break; case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralH: mySection.Shape = Structural1DPropertyShape.Rectangular; mySection.Hollow = true; mySection.Thickness = (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralH).GetProperty("WallNominalThickness").GetValue(myFamily.Symbol.GetStructuralSection()) / Scale; break; case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralR: mySection.Shape = Structural1DPropertyShape.Circular; mySection.Hollow = true; mySection.Thickness = (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("WallNominalThickness").GetValue(myFamily.Symbol.GetStructuralSection()) / Scale; mySection.Profile = new SpeckleCircle( new SpecklePlane(new SpecklePoint(0, 0, 0), new SpeckleVector(0, 0, 1), new SpeckleVector(1, 0, 0), new SpeckleVector(0, 1, 0)), (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("Diameter").GetValue(myFamily.Symbol.GetStructuralSection()) / 2 / Scale); break; case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralF: mySection.Shape = Structural1DPropertyShape.Rectangular; mySection.Hollow = false; break; case Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralShape.GeneralS: mySection.Shape = Structural1DPropertyShape.Circular; mySection.Profile = new SpeckleCircle( new SpecklePlane(new SpecklePoint(0, 0, 0), new SpeckleVector(0, 0, 1), new SpeckleVector(1, 0, 0), new SpeckleVector(0, 1, 0)), (double)typeof(Autodesk.Revit.DB.Structure.StructuralSections.StructuralSectionGeneralR).GetProperty("Diameter").GetValue(myFamily.Symbol.GetStructuralSection()) / 2 / Scale); mySection.Hollow = false; break; default: mySection.Shape = Structural1DPropertyShape.Generic; mySection.Hollow = false; break; } // Generate section profile var profile = myFamily.GetSweptProfile().GetSweptProfile(); if (mySection.Shape != Structural1DPropertyShape.Circular) { var myProfile = new SpecklePolyline { Value = new List <double>() }; for (var i = 0; i < profile.Curves.Size; i++) { var sectionCurves = SpeckleCore.Converter.Serialise(profile.Curves.get_Item(i)); var sectionCoordinates = new List <double>(); var nextCoordinates = new List <double>(); if (sectionCurves is SpeckleLine) { sectionCoordinates = (sectionCurves as SpeckleLine).Value.Select(x => Math.Round(x, 10)).ToList(); if (myProfile.Value.Count == 0) { myProfile.Value = sectionCoordinates; continue; } if (myProfile.Value.Skip(myProfile.Value.Count - 3).SequenceEqual(sectionCoordinates.Take(3))) { nextCoordinates = sectionCoordinates.Skip(3).ToList(); } else { break; } } else if (sectionCurves is SpeckleArc) { if (myProfile.Value.Count == 0) { myProfile.Value = (sectionCurves as SpeckleArc).StartPoint.Value.Select(x => Math.Round(x, 10)) .Concat((sectionCurves as SpeckleArc).MidPoint.Value.Select(x => Math.Round(x, 10))) .Concat((sectionCurves as SpeckleArc).EndPoint.Value.Select(x => Math.Round(x, 10))) .ToList(); continue; } if (myProfile.Value.Skip(myProfile.Value.Count - 3).SequenceEqual((sectionCurves as SpeckleArc).StartPoint.Value.Select(x => Math.Round(x, 10)))) { nextCoordinates = (sectionCurves as SpeckleArc).EndPoint.Value.Select(x => Math.Round(x, 10)).ToList(); } else if (myProfile.Value.Skip(myProfile.Value.Count - 3).SequenceEqual((sectionCurves as SpeckleArc).EndPoint.Value.Select(x => Math.Round(x, 10)))) { nextCoordinates = (sectionCurves as SpeckleArc).StartPoint.Value.Select(x => Math.Round(x, 10)).ToList(); } else { break; } } if (nextCoordinates.SequenceEqual(myProfile.Value.Take(3))) { myProfile.Closed = true; break; } else { myProfile.Value.AddRange(nextCoordinates); } } myProfile.GenerateHash(); mySection.Profile = myProfile; } // Material try { var matType = myFamily.StructuralMaterialType; var structMat = (Material)Doc.GetElement(myFamily.StructuralMaterialId); if (structMat == null) { structMat = (Material)Doc.GetElement(myFamily.Symbol.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()); } var matAsset = ((PropertySetElement)Doc.GetElement(structMat.StructuralAssetId)).GetStructuralAsset(); SpeckleObject myMaterial = null; switch (matType) { case Autodesk.Revit.DB.Structure.StructuralMaterialType.Concrete: var concMat = new StructuralMaterialConcrete { ApplicationId = Doc.GetElement(myFamily.StructuralMaterialId).UniqueId, Name = Doc.GetElement(myFamily.StructuralMaterialId).Name, YoungsModulus = matAsset.YoungModulus.X, ShearModulus = matAsset.ShearModulus.X, PoissonsRatio = matAsset.PoissonRatio.X, Density = matAsset.Density, CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X, CompressiveStrength = matAsset.ConcreteCompression, MaxStrain = 0, AggragateSize = 0 }; myMaterial = concMat; break; case Autodesk.Revit.DB.Structure.StructuralMaterialType.Steel: var steelMat = new StructuralMaterialSteel { ApplicationId = Doc.GetElement(myFamily.StructuralMaterialId).UniqueId, Name = Doc.GetElement(myFamily.StructuralMaterialId).Name, YoungsModulus = matAsset.YoungModulus.X, ShearModulus = matAsset.ShearModulus.X, PoissonsRatio = matAsset.PoissonRatio.X, Density = matAsset.Density, CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X, YieldStrength = matAsset.MinimumYieldStress, UltimateStrength = matAsset.MinimumTensileStrength, MaxStrain = 0 }; myMaterial = steelMat; break; default: var defMat = new StructuralMaterialSteel { ApplicationId = Doc.GetElement(myFamily.StructuralMaterialId).UniqueId, Name = Doc.GetElement(myFamily.StructuralMaterialId).Name }; myMaterial = defMat; break; } myMaterial.GenerateHash(); mySection.MaterialRef = (myMaterial as SpeckleObject).ApplicationId; returnObjects.Add(myMaterial); } catch { } mySection.GenerateHash(); myElement.PropertyRef = mySection.ApplicationId; returnObjects.Add(mySection); } catch { } myElement.GenerateHash(); myElement.ApplicationId = myStick.UniqueId; returnObjects.Add(myElement); return(returnObjects); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static List <Bar> BarsFromRevit(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); List <Bar> bars = refObjects.GetValues <Bar>(familyInstance.Id); if (bars != null) { return(bars); } // Get bar curve oM.Geometry.ICurve locationCurve = null; AnalyticalModelStick analyticalModel = familyInstance.GetAnalyticalModel() as AnalyticalModelStick; if (analyticalModel != null) { Curve curve = analyticalModel.GetCurve(); if (curve != null) { locationCurve = curve.IFromRevit(); } } if (locationCurve != null) { familyInstance.AnalyticalPullWarning(); } else { locationCurve = familyInstance.LocationCurve(settings); } // Get bar material ElementId structuralMaterialId = familyInstance.StructuralMaterialId; if (structuralMaterialId.IntegerValue < 0) { structuralMaterialId = familyInstance.Symbol.LookupParameterElementId(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM); } Material revitMaterial = familyInstance.Document.GetElement(structuralMaterialId) as Material; if (revitMaterial == null) { revitMaterial = familyInstance.Category.Material; } // Get material grade string materialGrade = familyInstance.MaterialGrade(settings); // Find material fragment: convert the material assigned to the element, if that returns null try finding a material in the library, based on the material type assigned to the family. IMaterialFragment materialFragment = revitMaterial.MaterialFragmentFromRevit(materialGrade, settings, refObjects); if (materialFragment == null) { materialFragment = familyInstance.StructuralMaterialType.LibraryMaterial(materialGrade); } // If material fragment could not be found create an empty one and raise a warning further down the line. bool materialFound = materialFragment != null; if (materialFragment == null) { materialFragment = familyInstance.StructuralMaterialType.EmptyMaterialFragment(materialGrade); } // Get bar profile and create property string profileName = familyInstance.Symbol.Name; ISectionProperty property = BH.Engine.Library.Query.Match("SectionProperties", profileName) as ISectionProperty; if (property == null) { IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects); //TODO: this should be removed and null passed finally? if (profile == null) { profile = new FreeFormProfile(new List <oM.Geometry.ICurve>()); } if (profile.Edges.Count == 0) { familyInstance.Symbol.ConvertProfileFailedWarning(); } if (!materialFound) { Compute.InvalidDataMaterialWarning(familyInstance); } property = BH.Engine.Structure.Create.SectionPropertyFromProfile(profile, materialFragment, profileName); } else { property = property.ShallowClone(); if (!materialFound) { BH.Engine.Reflection.Compute.RecordNote($"A matching section was found in the library. No valid material was defined in Revit, so the default material for this section was used. Revit ElementId: {familyInstance.Id.IntegerValue}"); } else { property.Material = materialFragment; } property.Name = profileName; } // Create linear bars bars = new List <Bar>(); if (locationCurve != null) { //TODO: check category of familyInstance to recognize which rotation query to use double rotation = familyInstance.OrientationAngle(settings); foreach (BH.oM.Geometry.Line line in locationCurve.ICollapseToPolyline(Math.PI / 12).SubParts()) { bars.Add(BH.Engine.Structure.Create.Bar(line, property, rotation)); } } else { bars.Add(BH.Engine.Structure.Create.Bar(null, null, property, 0)); } for (int i = 0; i < bars.Count; i++) { bars[i].Name = familyInstance.Name; //Set identifiers, parameters & custom data bars[i].SetIdentifiers(familyInstance); bars[i].CopyParameters(familyInstance, settings.ParameterSettings); bars[i].SetProperties(familyInstance, settings.ParameterSettings); } refObjects.AddOrReplace(familyInstance.Id, bars); return(bars); }