public Polycurve CurveLoopToSpeckle(CurveLoop loop, string units = null) { var polycurve = new Polycurve(); polycurve.units = units ?? ModelUnits; polycurve.closed = !loop.IsOpen(); polycurve.length = units == Units.None ? loop.GetExactLength() : ScaleToSpeckle(loop.GetExactLength()); polycurve.segments.AddRange(loop.Select(x => CurveToSpeckle(x))); return(polycurve); }
public Polycurve CurveLoopToSpeckle(CurveLoop loop) { var polycurve = new Polycurve(); polycurve.units = ModelUnits; polycurve.closed = !loop.IsOpen(); polycurve.length = ScaleToSpeckle(loop.GetExactLength()); polycurve.segments.AddRange(loop.Select(x => CurveToSpeckle(x))); return(polycurve); }
private List <CurveLoop> CreateProfiles(Area area) { List <CurveLoop> profiles = new List <CurveLoop>(); try { CurveArrArray curveArrArray = new CurveArrArray(); if (area.GetBoundarySegments(new SpatialElementBoundaryOptions()) != null) { foreach (IList <Autodesk.Revit.DB.BoundarySegment> boundarySegments in area.GetBoundarySegments(new SpatialElementBoundaryOptions())) { if (boundarySegments.Count > 0) { CurveArray curveArray = new CurveArray(); foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in boundarySegments) { #if RELEASE2016 || RELEASE2017 Curve curve = boundarySegment.GetCurve(); #else Curve curve = boundarySegment.Curve; #endif curveArray.Append(curve); } curveArrArray.Append(curveArray); } } } double zValue = 0; double maxCircum = 0; bool isFirst = true; foreach (CurveArray curveArray in curveArrArray) { List <XYZ> pointList = new List <XYZ>(); CurveLoop profile = new CurveLoop(); double circumference = 0; foreach (Curve curve in curveArray) { int pointCount = curve.Tessellate().Count; if (pointCount > 2) { IList <XYZ> tPoints = curve.Tessellate(); //to make equivalent z value to avoid slightly line offset error. if (isFirst) { zValue = tPoints[0].Z; isFirst = false; } //remove the last point on the curve. for (int i = 0; i < tPoints.Count - 1; i++) { XYZ tempPoint = new XYZ(tPoints[i].X, tPoints[i].Y, zValue); if (pointList.Count == 0) { pointList.Add(tempPoint); } else { double distance = pointList[pointList.Count - 1].DistanceTo(tempPoint); if (distance > 0.004) { pointList.Add(tempPoint); } } } } else if (pointCount == 2) { #if RELEASE2013 XYZ pt = curve.get_EndPoint(0); #else XYZ pt = curve.GetEndPoint(0); #endif if (isFirst) { zValue = pt.Z; isFirst = false; } XYZ tempPoint = new XYZ(pt.X, pt.Y, zValue); if (pointList.Count == 0) { pointList.Add(tempPoint); } else { double distance = pointList[pointList.Count - 1].DistanceTo(tempPoint); if (distance > 0.004) { pointList.Add(tempPoint); } } } } int num = pointList.Count; double minX = pointList[0].X; double minY = pointList[0].Y; double minZ = pointList[0].Z; double maxX = pointList[0].X; double maxY = pointList[0].Y; double maxZ = minZ + 100; if (num > 2) { Curve newCurve = null; for (int i = 0; i < num; i++) { if (i == num - 1) { #if RELEASE2013 newCurve = doc.Application.Create.NewLine(pointList[i], pointList[0], true); #else newCurve = Line.CreateBound(pointList[i], pointList[0]); #endif } else { #if RELEASE2013 newCurve = doc.Application.Create.NewLine(pointList[i], pointList[i + 1], true); #else newCurve = Line.CreateBound(pointList[i], pointList[i + 1]); #endif } profile.Append(newCurve); XYZ xyz = pointList[i]; if (xyz.X < minX) { minX = xyz.X; } if (xyz.Y < minY) { minY = xyz.Y; } if (xyz.X > maxX) { maxX = xyz.X; } if (xyz.Y > maxY) { maxY = xyz.Y; } } minXYZ = new XYZ(minX, minY, minZ); maxXYZ = new XYZ(maxX, maxY, maxZ); circumference = profile.GetExactLength(); if (maxCircum == 0) { maxCircum = circumference; } else if (maxCircum < circumference) { maxCircum = circumference; } if (maxCircum == circumference) { profiles.Insert(0, profile); } else { profiles.Add(profile); } } } } catch (Exception ex) { MessageBox.Show("Area Id:" + area.Id.IntegerValue + "\nFailed to create profiles from an area object.\n" + ex.Message, "FARCalculator:CreateProfiles", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(profiles); }
public void Execute(UIApplication uiapp) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; // myListView_ALL_Fam_Master.Items.Add(doc.GetElement(uidoc.Selection.GetElementIds().First()).Name); if (uidoc.Selection.GetElementIds().Count != 1) { MessageBox.Show("Please select ONE Wall."); return; } Element myElementWall = doc.GetElement(uidoc.Selection.GetElementIds().First()); if (myElementWall.GetType() == typeof(FamilyInstance)) { FamilyInstance myFamilyInstance = myElementWall as FamilyInstance; myElementWall = myFamilyInstance.Host; if (myElementWall == null) { MessageBox.Show("Family instance must be hosted to a wall."); return; } } /// TECHNIQUE 08 OF 19 (EE08_MoveElementAroundHostingSurface.cs) ///↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ MOVING ELEMENTS AROUND A HOSTING SURFACE ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ /// The people walk around the perimeter of the wall, and it will work on any surface /// /// /// Interfaces and ENUM's: /// /// /// Demonstrates classes: /// Reference /// Face /// Transform /// PlanarFace /// CurveLoop /// /// /// Key methods: /// myElementWall.GetGeometryObjectFromReference(pickedRef) as Face /// pickedRef.ConvertToStableRepresentation(doc).Contains("INSTANCE")) /// (myElementWall as FamilyInstance).GetTotalTransform(); /// myFace.GetBoundingBox().Min /// myFace.Evaluate(myUV_Min) /// /// myXYZ_FamilyTransform.OfPoint(myXYZ_CornerOne) /// myXYZ_FamilyTransform.OfVector(myPlanarFace.XVector); /// myCurveLoop.GetExactLength(); /// /// /// L1.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong); /// ElementTransformUtils.MoveElement(doc, myFamilyInstance.Id, myXYZ_MoveThisMuch); /// /// * class is actually part of the .NET framework (not Revit API) /// /// /// /// https://github.com/joshnewzealand/Revit-API-Playpen-CSharp List <Element> myListOfStuffOnWall = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_GenericModel).Where(x => (((FamilyInstance)x).Host != null)).Where(x => ((FamilyInstance)x).Host.Id == myElementWall.Id).ToList(); List <Element> myListOfFurniture = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Furniture).Where(x => (((FamilyInstance)x).Host != null)).Where(x => ((FamilyInstance)x).Host.Id == myElementWall.Id).ToList(); myListOfStuffOnWall.AddRange(myListOfFurniture); if (myListOfStuffOnWall.Count() > 0) { using (Transaction tx = new Transaction(doc)) { tx.Start("Rotate People"); foreach (FamilyInstance myFI in myListOfStuffOnWall) { FamilyInstance myFamilyInstance = myFI as FamilyInstance; Reference pickedRef = myFI.HostFace; ////doc.Delete(myListElementID); ////myListElementID.Clear(); Face myFace = myElementWall.GetGeometryObjectFromReference(pickedRef) as Face; if (myFace == null) { return; } Transform myXYZ_FamilyTransform = Transform.Identity; if (pickedRef.ConvertToStableRepresentation(doc).Contains("INSTANCE")) { myXYZ_FamilyTransform = (myElementWall as FamilyInstance).GetTotalTransform(); } Transform myTransform = Transform.Identity; if (myFace.GetType() != typeof(PlanarFace)) { return; } PlanarFace myPlanarFace = myFace as PlanarFace; UV myUV_Min = myFace.GetBoundingBox().Min; UV myUV_Max = myFace.GetBoundingBox().Max; XYZ myXYZ_CornerOne = myFace.Evaluate(myUV_Min); myTransform.Origin = myXYZ_FamilyTransform.OfPoint(myXYZ_CornerOne); myTransform.BasisX = myXYZ_FamilyTransform.OfVector(myPlanarFace.XVector); myTransform.BasisY = myXYZ_FamilyTransform.OfVector(myPlanarFace.YVector); myTransform.BasisZ = myXYZ_FamilyTransform.OfVector(myPlanarFace.FaceNormal); XYZ myXYZ_Centre = XYZ.Zero; XYZ myXYZ_Min = new XYZ(myUV_Min.U, myUV_Min.V, 0); XYZ myXYZ_Max = new XYZ(myUV_Max.U, myUV_Max.V, 0); XYZ myXYZ_UV_CornerOne = (((myXYZ_Max - myXYZ_Min) * 0.1)); //; + myXYZ_Min; XYZ myXYZ_UV_CornerTwo = (((myXYZ_Max - myXYZ_Min) * 0.9)); // + myXYZ_Min; XYZ myXYZ_UV_Corner01 = new XYZ(myXYZ_UV_CornerOne.X, myXYZ_UV_CornerOne.Y, 0); XYZ myXYZ_UV_Corner02 = new XYZ(myXYZ_UV_CornerTwo.X, myXYZ_UV_CornerOne.Y, 0); XYZ myXYZ_UV_Corner03 = new XYZ(myXYZ_UV_CornerTwo.X, myXYZ_UV_CornerTwo.Y, 0); XYZ myXYZ_UV_Corner04 = new XYZ(myXYZ_UV_CornerOne.X, myXYZ_UV_CornerTwo.Y, 0); Line L1 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner01), myTransform.OfPoint(myXYZ_UV_Corner02)); Line L2 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner02), myTransform.OfPoint(myXYZ_UV_Corner03)); Line L3 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner03), myTransform.OfPoint(myXYZ_UV_Corner04)); Line L4 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner04), myTransform.OfPoint(myXYZ_UV_Corner01)); CurveLoop myCurveLoop = new CurveLoop(); myCurveLoop.Append(L1); myCurveLoop.Append(L2); myCurveLoop.Append(L3); myCurveLoop.Append(L4); double myDouble_ExactLength = myCurveLoop.GetExactLength(); double myDouble_ExactLength_Twenty = myDouble_ExactLength / 40; XYZ myXYZ_Result = myTransform.OfPoint((myXYZ_Max - myXYZ_Min) / 2); int myIntCurrentSpinnerValue = myWindow1.myIntegerUpDown_OneToTwentyCount.Value.Value; int myInt_Positioning = (40 / myListOfStuffOnWall.Count()) * (myListOfStuffOnWall.IndexOf(myFI) + 1); myIntCurrentSpinnerValue = (40 - myInt_Positioning) + myIntCurrentSpinnerValue; if (myIntCurrentSpinnerValue > 40) { myIntCurrentSpinnerValue = myIntCurrentSpinnerValue - 40; } double myDouble_FutureForeach = myDouble_ExactLength_Twenty * myIntCurrentSpinnerValue; double myDouble_ThisFarAlong; switch (myDouble_FutureForeach) { case double n when n < L1.Length: myDouble_ThisFarAlong = myDouble_FutureForeach; myXYZ_Result = L1.GetEndPoint(0) + (L1.GetEndPoint(1) - L1.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong); break; case double n when n >= L1.Length& n < L1.Length + L2.Length: myDouble_ThisFarAlong = myDouble_FutureForeach - L1.Length; myXYZ_Result = L2.GetEndPoint(0) + (L2.GetEndPoint(1) - L2.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong); break; case double n when n >= L1.Length + L2.Length& n < L1.Length + L2.Length + L3.Length: myDouble_ThisFarAlong = myDouble_FutureForeach - L1.Length - L2.Length; myXYZ_Result = L3.GetEndPoint(0) + (L3.GetEndPoint(1) - L3.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong); break; case double n when n >= L1.Length + L2.Length + L3.Length: myDouble_ThisFarAlong = myDouble_FutureForeach - L1.Length - L2.Length - L3.Length; myXYZ_Result = L4.GetEndPoint(0) + (L4.GetEndPoint(1) - L4.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong); break; } XYZ myXYZ_MoveThisMuch = myXYZ_Result - ((LocationPoint)myFamilyInstance.Location).Point; ElementTransformUtils.MoveElement(doc, myFamilyInstance.Id, myXYZ_MoveThisMuch); //SketchPlane mySketchPlane = SketchPlane.Create(doc, pickedRef); //myListElementID.Add(doc.Create.NewModelCurve(L1, mySketchPlane).Id); //myListElementID.Add(doc.Create.NewModelCurve(L2, mySketchPlane).Id); //myListElementID.Add(doc.Create.NewModelCurve(L3, mySketchPlane).Id); //myListElementID.Add(doc.Create.NewModelCurve(L4, mySketchPlane).Id); } tx.Commit(); } if (myWindow1.myIntegerUpDown_OneToTwentyCount.Value.Value == 40) { myWindow1.myIntegerUpDown_OneToTwentyCount.Value = 0; } myWindow1.myIntegerUpDown_OneToTwentyCount.Value++; } } #region catch and finally catch (Exception ex) { DatabaseMethods.writeDebug("EE08_MoveElementAroundHostingSurface" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true); } finally { } #endregion }