public static List <SpeckleObject> ToSpeckle(this BoundaryConditions myRestraint) { var points = new List <XYZ>(); var restraintType = myRestraint.GetBoundaryConditionsType(); if (restraintType == BoundaryConditionsType.Point) { var point = myRestraint.Point; points.Add(point); } else if (restraintType == BoundaryConditionsType.Line) { var curve = myRestraint.GetCurve(); points.Add(curve.GetEndPoint(0)); points.Add(curve.GetEndPoint(1)); } else if (restraintType == BoundaryConditionsType.Area) { var loops = myRestraint.GetLoops(); foreach (var loop in loops) { foreach (var curve in loop) { points.Add(curve.GetEndPoint(0)); points.Add(curve.GetEndPoint(1)); } } points = points.Distinct().ToList(); } var coordinateSystem = myRestraint.GetDegreesOfFreedomCoordinateSystem(); var axis = 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 }) ); var restraint = new StructuralVectorBoolSix(new bool[6]); var stiffness = new StructuralVectorSix(new double[6]); var listOfParams = new BuiltInParameter[] { BuiltInParameter.BOUNDARY_DIRECTION_X, BuiltInParameter.BOUNDARY_DIRECTION_Y, BuiltInParameter.BOUNDARY_DIRECTION_Z, BuiltInParameter.BOUNDARY_DIRECTION_ROT_X, BuiltInParameter.BOUNDARY_DIRECTION_ROT_Y, BuiltInParameter.BOUNDARY_DIRECTION_ROT_Z }; var listOfSpringParams = new BuiltInParameter[] { BuiltInParameter.BOUNDARY_RESTRAINT_X, BuiltInParameter.BOUNDARY_RESTRAINT_Y, BuiltInParameter.BOUNDARY_RESTRAINT_Z, BuiltInParameter.BOUNDARY_RESTRAINT_ROT_X, BuiltInParameter.BOUNDARY_RESTRAINT_ROT_Y, BuiltInParameter.BOUNDARY_RESTRAINT_ROT_Z, }; for (var i = 0; i < 6; i++) { switch (myRestraint.get_Parameter(listOfParams[i]).AsInteger()) { case 0: restraint.Value[i] = true; break; case 1: restraint.Value[i] = false; break; case 2: stiffness.Value[i] = myRestraint.get_Parameter(listOfSpringParams[i]).AsDouble(); break; } } restraint.GenerateHash(); stiffness.GenerateHash(); var myNodes = new List <SpeckleObject>(); foreach (var point in points) { var myPoint = (SpeckleCoreGeometryClasses.SpecklePoint)SpeckleCore.Converter.Serialise(point); var myNode = new StructuralNode(); myNode.basePoint = myPoint; myNode.Axis = axis; myNode.Restraint = restraint; myNode.Stiffness = stiffness; myNodes.Add(myNode); } return(myNodes); }
private Base BoundaryConditionsToSpeckle(BoundaryConditions revitBoundary) { var points = new List <XYZ> { }; var nodes = new List <Node> { }; var cs = revitBoundary.GetDegreesOfFreedomCoordinateSystem(); var localAxis = new Plane(PointToSpeckle(cs.Origin), VectorToSpeckle(cs.BasisZ), VectorToSpeckle(cs.BasisX), VectorToSpeckle(cs.BasisY)); var restraintType = revitBoundary.GetBoundaryConditionsType(); var state = 0; switch (restraintType) { case BoundaryConditionsType.Point: var point = revitBoundary.Point; points.Add(point); state = GetParamValue <int>(revitBoundary, BuiltInParameter.BOUNDARY_PARAM_PRESET); // 1 fixed, 2 pinned, 3 roller, 4 user/variable break; case BoundaryConditionsType.Line: var curve = revitBoundary.GetCurve(); points.Add(curve.GetEndPoint(0)); points.Add(curve.GetEndPoint(1)); state = GetParamValue <int>(revitBoundary, BuiltInParameter.BOUNDARY_PARAM_PRESET_LINEAR); break; case BoundaryConditionsType.Area: var loops = revitBoundary.GetLoops(); foreach (var loop in loops) { foreach (var areaCurve in loop) { points.Add(areaCurve.GetEndPoint(1)); } } points = points.Distinct().ToList(); state = GetParamValue <int>(revitBoundary, BuiltInParameter.BOUNDARY_PARAM_PRESET_AREA); break; default: break; } var restraint = GetRestraintCode(revitBoundary, restraintType, state); foreach (var point in points) { var speckleNode = new Node(); //var speckleNode = new Node(PointToSpeckle(point), null, restraint, localAxis); GetAllRevitParamsAndIds(speckleNode, revitBoundary); nodes.Add(speckleNode); } var speckleBoundaryCondition = new Base(); if (nodes.Count > 1) { speckleBoundaryCondition["nodes"] = nodes; } else { speckleBoundaryCondition = nodes[0]; } return(speckleBoundaryCondition); }