/// <summary> /// create a horizontal nurbspline instance with specified z coordinate value /// </summary> public NurbSpline CreateNurbSpline(double z) { // create control points with same z value List <XYZ> ctrPoints = new List <XYZ>(); Autodesk.Revit.DB.XYZ xyz1 = new Autodesk.Revit.DB.XYZ(-41.887503610431267, -9.0290629129782189, z); Autodesk.Revit.DB.XYZ xyz2 = new Autodesk.Revit.DB.XYZ(-9.27600019217055, 0.32213521486563046, z); Autodesk.Revit.DB.XYZ xyz3 = new Autodesk.Revit.DB.XYZ(9.27600019217055, 0.32213521486563046, z); Autodesk.Revit.DB.XYZ xyz4 = new Autodesk.Revit.DB.XYZ(41.887503610431267, 9.0290629129782189, z); ctrPoints.Add(xyz1); ctrPoints.Add(xyz2); ctrPoints.Add(xyz3); ctrPoints.Add(xyz4); IList <double> weights = new List <double>(); double w1 = 1, w2 = 1, w3 = 1, w4 = 1; weights.Add(w1); weights.Add(w2); weights.Add(w3); weights.Add(w4); IList <double> knots = new List <double>(); double k0 = 0, k1 = 0, k2 = 0, k3 = 0, k4 = 34.425128, k5 = 34.425128, k6 = 34.425128, k7 = 34.425128; knots.Add(k0); knots.Add(k1); knots.Add(k2); knots.Add(k3); knots.Add(k4); knots.Add(k5); knots.Add(k6); knots.Add(k7); NurbSpline detailNurbSpline = NurbSpline.Create(ctrPoints, weights, knots, 3, false, true); m_revit.ActiveUIDocument.Document.Regenerate(); return(detailNurbSpline); }
protected override void Process(IFCAnyHandle ifcCurve) { base.Process(ifcCurve); KnotMultiplicities = IFCAnyHandleUtil.GetAggregateIntAttribute <List <int> >(ifcCurve, "KnotMultiplicities"); Knots = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(ifcCurve, "Knots"); if (KnotMultiplicities == null || Knots == null) { Importer.TheLog.LogError(ifcCurve.StepId, "Cannot find the KnotMultiplicities or Knots attribute of this IfcBSplineCurveWithKnots", true); } if (KnotMultiplicities.Count != Knots.Count) { Importer.TheLog.LogError(ifcCurve.StepId, "The number of knots and knot multiplicities are not the same", true); } IList <double> revitKnots = IFCGeometryUtil.ConvertIFCKnotsToRevitKnots(KnotMultiplicities, Knots); Curve nurbsSpline = NurbSpline.CreateCurve(Degree, revitKnots, ControlPointsList); SetCurve(nurbsSpline); if (nurbsSpline == null) { Importer.TheLog.LogWarning(ifcCurve.StepId, "Cannot get the curve representation of this IfcCurve", false); } }
public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args) { if (SelectedIndex < 0) { throw new Exception("Please select a nurbsCurve node."); } var node_name = Items[SelectedIndex].Name; Point3DCollection controlVertices; List <double> weights, knots; int degree; bool closed, rational; DynamoMaya.Contract.IService s = MayaCommunication.openChannelToMaya(); s.receiveCurveFromMaya(node_name, out controlVertices, out weights, out knots, out degree, out closed, out rational); MayaCommunication.closeChannelToMaya(s); List <XYZ> controlPoints = new List <XYZ>(); foreach (Point3D cv in controlVertices) { controlPoints.Add(new XYZ(cv.X, cv.Y, cv.Z)); } NurbSpline ns = NurbSpline.Create(controlPoints, weights, knots, degree, closed, true); return(FScheme.Value.NewContainer(ns)); }
private static Autodesk.Revit.DB.Curve CreateNurbSpline(IList <XYZ> controlPoints, IList <double> weights, IList <double> knots, int degree, bool closed, bool rational) { if (rational) { return(NurbSpline.CreateCurve(degree, knots, controlPoints, weights)); } return(NurbSpline.CreateCurve(degree, knots, controlPoints)); }
/***************************************************/ public static oM.Geometry.NurbsCurve FromRevit(this HermiteSpline curve) { if (curve == null) { return(null); } return(NurbSpline.Create(curve).FromRevit()); }
public void CreateInDynamoModifyInRevitToCauseFailure() { //Create a wall in Dynamo string dynFilePath = Path.Combine(workingDirectory, @".\ElementBinding\CreateWallInDynamo.dyn"); string testPath = Path.GetFullPath(dynFilePath); ViewModel.OpenCommand.Execute(testPath); RunCurrentModel(); //Modify the wall in Revit using (var trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document, "ModifyInRevit")) { bool hasError = false; trans.Start(); try { IList <Element> rps = GetAllWallElements(false); Assert.AreEqual(1, rps.Count); Wall wall = rps.First() as Wall; List <XYZ> ctrlPnts = new List <XYZ>(); ctrlPnts.Add(new XYZ(0.0, 1.0, 0.0)); ctrlPnts.Add(new XYZ(1.0, 0.0, 0.0)); ctrlPnts.Add(new XYZ(2.0, 0.0, 0.0)); ctrlPnts.Add(new XYZ(3.0, 1.0, 0.0)); List <double> weights = new List <double>(); weights.Add(1.0); weights.Add(1.0); weights.Add(1.0); weights.Add(1.0); var spline = NurbSpline.Create(ctrlPnts, weights); var wallLocation = wall.Location as LocationCurve; wallLocation.Curve = spline; } catch (Exception e) { hasError = true; trans.RollBack(); } if (!hasError) { trans.Commit(); } } RunCurrentModel(); IList <Element> rps2 = GetAllWallElements(false); Assert.AreEqual(1, rps2.Count); }
Stream(NurbSpline spline) { if (HasXform) { StreamWcs(spline.CreateTransformed(CurrentXform)); } else { StreamWcs(spline); } }
Stream(ArrayList data, NurbSpline nurbSpline) { data.Add(new Snoop.Data.ClassSeparator(typeof(NurbSpline))); data.Add(new Snoop.Data.Enumerable("Control points", nurbSpline.CtrlPoints)); data.Add(new Snoop.Data.Int("Degree", nurbSpline.Degree)); data.Add(new Snoop.Data.Bool("Is closed", nurbSpline.isClosed)); // TBD: should be upper-case Is data.Add(new Snoop.Data.Bool("Is rational", nurbSpline.isRational)); // TBD: should be upper-case Is data.Add(new Snoop.Data.Enumerable("Knots", nurbSpline.Knots)); data.Add(new Snoop.Data.Enumerable("Weights", nurbSpline.Weights)); }
/// <summary> /// create Nurbspline beam /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void newNurbSplineButton_Click(object sender, EventArgs e) { Level locLev = LevelCB.SelectedValue as Level; NurbSpline beamNs = m_dataBuffer.CreateNurbSpline(locLev.Elevation); bool succeed = m_dataBuffer.CreateCurvedBeam(BeamTypeCB.SelectedValue as FamilySymbol, beamNs, locLev); if (succeed) { TaskDialog.Show("Revit", "Succeeded to create NurbSpline beam."); } }
public void Process(DataTreeBranch b, DataTreeBranch currentBranch) { List <XYZ> ptArr = new List <XYZ>(); List <double> weights = new List <double>(); foreach (object o in b.Leaves) { ReferencePoint pt = o as ReferencePoint; ptArr.Add(pt.Position); weights.Add(1); } //only make a curve if //there's enough points if (ptArr.Count > 1) { //make a curve NurbSpline ns = dynElementSettings.SharedInstance.Doc.Application.Application.Create.NewNurbSpline(ptArr, weights); double rawParam = ns.ComputeRawParameter(.5); Transform t = ns.ComputeDerivatives(rawParam, false); XYZ norm = t.BasisZ; if (norm.GetLength() == 0) { norm = XYZ.BasisZ; } Plane p = new Plane(norm, t.Origin); SketchPlane sp = dynElementSettings.SharedInstance.Doc.Document.FamilyCreate.NewSketchPlane(p); sps.Add(sp); ModelNurbSpline c = (ModelNurbSpline)dynElementSettings.SharedInstance.Doc.Document.FamilyCreate.NewModelCurve(ns, sp); //add the element to the collection //so it can be deleted later Elements.Append(c); //create a leaf node on the local branch currentBranch.Leaves.Add(c); } foreach (DataTreeBranch b1 in b.Branches) { //every time you read a branch //create a branch DataTreeBranch newBranch = new DataTreeBranch(); this.Tree.Trunk.Branches.Add(newBranch); Process(b1, newBranch); } }
/// <summary> /// Converts a List of Grevit Curves to Revit Curves /// </summary> /// <param name="document">Active Document</param> /// <param name="grevitCurves">List of Grevit Curves</param> /// <returns>List of Revit Curves</returns> public static List <Curve> GrevitCurvesToRevitCurves(Component component, CoordinatesOverride coords = null) { List <Curve> curvesOut = new List <Curve>(); if (component.GetType() == typeof(Grevit.Types.Line)) { Grevit.Types.Line line = (Grevit.Types.Line)component; curvesOut.Add(Autodesk.Revit.DB.Line.CreateBound(line.from.ToXYZ(coords), line.to.ToXYZ(coords))); } else if (component.GetType() == typeof(Grevit.Types.Arc)) { Grevit.Types.Arc arc = (Grevit.Types.Arc)component; curvesOut.Add(Autodesk.Revit.DB.Arc.Create(arc.center.ToXYZ(coords), arc.radius, arc.start, arc.end, XYZ.BasisX, XYZ.BasisY)); } else if (component.GetType() == typeof(Grevit.Types.Curve3Points)) { Grevit.Types.Curve3Points curve3points = (Grevit.Types.Curve3Points)component; curvesOut.Add(Autodesk.Revit.DB.Arc.Create(curve3points.a.ToXYZ(coords), curve3points.c.ToXYZ(coords), curve3points.b.ToXYZ(coords))); } else if (component.GetType() == typeof(Grevit.Types.PLine)) { Grevit.Types.PLine pline = (Grevit.Types.PLine)component; for (int i = 0; i < pline.points.Count - 1; i++) { curvesOut.Add(Autodesk.Revit.DB.Line.CreateBound(pline.points[i].ToXYZ(coords), pline.points[i + 1].ToXYZ(coords))); } } else if (component.GetType() == typeof(Spline)) { Spline spline = (Spline)component; IList <XYZ> points = new List <XYZ>(); foreach (Grevit.Types.Point point in spline.controlPoints) { points.Add(point.ToXYZ(coords)); } #if (Revit2015 || Revit2016 || Revit2017) NurbSpline ns = NurbSpline.Create(points, spline.weights); #else NurbSpline ns = (NurbSpline)NurbSpline.CreateCurve(points, spline.weights); #endif ns.isClosed = spline.isClosed; curvesOut.Add(ns); } return(curvesOut); }
private static ElementId createModelCurve(Document document, Curve curve, SketchPlane sp = null) { Line line = curve as Line; Arc arc = curve as Arc; Ellipse ellipse = curve as Ellipse; HermiteSpline spline = curve as HermiteSpline; NurbSpline nbSpline = curve as NurbSpline; if (line != null && null == sp) { XYZ normal = getVertVec(line.Direction).Normalize(); XYZ origin = line.GetEndPoint(0); sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin)); } else if (arc != null && null == sp) { XYZ normal = arc.Normal; sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, arc.Center)); } else if (ellipse != null && null == sp) { XYZ normal = ellipse.Normal; sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, ellipse.Center)); } else if (spline != null && null == sp) { Transform tran = spline.ComputeDerivatives(0, false); XYZ normal = getVertVec(tran.BasisX).Normalize(); XYZ origin = spline.GetEndPoint(0); sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin)); } else if (nbSpline != null && null == sp) { Transform tran = nbSpline.ComputeDerivatives(0, false); XYZ normal = getVertVec(tran.BasisX).Normalize(); XYZ origin = nbSpline.GetEndPoint(0); sp = SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(normal, origin)); } if (sp == null) { throw new ArgumentException("Not valid sketchplane to create curve:" + curve.GetType().Name); } // // create model line with curve and the specified sketch plane. ModelCurve mCurve = document.Create.NewModelCurve(curve, sp); return((null != mCurve) ? mCurve.Id : ElementId.InvalidElementId); }
public static bool IsCurveClosed(NurbSpline curve) { #if (REVIT2021 || REVIT2022) try { return(curve.IsClosed); } catch { return(true); } #else return(curve.isClosed); #endif }
internal static Curve ToNurbsSpline(RG.NurbsCurve value, double factor) { var degree = value.Degree; var knots = ToDoubleArray(value.Knots, degree); var controlPoints = ToXYZArray(value.Points, factor); if (value.IsRational) { var weights = value.Points.ConvertAll(x => x.Weight); return(NurbSpline.CreateCurve(value.Degree, knots, controlPoints, weights)); } else { return(NurbSpline.CreateCurve(value.Degree, knots, controlPoints)); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; List <RG.Point3d> pts = new List <RG.Point3d> { new RG.Point3d(0, 0, 0), new RG.Point3d(5, 10, 0), new RG.Point3d(15, 0, 0), new RG.Point3d(20, 0, 0) }; RG.PolylineCurve pc = new RG.PolylineCurve(pts); RG.NurbsCurve nurb = pc.ToNurbsCurve(); nurb.IncreaseDegree(3); var knots = ToDoubleArray(nurb.Knots, nurb.Degree); var controlPoints = ToXYZArray(nurb.Points, 1); var weights = nurb.Points.ConvertAll(x => x.Weight); XYZ normal = new XYZ(0, 0, 1); XYZ origin = new XYZ(0, 0, 0); Plane rvtPlane = Plane.CreateByNormalAndOrigin(normal, origin); //var plane = sketchPlane.GetPlane().ToPlane(); Curve rvtN = NurbSpline.CreateCurve(nurb.Degree, knots, controlPoints); using (Transaction t = new Transaction(doc, "a")) { t.Start(); SketchPlane sketchPlane = SketchPlane.Create(doc, rvtPlane); ModelCurve mc = doc.Create.NewModelCurve(rvtN, sketchPlane); TaskDialog.Show("r", mc.Id.ToString()); t.Commit(); } return(Result.Succeeded); }
public DB.Curve CurveToNative(Curve speckleCurve) { var pts = new List <XYZ>(); for (int i = 0; i < speckleCurve.points.Count; i += 3) { //use PointToNative for conversion as that takes into account the Project Base Point var point = new Point(speckleCurve.points[i], speckleCurve.points[i + 1], speckleCurve.points[i + 2], speckleCurve.units); pts.Add(PointToNative(point)); } try { if (speckleCurve.knots != null && speckleCurve.weights != null && speckleCurve.knots.Any() && speckleCurve.weights.Any()) { var weights = speckleCurve.weights.GetRange(0, pts.Count); var speckleKnots = new List <double>(speckleCurve.knots); if (speckleKnots.Count != pts.Count + speckleCurve.degree + 1) { // Curve has rhino knots, repeat first and last. speckleKnots.Insert(0, speckleKnots[0]); speckleKnots.Add(speckleKnots[speckleKnots.Count - 1]); } //var knots = speckleKnots.GetRange(0, pts.Count + speckleCurve.degree + 1); var curve = NurbSpline.CreateCurve(speckleCurve.degree, speckleKnots, pts, weights); return(curve); } else { var weights = speckleCurve.weights.GetRange(0, pts.Count); var curve = NurbSpline.CreateCurve(pts, weights); return(curve); } } catch (Exception e) { if (e is Autodesk.Revit.Exceptions.ArgumentException) { throw e; // prob a closed, periodic curve } return(null); } }
/***************************************************/ public static oM.Geometry.NurbsCurve FromRevit(this NurbSpline curve) { if (curve == null) { return(null); } List <double> knots = curve.Knots.Cast <double>().ToList(); knots.RemoveAt(knots.Count - 1); knots.RemoveAt(0); return(new BH.oM.Geometry.NurbsCurve { ControlPoints = curve.CtrlPoints.Select(x => x.PointFromRevit()).ToList(), Knots = knots, Weights = curve.Weights.Cast <double>().ToList() }); }
public DB.Curve CurveToNative(Curve speckleCurve) { var pts = new List <XYZ>(); for (int i = 0; i < speckleCurve.points.Count; i += 3) { pts.Add(new XYZ( ScaleToNative(speckleCurve.points[i], speckleCurve.units), ScaleToNative(speckleCurve.points[i + 1], speckleCurve.units), ScaleToNative(speckleCurve.points[i + 2], speckleCurve.units))); } try { if (speckleCurve.knots != null && speckleCurve.weights != null && speckleCurve.knots.Any() && speckleCurve.weights.Any()) { var weights = speckleCurve.weights.GetRange(0, pts.Count); var speckleKnots = new List <double>(speckleCurve.knots); if (speckleKnots.Count != pts.Count + speckleCurve.degree + 1) { // Curve has rhino knots, repeat first and last. speckleKnots.Insert(0, speckleKnots[0]); speckleKnots.Add(speckleKnots[speckleKnots.Count - 1]); } //var knots = speckleKnots.GetRange(0, pts.Count + speckleCurve.degree + 1); var curve = NurbSpline.CreateCurve(speckleCurve.degree, speckleKnots, pts, weights); return(curve); } else { var weights = speckleCurve.weights.GetRange(0, pts.Count); var curve = NurbSpline.CreateCurve(pts, weights); return(curve); } } catch (Exception e) { return(null); } }
private void Stream(ArrayList data, NurbSpline nurbSpline) { data.Add(new Snoop.Data.ClassSeparator(typeof(NurbSpline))); data.Add(new Snoop.Data.Enumerable("Control points", nurbSpline.CtrlPoints)); data.Add(new Snoop.Data.Int("Degree", nurbSpline.Degree)); data.Add(new Snoop.Data.Bool("Is closed", nurbSpline.isClosed)); // TBD: should be upper-case Is data.Add(new Snoop.Data.Bool("Is rational", nurbSpline.isRational)); // TBD: should be upper-case Is data.Add(new Snoop.Data.Enumerable("Knots", nurbSpline.Knots)); data.Add(new Snoop.Data.Enumerable("Weights", nurbSpline.Weights)); }
StreamWcs(NurbSpline nurbSpline) { m_app.ActiveUIDocument.Document.Create.NewModelCurve(nurbSpline, m_sketchPlane); }
private static DirectShapeInfo ConvertBrep(Document doc, RhinoObjectInfo rhinoInfo) { DirectShapeInfo shapeInfo = new DirectShapeInfo(); try { BRepBuilder brepBuilder = null; Rhino.Geometry.Brep rhinoBrep = rhinoInfo.Geometry as Rhino.Geometry.Brep; if (rhinoBrep.IsSolid) { brepBuilder = new BRepBuilder(BRepType.Solid); } else if (rhinoBrep.IsSurface) { brepBuilder = new BRepBuilder(BRepType.OpenShell); } foreach (Rhino.Geometry.BrepFace brepFace in rhinoBrep.Faces) { BRepBuilderGeometryId nurbSplineFaceId = BRepBuilderGeometryId.InvalidGeometryId(); BRepBuilderGeometryId loopId = BRepBuilderGeometryId.InvalidGeometryId(); bool reverse = brepFace.OrientationIsReversed; if (brepFace.ObjectType == Rhino.DocObjects.ObjectType.Surface) { Rhino.Geometry.NurbsSurface nurbsSurface = brepFace.ToNurbsSurface(); Rhino.Geometry.Collections.NurbsSurfacePointList points = nurbsSurface.Points; int dirU = points.CountU; int dirV = points.CountV; int degreeU = nurbsSurface.Degree(0); int degreeV = nurbsSurface.Degree(1); // knots Rhino.Geometry.Collections.NurbsSurfaceKnotList knotsU = nurbsSurface.KnotsU; Rhino.Geometry.Collections.NurbsSurfaceKnotList knotsV = nurbsSurface.KnotsV; List <XYZ> controlPoints = new List <XYZ>(); XYZ[][] rvtPoints = new XYZ[dirU][]; double[][] rvtWeights = new double[dirU][]; for (int u = 0; u < dirU; u++) { rvtPoints[u] = new XYZ[dirV]; rvtWeights[u] = new double[dirV]; for (int v = 0; v < dirV; v++) { // point coordinates at u, v Rhino.Geometry.Point3d pt = points.GetControlPoint(u, v).Location; XYZ xyz = new XYZ(pt.X, pt.Y, pt.Z); rvtPoints[u][v] = xyz; controlPoints.Add(xyz); // weights at u, v rvtWeights[u][v] = points.GetControlPoint(u, v).Weight; } } // knots U List <double> rvt_knotsU = new List <double>(); rvt_knotsU.Add(knotsU[0]); for (int i = 0; i < knotsU.Count; i++) { rvt_knotsU.Add(knotsU[i]); } rvt_knotsU.Add(knotsU[knotsU.Count - 1]); // knots V List <double> rvt_knotsV = new List <double>(); rvt_knotsV.Add(knotsV[0]); for (int i = 0; i < knotsV.Count; i++) { rvt_knotsV.Add(knotsV[i]); } rvt_knotsV.Add(knotsV[knotsV.Count - 1]); BRepBuilderSurfaceGeometry brepSurface = BRepBuilderSurfaceGeometry.CreateNURBSSurface(degreeU, degreeV, rvt_knotsU, rvt_knotsV, controlPoints, reverse, null); nurbSplineFaceId = brepBuilder.AddFace(brepSurface, reverse); loopId = brepBuilder.AddLoop(nurbSplineFaceId); } foreach (Rhino.Geometry.BrepLoop loop in brepFace.Loops) { Rhino.Geometry.Curve curve = loop.To3dCurve(); Rhino.Geometry.NurbsCurve nurbsCurve = curve.ToNurbsCurve(); int degree = nurbsCurve.Degree; List <XYZ> controlPoints = new List <XYZ>(); List <double> weights = new List <double>(); List <double> knots = new List <double>(); for (int i = 0; i < nurbsCurve.Points.Count; i++) { Rhino.Geometry.ControlPoint ctrlPoint = nurbsCurve.Points[i]; Rhino.Geometry.Point3d point = ctrlPoint.Location; XYZ xyz = new XYZ(point.X, point.Y, point.Z); controlPoints.Add(xyz); weights.Add(ctrlPoint.Weight); } knots.Add(nurbsCurve.Knots[0]); for (int i = 0; i < nurbsCurve.Knots.Count; i++) { double knot = nurbsCurve.Knots[i]; knots.Add(knot); } knots.Add(nurbsCurve.Knots[nurbsCurve.Knots.Count - 1]); Curve rvtCurve = NurbSpline.CreateCurve(degree, knots, controlPoints, weights); BRepBuilderEdgeGeometry edgeGeo = BRepBuilderEdgeGeometry.Create(rvtCurve); BRepBuilderGeometryId edgeId = brepBuilder.AddEdge(edgeGeo); brepBuilder.AddCoEdge(loopId, edgeId, false); } brepBuilder.FinishLoop(loopId); brepBuilder.FinishFace(nurbSplineFaceId); } brepBuilder.Finish(); DirectShape shape = DirectShape.CreateElement(doc, new ElementId((int)BuiltInCategory.OST_GenericModel)); shape.ApplicationId = "RhinoBrep"; shape.ApplicationDataId = rhinoInfo.ObjectId.ToString(); if (null != shape) { shape.SetShape(brepBuilder); } shapeInfo.DirectShapeId = shape.Id; shapeInfo.RhinoObjectId = rhinoInfo.ObjectId; } catch (Exception ex) { string message = ex.Message; MessageBox.Show("Cannot Conver To Brep.\n" + ex.Message); } return(shapeInfo); }
public virtual void Stream(NurbSpline spline) { if (HasXform) StreamWcs(spline.CreateTransformed(CurrentXform)); else StreamWcs(spline); }
/// <summary> /// Override Splines since we can make an optimal Spline Model Line before it /// gets broken into tesselated segments. /// </summary> /// <param name="nurbSpline">spline to create</param> public override void StreamWcs(NurbSpline nurbSpline) { m_app.ActiveUIDocument.Document.Create.NewModelCurve(nurbSpline, m_sketchPlane); }
public override Value Evaluate(FSharpList<Value> args) { var pts = ((Value.List)args[0]).Item.Select( e => ((ReferencePoint)((Value.Container)e).Item).Position ).ToList(); foreach (ElementId el in this.Elements) { Element e; if (dynUtils.TryGetElement(el, out e)) { DeleteElement(el); ns = null; c = null; } } if (pts.Count <= 1) { throw new Exception("Not enough reference points to make a curve."); } if (ns == null) { //make a curve ns = this.UIDocument.Application.Application.Create.NewNurbSpline( pts, Enumerable.Repeat(1.0, pts.Count).ToList()); } else { DoubleArray arr = new DoubleArray(); var weights = Enumerable.Repeat(1.0, pts.Count).ToList(); foreach (double weight in weights) { double d = weight; arr.Append(ref d); } //update the existing curve ns.SetControlPointsAndWeights(pts, arr); } if (c == null) { double rawParam = ns.ComputeRawParameter(.5); Transform t = ns.ComputeDerivatives(rawParam, false); XYZ norm = t.BasisZ; if (norm.GetLength() == 0) { norm = XYZ.BasisZ; } Plane p = new Plane(norm, t.Origin); SketchPlane sp = this.UIDocument.Document.FamilyCreate.NewSketchPlane(p); //sps.Add(sp); c = (ModelNurbSpline) this.UIDocument.Document.FamilyCreate.NewModelCurve(ns, sp); this.Elements.Add(c.Id); } else { c.GeometryCurve = ns; } return Value.NewContainer(c); }
static internal Rhino.Geometry.Curve ToRhino(this Autodesk.Revit.DB.Curve curve) { switch (curve) { case Autodesk.Revit.DB.Line line: { return(line.IsBound ? new Rhino.Geometry.LineCurve(line.GetEndPoint(0).ToRhino(), line.GetEndPoint(1).ToRhino()) : null); } case Autodesk.Revit.DB.Arc arc: { var plane = new Rhino.Geometry.Plane(arc.Center.ToRhino(), new Vector3d(arc.XDirection.ToRhino()), new Vector3d(arc.YDirection.ToRhino())); if (arc.IsBound) { var p0 = arc.GetEndPoint(0).ToRhino(); var p1 = arc.Evaluate(0.5, true).ToRhino(); var p2 = arc.GetEndPoint(1).ToRhino(); return(new Rhino.Geometry.ArcCurve(new Rhino.Geometry.Arc(p0, p1, p2))); } else { return(new Rhino.Geometry.ArcCurve(new Rhino.Geometry.Circle(plane, arc.Radius))); } } case Autodesk.Revit.DB.Ellipse ellipse: { var plane = new Rhino.Geometry.Plane(ellipse.Center.ToRhino(), new Vector3d(ellipse.XDirection.ToRhino()), new Vector3d(ellipse.YDirection.ToRhino())); var e = new Rhino.Geometry.Ellipse(plane, ellipse.RadiusX, ellipse.RadiusY); var n = e.ToNurbsCurve(); if (ellipse.IsBound) { var t0 = Math.IEEERemainder(ellipse.GetEndParameter(0), 2.0 * Math.PI); var t1 = Math.IEEERemainder(ellipse.GetEndParameter(1), 2.0 * Math.PI); return(n.Trim(t0, t1)); } return(n); } case Autodesk.Revit.DB.HermiteSpline hermite: { return(NurbSpline.Create(hermite).ToRhino()); } case Autodesk.Revit.DB.NurbSpline nurb: { var controlPoints = nurb.CtrlPoints; var n = new Rhino.Geometry.NurbsCurve(3, nurb.isRational, nurb.Degree + 1, controlPoints.Count); if (nurb.isRational) { using (var Weights = nurb.Weights) { var weights = Weights.OfType <double>().ToArray(); int index = 0; foreach (var pt in controlPoints) { var w = weights[index]; n.Points.SetPoint(index++, pt.X * w, pt.Y * w, pt.Z * w, w); } } } else { int index = 0; foreach (var pt in controlPoints) { n.Points.SetPoint(index++, pt.X, pt.Y, pt.Z); } } using (var Knots = nurb.Knots) { int index = 0; foreach (var w in Knots.OfType <double>().Skip(1).Take(n.Knots.Count)) { n.Knots[index++] = w; } } return(n); } case Autodesk.Revit.DB.CylindricalHelix helix: // TODO : default: return(new Rhino.Geometry.PolylineCurve(curve.Tessellate().ToRhino())); } }
public virtual void StreamWcs(NurbSpline spline) { StreamCurveAsTesselatedPointsWcs(spline); }
static internal IEnumerable <Autodesk.Revit.DB.Curve> ToHost(this Rhino.Geometry.Curve curve) { var simplifiedCurve = curve.Simplify(CurveSimplifyOptions.SplitAtFullyMultipleKnots, Revit.ModelAbsoluteTolerance, Math.PI / 1800.0); if (simplifiedCurve != null) { curve = simplifiedCurve; } switch (curve) { case Rhino.Geometry.PolyCurve polyCurve: polyCurve.RemoveNesting(); for (int s = 0; s < polyCurve.SegmentCount; ++s) { foreach (var segment in polyCurve.SegmentCurve(s).ToHost()) { yield return(segment); } } break; case Rhino.Geometry.NurbsCurve nurbsCurve: if (nurbsCurve.IsClosed) { foreach (var segment in nurbsCurve.Split(nurbsCurve.Domain.Mid)) { foreach (var c in segment.ToHost()) { yield return(c); } } } else { nurbsCurve.Knots.RemoveMultipleKnots(1, nurbsCurve.Degree, Revit.ModelAbsoluteTolerance); var degree = nurbsCurve.Degree; var knots = nurbsCurve.Knots.ToHost(); var controlPoints = nurbsCurve.Points.ToHost(); Debug.Assert(degree >= 1); Debug.Assert(controlPoints.Count > nurbsCurve.Degree); Debug.Assert(knots.Count == nurbsCurve.Degree + controlPoints.Count + 1); Autodesk.Revit.DB.Curve nurbSpline = null; try { if (nurbsCurve.IsRational) { var weights = new List <double>(controlPoints.Count); foreach (var p in nurbsCurve.Points) { Debug.Assert(p.Weight > 0.0); weights.Add(p.Weight); } Debug.Assert(weights.Count == controlPoints.Count); nurbSpline = NurbSpline.CreateCurve(nurbsCurve.Degree, knots, controlPoints, weights); } else { nurbSpline = NurbSpline.CreateCurve(nurbsCurve.Degree, knots, controlPoints); } } catch (Autodesk.Revit.Exceptions.ApplicationException e) { Debug.Fail(e.Source, e.Message); } yield return(nurbSpline); } break; default: foreach (var c in ToHost(curve.ToNurbsCurve())) { yield return(c); } break; } }
StreamWcs(NurbSpline spline) { StreamCurveAsTesselatedPointsWcs(spline); }
public static bool IsCurveClosed(NurbSpline curve) { #if REVIT2021 return(curve.IsClosed); # else return(curve.isClosed);
/// <summary> /// Add the oriented edge to the current loop /// </summary> /// <param name="id">the id of the edge, corresponding to the StepID of the IfcOrientedEdge</param> /// <param name="curve">the curve, which represents the geometry of the edge</param> /// <param name="startPoint">the start point of the curve</param> /// <param name="endPoint">the end point of the curve</param> /// <param name="orientation">the orientation of the edge</param> /// <returns>true if the edge is successfully added to the boundary</returns> public bool AddOrientedEdgeToTheBoundary(int id, Curve curve, XYZ startPoint, XYZ endPoint, bool orientation) { if (m_CurrentBrepBuilderLoop == null) { throw new InvalidOperationException("StartCollectingLoopForBrepBuilder hasn't been called"); } BRepBuilderGeometryId edgeId = null; if (m_EdgeIdToBrepId.ContainsKey(id) && m_EdgeIdToBrepId[id] != null) { edgeId = m_EdgeIdToBrepId[id]; } else { //TODO: create an utility function MakeBound(Curve, XYZ, XYZ) and factor out this code BRepBuilderEdgeGeometry edge = null; if (curve is Line) { edge = BRepBuilderEdgeGeometry.Create(startPoint, endPoint); } else if (curve is Arc) { Arc arc = curve as Arc; // The curve we receive is an unbound arc, so we have to bound it by the startPoint and the endPoint IntersectionResult start = arc.Project(startPoint); IntersectionResult end = arc.Project(endPoint); double startParameter = start.Parameter; double endParameter = end.Parameter; if (endParameter < startParameter) { endParameter += Math.PI * 2; } arc.MakeBound(startParameter, endParameter); edge = BRepBuilderEdgeGeometry.Create(arc); } else if (curve is Ellipse) { Ellipse ellipse = curve as Ellipse; IntersectionResult start = ellipse.Project(startPoint); IntersectionResult end = ellipse.Project(endPoint); double startParameter = start.Parameter; double endParameter = end.Parameter; if (endParameter < startParameter) { endParameter += Math.PI * 2; } ellipse.MakeBound(startParameter, endParameter); edge = BRepBuilderEdgeGeometry.Create(ellipse); } else if (curve is NurbSpline) { NurbSpline nurbs = curve as NurbSpline; // Bound the NurbSpline based on the start and end points. // As mentioned above, there should be a function to bound // a curve based on two 3D points and it should be used here // instead of duplicating manual code. IntersectionResult start = nurbs.Project(startPoint); IntersectionResult end = nurbs.Project(endPoint); double startParameter = start.Parameter; double endParameter = end.Parameter; if (endParameter < startParameter) { Importer.TheLog.LogError(id, "Inverted start/end parameters for NurbSpline.", false /*throwError*/); return(false); } else { nurbs.MakeBound(startParameter, endParameter); } edge = BRepBuilderEdgeGeometry.Create(nurbs); } else { Importer.TheLog.LogError(id, "Unsupported edge curve type: " + curve.GetType().ToString(), false); return(false); } edgeId = m_BrepBuilder.AddEdge(edge); m_EdgeIdToBrepId.Add(id, edgeId); } try { m_BrepBuilder.AddCoEdge(m_CurrentBrepBuilderLoop, edgeId, !orientation); } catch { return(false); } return(true); }
/***************************************************/ public static List <Curve> ToRevitCurves(this BH.oM.Geometry.NurbsCurve curve) { if (curve.ControlPoints.Count == 2) { return new List <Curve> { new oM.Geometry.Line { Start = curve.ControlPoints[0], End = curve.ControlPoints[1] }.ToRevit() } } ; else { List <double> knots = curve.Knots.ToList(); knots.Insert(0, knots[0]); knots.Add(knots[knots.Count - 1]); List <XYZ> controlPoints = curve.ControlPoints.Select(x => x.ToRevit()).ToList(); try { Curve nc = NurbSpline.CreateCurve(curve.Degree(), knots, controlPoints, curve.Weights); //Split the curve in half when it is closed. if (nc.GetEndPoint(0).DistanceTo(nc.GetEndPoint(1)) <= BH.oM.Adapters.Revit.Tolerance.Vertex) { double param1 = nc.GetEndParameter(0); double param2 = nc.GetEndParameter(1); Curve c1 = nc.DeepClone(); Curve c2 = nc.DeepClone(); c1.MakeBound(param1, (param1 + param2) * 0.5); c2.MakeBound((param1 + param2) * 0.5, param2); return(new List <Curve> { c1, c2 }); } else { return new List <Curve> { nc } }; } catch { BH.Engine.Reflection.Compute.RecordWarning("Conversion of a nurbs curve from BHoM to Revit failed. An approximate, 100-segment polyline has been created instead."); List <XYZ> pts = new List <XYZ>(); int k = 100; for (int i = 0; i <= k; i++) { double t = i / (double)k; pts.Add(curve.PointAtParameter(t).ToRevit()); } List <Curve> result = new List <Curve>(); for (int i = 1; i < pts.Count; i++) { result.Add(Line.CreateBound(pts[i - 1], pts[i])); } return(result); } } }
static internal IEnumerable <Autodesk.Revit.DB.Curve> ToHost(this Rhino.Geometry.Curve curve, double curveTolerance = double.PositiveInfinity) { curveTolerance = Math.Min(Revit.ShortCurveTolerance, Math.Abs(curveTolerance)); Debug.Assert(!curve.IsShort(curveTolerance)); var simplifiedCurve = curve.Simplify(CurveSimplifyOptions.SplitAtFullyMultipleKnots, curveTolerance, Revit.AngleTolerance); if (simplifiedCurve != null) { curve = simplifiedCurve; } switch (curve) { case Rhino.Geometry.LineCurve line: yield return(Autodesk.Revit.DB.Line.CreateBound(line.PointAtStart.ToHost(), line.PointAtEnd.ToHost())); break; case Rhino.Geometry.PolylineCurve polyline: for (int p = 1; p < polyline.PointCount; ++p) { yield return(Autodesk.Revit.DB.Line.CreateBound(polyline.Point(p - 1).ToHost(), polyline.Point(p).ToHost())); } break; case Rhino.Geometry.ArcCurve arc: if (arc.IsClosed) { yield return(Autodesk.Revit.DB.Arc.Create(arc.Arc.Plane.ToHost(), arc.Arc.Radius, 0.0, (2.0 * Math.PI) - 2e-8)); } else { yield return(Autodesk.Revit.DB.Arc.Create(arc.Arc.StartPoint.ToHost(), arc.Arc.EndPoint.ToHost(), arc.Arc.MidPoint.ToHost())); } break; case Rhino.Geometry.PolyCurve polyCurve: polyCurve.RemoveNesting(); polyCurve.RemoveShortSegments(curveTolerance); for (int s = 0; s < polyCurve.SegmentCount; ++s) { foreach (var segment in polyCurve.SegmentCurve(s).ToHost()) { yield return(segment); } } break; case Rhino.Geometry.NurbsCurve nurbsCurve: if (nurbsCurve.IsLinear(Revit.VertexTolerance)) { yield return(Autodesk.Revit.DB.Line.CreateBound(nurbsCurve.PointAtStart.ToHost(), nurbsCurve.PointAtEnd.ToHost())); yield break; } if (nurbsCurve.TryGetPolyline(out var polylineSegment)) { polylineSegment.ReduceSegments(curveTolerance); foreach (var segment in polylineSegment.GetSegments()) { yield return(Autodesk.Revit.DB.Line.CreateBound(segment.From.ToHost(), segment.To.ToHost())); } yield break; } if (nurbsCurve.TryGetArc(out var arcSegment, Revit.VertexTolerance)) { yield return(Autodesk.Revit.DB.Arc.Create(arcSegment.StartPoint.ToHost(), arcSegment.EndPoint.ToHost(), arcSegment.MidPoint.ToHost())); yield break; } if (nurbsCurve.IsClosed) { if (nurbsCurve.TryGetCircle(out var circle, Revit.VertexTolerance)) { yield return(Autodesk.Revit.DB.Arc.Create(circle.Plane.ToHost(), circle.Radius, 0.0, 2.0 * (2.0 * Math.PI) - 2e-8)); yield break; } if (nurbsCurve.TryGetEllipse(out var ellipse, Revit.VertexTolerance)) { yield return(Autodesk.Revit.DB.Ellipse.CreateCurve(ellipse.Plane.Origin.ToHost(), ellipse.Radius1, ellipse.Radius2, ellipse.Plane.XAxis.ToHost(), ellipse.Plane.YAxis.ToHost(), 0.0, (2.0 * Math.PI) - 2e-8)); yield break; } foreach (var segment in nurbsCurve.Split(nurbsCurve.Domain.Mid)) { foreach (var c in segment.ToHost()) { yield return(c); } } } else { nurbsCurve.Knots.RemoveMultipleKnots(1, nurbsCurve.Degree, Revit.VertexTolerance); var degree = nurbsCurve.Degree; var knots = nurbsCurve.Knots.ToHost(); var controlPoints = nurbsCurve.Points.ToHost(); Debug.Assert(degree >= 1); Debug.Assert(controlPoints.Count > nurbsCurve.Degree); Debug.Assert(knots.Count == nurbsCurve.Degree + controlPoints.Count + 1); Autodesk.Revit.DB.Curve nurbSpline = null; try { if (nurbsCurve.IsRational) { var weights = new List <double>(controlPoints.Count); foreach (var p in nurbsCurve.Points) { Debug.Assert(p.Weight > 0.0); weights.Add(p.Weight); } Debug.Assert(weights.Count == controlPoints.Count); nurbSpline = NurbSpline.CreateCurve(nurbsCurve.Degree, knots, controlPoints, weights); } else { nurbSpline = NurbSpline.CreateCurve(nurbsCurve.Degree, knots, controlPoints); } } catch (Autodesk.Revit.Exceptions.ApplicationException e) { Debug.Fail(e.Source, e.Message); } yield return(nurbSpline); } break; default: foreach (var c in curve.ToNurbsCurve().ToHost()) { yield return(c); } break; } }
private static bool IsLineLikeInternal(NurbSpline crv) { return(IsLineLikeInternal(crv.CtrlPoints)); }
//绘制模型线 private void CreateCurve(XYZ startPoint, XYZ endPoint, XYZ normal1, XYZ normal2) { XYZ StartToEnd = new XYZ((endPoint - startPoint).X, (endPoint - startPoint).Y, 0); XYZ p_normal1 = new XYZ(normal1.X, normal1.Y, 0); XYZ p_normal2 = new XYZ(normal2.X, normal2.Y, 0); p_normal1 = p_normal1 / (Math.Sqrt(p_normal1.X * p_normal1.X + p_normal1.Y * p_normal1.Y)); p_normal2 = p_normal2 / (Math.Sqrt(p_normal2.X * p_normal2.X + p_normal2.Y * p_normal2.Y)); XYZ XoYprj_start = new XYZ(startPoint.X, startPoint.Y, 0); XYZ XoYprj_end = new XYZ(endPoint.X, endPoint.Y, 0); //在起点、终点间插值,并在z=0平面上绘制NurbSpline曲线 double[] doubleArray = { 1, 1, 1, 1, 1, 1 }; IList <XYZ> controlPoints2 = new List <XYZ>(); controlPoints2.Add(XoYprj_start); controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(2000)); controlPoints2.Add(XoYprj_start + p_normal1 * mmToFeet(4000)); controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(4000)); controlPoints2.Add(XoYprj_end + p_normal2 * mmToFeet(2000)); controlPoints2.Add(XoYprj_end); Curve nbLine = NurbSpline.Create(controlPoints2, doubleArray); //提取曲线上的拟合点,并在z轴方向插值拟合原曲线 IList <XYZ> ptsOnCurve = nbLine.Tessellate(); int ptCount = ptsOnCurve.Count; ReferencePointArray ptArr = new ReferencePointArray(); for (int i = 0; i < ptCount; i++) { XYZ pt = ptsOnCurve[i]; if (i < (ptCount - 1) / 8) { ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z))); } else if (i > 7 * (ptCount - 1) / 8) { ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, endPoint.Z))); } else { ptArr.Append(m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + (i - (ptCount - 1) / 8) * (endPoint.Z - startPoint.Z) / (0.75 * (ptCount - 1))))); } //ReferencePoint p = m_familyCreator.NewReferencePoint(new XYZ(pt.X, pt.Y, startPoint.Z + i*(endPoint.Z - startPoint.Z)/ (ptCount - 1))); //ptArr.Append(p); } CurveByPoints curve = m_familyCreator.NewCurveByPoints(ptArr); curve.Visible = false; //创建放样平面并加入参照数组中 int step = 8;//取step个点进行拟合 ReferenceArrayArray refArr = new ReferenceArrayArray(); for (int i = 0; i <= step; i++) { int position = i * (ptCount - 1) / step; //取起点截面及第二个截面作为参照平面 if (i == 0) { refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i + 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i + 1) * (ptCount - 1) / step)])); } //取终点截面及倒数第二个截面作为参照平面 else if (i == step) { refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), ptArr.get_Item((i - 1) * (ptCount - 1) / step), (curve.GeometryCurve as HermiteSpline).Tangents[position], (curve.GeometryCurve as HermiteSpline).Tangents[((i - 1) * (ptCount - 1) / step)])); } else { refArr.Append(CreatePlaneByPoint(ptArr.get_Item(position), (curve.GeometryCurve as HermiteSpline).Tangents[position])); } } //创建放样实体 m_familyCreator.NewLoftForm(true, refArr); }
private static bool AreSimilar(NurbSpline a, NurbSpline b, double tolerance) { return(CompareRandomParameterLocationDistances(a, b, tolerance)); }