private string CreateMassFamily(string famPath, Geometry.Surface surface, string name) { var famDoc = Doc.Application.NewFamilyDocument(famPath); using (Transaction t = new Transaction(famDoc, "Create Mass")) { t.Start(); try { var pointLists = surface.GetControlPoints(); var curveArray = new ReferenceArrayArray(); foreach (var list in pointLists) { var arr = new ReferencePointArray(); foreach (var point in list) { var refPt = famDoc.FamilyCreate.NewReferencePoint(PointToNative(point)); arr.Append(refPt); } var curve = famDoc.FamilyCreate.NewCurveByPoints(arr); var referenceArray = new ReferenceArray(); referenceArray.Append(curve.GeometryCurve.Reference); curveArray.Append(referenceArray); } var loft = famDoc.FamilyCreate.NewLoftForm(true, curveArray); } catch (Exception e) { } t.Commit(); } var famName = "SpeckleMass_" + name; string tempFamilyPath = Path.Combine(Path.GetTempPath(), famName + ".rfa"); SaveAsOptions so = new SaveAsOptions(); so.OverwriteExistingFile = true; famDoc.SaveAs(tempFamilyPath, so); famDoc.Close(); return(tempFamilyPath); }
public AC.NurbSurface SurfaceToNative(Geometry.Surface surface) { // Get control points var points = surface.GetControlPoints().Select(l => l.Select(p => new ControlPoint( ScaleToNative(p.x, p.units), ScaleToNative(p.y, p.units), ScaleToNative(p.z, p.units), p.weight, p.units)).ToList()).ToList(); var _surface = AC.NurbSurface.Create(new IntPtr(), true); // check what new unmanaged pointer does!! // Set control points Point3dCollection controlPoints = new Point3dCollection(); DoubleCollection weights = new DoubleCollection(); for (var i = 0; i < points.Count; i++) { for (var j = 0; j < points[i].Count; j++) { var pt = points[i][j]; controlPoints.Add(PointToNative(pt)); weights.Add(pt.weight); } } // Get knot vectors KnotCollection UKnots = new KnotCollection(); KnotCollection VKnots = new KnotCollection(); for (int i = 0; i < surface.knotsU.Count; i++) { UKnots.Add(surface.knotsU[i]); } for (int i = 0; i < surface.knotsV.Count; i++) { VKnots.Add(surface.knotsV[i]); } // Set surface info _surface.Set(surface.degreeU, surface.degreeV, 0, 0, surface.countU, surface.countV, controlPoints, weights, UKnots, VKnots); return(_surface); }
public NurbsSurface SurfaceToNative(Geometry.Surface surface) { // Create rhino surface var points = surface.GetControlPoints().Select(l => l.Select(p => new ControlPoint( ScaleToNative(p.x, p.units), ScaleToNative(p.y, p.units), ScaleToNative(p.z, p.units), p.weight, p.units)).ToList()).ToList(); var result = NurbsSurface.Create(3, surface.rational, surface.degreeU + 1, surface.degreeV + 1, points.Count, points[0].Count); // Set knot vectors var correctUKnots = GetCorrectKnots(surface.knotsU, surface.countU, surface.degreeU); for (int i = 0; i < correctUKnots.Count; i++) { result.KnotsU[i] = correctUKnots[i]; } var correctVKnots = GetCorrectKnots(surface.knotsV, surface.countV, surface.degreeV); for (int i = 0; i < correctVKnots.Count; i++) { result.KnotsV[i] = correctVKnots[i]; } // Set control points for (var i = 0; i < points.Count; i++) { for (var j = 0; j < points[i].Count; j++) { var pt = points[i][j]; result.Points.SetPoint(i, j, pt.x * pt.weight, pt.y * pt.weight, pt.z * pt.weight); result.Points.SetWeight(i, j, pt.weight); } } // Return surface return(result); }