public static Autodesk.DesignScript.Geometry.Mesh GetMeshFromElem(Revit.Elements.Element element) { rDoc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument; geoOpt = rDoc.Application.Create.NewGeometryOptions(); geoOpt.ComputeReferences = true; geoOpt.IncludeNonVisibleObjects = false; object retrievedMeshes = GetMeshes(element); Autodesk.DesignScript.Geometry.Mesh m = null; if (retrievedMeshes is IList) { int counter = 0; while (retrievedMeshes is IList) { List <Autodesk.DesignScript.Geometry.Mesh> listData = (List <Autodesk.DesignScript.Geometry.Mesh>)retrievedMeshes; retrievedMeshes = listData[0]; counter++; if (counter > 100) { break; } } m = retrievedMeshes as Autodesk.DesignScript.Geometry.Mesh; } else { m = retrievedMeshes as Autodesk.DesignScript.Geometry.Mesh; } return(m); }
public MeshBinder(Autodesk.DesignScript.Geometry.Mesh mesh, Color color) { dynamoMesh = true; StartingPositions = mesh.VertexPositions.ToTriples().ToArray(); Color = color; faces = mesh.FaceIndices; meshIndices = new IntCollection(); foreach (IndexGroup face in faces) { meshIndices.Add((int)face.A); meshIndices.Add((int)face.B); meshIndices.Add((int)face.C); if (face.D == uint.MaxValue) { continue; } meshIndices.Add((int)face.A); meshIndices.Add((int)face.C); meshIndices.Add((int)face.D); } }
/// <summary> /// Create a Revit DirectShape given some geometry, a name for the shape, a Category, and Material. /// The geometry will be tessellated before being placed in the Revit model /// The category of a DirectShape cannot be changed after creation, so /// a new DirectShape will be generated if the category input is changed. /// </summary> /// <param name="mesh">A Mesh that will be tessellated and placed in the Revit model as a DirectShape</param> /// <param name="name">A string name for the DirectShape</param> /// <param name="category">Must be a top level Built-in Category</param> /// <param name="material">A Material to apply to the faces of the DirectShape</param> /// <returns>A DirectShape Element</returns> public static DirectShape ByMesh(Autodesk.DesignScript.Geometry.Mesh mesh, Category category, [DefaultArgumentAttribute(" DirectShape.DynamoPreviewMaterial")] Material material, string name = DEFAULT_NAME) { if (mesh == null) { throw new ArgumentNullException("mesh"); } if (name == null) { throw new ArgumentNullException("name"); } if (category == null) { throw new ArgumentNullException("category"); } if (material == null) { throw new ArgumentNullException("material"); } return(new DirectShape(mesh, name, category, material)); }
public static MeshBinder MeshBinder( Autodesk.DesignScript.Geometry.Mesh mesh, [DefaultArgument("null")] Color color) { return(new MeshBinder( mesh, color?.ToSharpDXColor() ?? DynaShapeDisplay.DefaultMeshFaceColor)); }
private static Autodesk.DesignScript.Geometry.Point getAveragePointFromFace(Autodesk.Revit.DB.Face f) { //the point to return Autodesk.DesignScript.Geometry.Point p = null; //if face is a ruled face RuledFace rf = f as RuledFace; if (rf != null) { //units seem to be messed up... convert to a designscript mesh first, then pull from that Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(rf.Triangulate()); var points = m.VertexPositions; int numVertices = points.Count(); double x = 0, y = 0, z = 0; foreach (var v in points) { x = x + v.X; y = y + v.Y; z = z + v.Z; } x = x / numVertices; y = y / numVertices; z = z / numVertices; p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z); } else // if it isn't a ruled face, treat it as planar { PlanarFace pf = f as PlanarFace; if (pf != null) { //units seem to be messed up... convert to a designscript mesh first, then pull from that Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(pf.Triangulate()); var points = m.VertexPositions; int numVertices = points.Count(); double x = 0, y = 0, z = 0; foreach (var v in points) { x = x + v.X; y = y + v.Y; z = z + v.Z; } x = x / numVertices; y = y / numVertices; z = z / numVertices; p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z); } } return(p); }
/// <summary> /// Returns the BoundingBox of a Dynamo DesignScript Mesh /// </summary> /// <param name="mesh">Dynamo DesignScript Mesh</param> /// <returns name="BoundingBox">Mesh's BoundingBox</returns> public static DS.BoundingBox BoundingBox(DS.Mesh mesh) { IEnumerable <double> x = mesh.VertexPositions.Select(pt => pt.X); IEnumerable <double> y = mesh.VertexPositions.Select(pt => pt.Y); IEnumerable <double> z = mesh.VertexPositions.Select(pt => pt.Z); return(DS.BoundingBox.ByCorners( DS.Point.ByCoordinates(x.Min(), y.Min(), z.Min()), DS.Point.ByCoordinates(x.Max(), y.Max(), z.Max()) )); }
public static Dictionary <string, object> Draw(hMember member) { Geo.Point OP1 = member._webAxis.StartPoint; Geo.Point OP2 = member._webAxis.EndPoint; Geo.Vector webAxis = Geo.Vector.ByTwoPoints(OP1, OP2); Geo.Vector normal = member._webNormal; Geo.Vector lateral = webAxis.Cross(normal); lateral = lateral.Normalized(); lateral = lateral.Scale(1.75); normal = normal.Normalized(); normal = normal.Scale(1.5); Geo.Vector lateralR = Geo.Vector.ByCoordinates(lateral.X * -1, lateral.Y * -1, lateral.Z * -1); Geo.Point p0 = OP1.Add(normal.Add(lateral)); Geo.Point p1 = OP2.Add(normal.Add(lateral)); Geo.Point p2 = OP1.Add(lateral); Geo.Point p3 = OP2.Add(lateral); Geo.Point p6 = OP1.Add(normal.Add(lateralR)); Geo.Point p7 = OP2.Add(normal.Add(lateralR)); Geo.Point p4 = OP1.Add(lateralR); Geo.Point p5 = OP2.Add(lateralR); Geo.Point[] pts = { p0, p1, p2, p1, p2, p3, p2, p3, p4, p3, p4, p5, p4, p5, p6, p5, p6, p7 }; Geo.IndexGroup g0 = Geo.IndexGroup.ByIndices(0, 1, 2); Geo.IndexGroup g1 = Geo.IndexGroup.ByIndices(3, 4, 5); Geo.IndexGroup g2 = Geo.IndexGroup.ByIndices(6, 7, 8); Geo.IndexGroup g3 = Geo.IndexGroup.ByIndices(9, 10, 11); Geo.IndexGroup g4 = Geo.IndexGroup.ByIndices(12, 13, 14); Geo.IndexGroup g5 = Geo.IndexGroup.ByIndices(15, 16, 17); Geo.IndexGroup[] ig = { g0, g1, g2, g3, g4, g5 }; Geo.Mesh mesh = Geo.Mesh.ByPointsFaceIndices(pts, ig); var points = new List <Geo.Point>(); foreach (hOperation op in member.operations) { points.Add(member._webAxis.PointAtParameter(op._loc / member._webAxis.Length)); } return(new Dictionary <string, object> { { "member", mesh }, { "operations", points } }); }
/// <summary> /// Creates a MeshToolkit Mesh by converting a Dynamo Mesh /// </summary> /// <param name="mesh">Dynamo Mesh</param> /// <returns name = "meshToolkit">MeshToolkit Mesh</returns> public static MT.Mesh ByDynamoMesh(DS.Mesh mesh) { var vertices = mesh.VertexPositions; var indexGroups = mesh.FaceIndices; List<int> indexes = new List<int>(); foreach (var ind in indexGroups) { indexes.Add((int)ind.A); indexes.Add((int)ind.B); indexes.Add((int)ind.C); } return MT.Mesh.ByVerticesAndIndices(vertices, indexes); }
public static IList <GeometryObject> ToRevitType( this Autodesk.DesignScript.Geometry.Mesh mesh, TessellatedShapeBuilderTarget target = TessellatedShapeBuilderTarget.Mesh, TessellatedShapeBuilderFallback fallback = TessellatedShapeBuilderFallback.Salvage, ElementId MaterialId = null, bool performHostUnitConversion = true) { var verts = mesh.VertexPositions; var indices = mesh.FaceIndices; var tsb = new TessellatedShapeBuilder() { Fallback = fallback, Target = target, GraphicsStyleId = ElementId.InvalidElementId }; tsb.OpenConnectedFaceSet(false); for (int faceindex = 0, count = indices.Count(); faceindex < count; faceindex++) { var f = indices[faceindex]; //if this is a quad face triangulate it if (f.Count > 3) { //and add two triangles to the tessellated shape builder var tri1 = IndexGroup.ByIndices(f.B, f.C, f.A); var tri2 = IndexGroup.ByIndices(f.A, f.C, f.D); AddFace(tsb, tri1, verts, performHostUnitConversion, MaterialId); AddFace(tsb, tri2, verts, performHostUnitConversion, MaterialId); } else { AddFace(tsb, f, verts, performHostUnitConversion, MaterialId); } } tsb.CloseConnectedFaceSet(); tsb.Build(); var result = tsb.GetBuildResult(); foreach (IDisposable vert in verts) { vert.Dispose(); } return(result.GetGeometricalObjects()); }
internal sMesh TosMesh(Dyn.Mesh dym) { sMesh sm = new sMesh(); for (int i = 0; i < dym.VertexPositions.Length; ++i) { sm.SetVertex(i, new sXYZ(dym.VertexPositions[i].X, dym.VertexPositions[i].Y, dym.VertexPositions[i].Z)); // if (rm.VertexColors[i] != null) // { // sm.vertices[i].color = sColor.FromWinColor(rm.VertexColors[i]); // } } for (int i = 0; i < dym.FaceIndices.Length; ++i) { sm.SetFace(i, (int)dym.FaceIndices[i].A, (int)dym.FaceIndices[i].B, (int)dym.FaceIndices[i].C); } return(sm); }
/// <summary> /// Converts a Parasite Mesh to a Dynamo Mesh /// </summary> /// <param name="mesh">Parasite mesh object </param> /// <returns>A Dynamo Mesh object</returns> public static Autodesk.DesignScript.Geometry.Mesh ToDynamoType(Parasite_Mesh mesh) { int[][] faceIndexes = mesh.FaceIndexes; Parasite_Point3d[] verticesTemp = mesh.Vertices; List <IndexGroup> indexGroups = new List <IndexGroup>(); List <Autodesk.DesignScript.Geometry.Point> vertices = verticesTemp.Select(x => ToDynamoType(x)).ToList(); for (int i = 0; i < faceIndexes.Length; i++) { for (int j = 0; j < faceIndexes[i].Length; j++) { if (faceIndexes[i].Length == 3) { IndexGroup ig = IndexGroup.ByIndices((uint)faceIndexes[i][0], (uint)faceIndexes[i][1], (uint)faceIndexes[i][2]); indexGroups.Add(ig); } if (faceIndexes[i].Length == 4) { IndexGroup ig = IndexGroup.ByIndices((uint)faceIndexes[i][0], (uint)faceIndexes[i][1], (uint)faceIndexes[i][2], (uint)faceIndexes[i][3]); indexGroups.Add(ig); } if (faceIndexes[i].Length > 4 || faceIndexes[i].Length < 3) { throw new ParasiteArgumentException("A Dynamo mesh cant have a face with more than 4 vertices or less than 3"); } } } Autodesk.DesignScript.Geometry.Mesh dMesh = Autodesk.DesignScript.Geometry.Mesh.ByPointsFaceIndices(vertices, indexGroups); // TODO: Check for mesh validity return(dMesh); }
/// <summary> /// This method just creates a 10x10x10 cube and outputs it if the bool input is set to true. /// This was just a simple test to see if it would show up. /// </summary> public static Autodesk.DesignScript.Geometry.Mesh GetSimpleMesh(bool returnBox) { // Build vertex list List <Autodesk.DesignScript.Geometry.Point> vertices = new List <Autodesk.DesignScript.Geometry.Point>(); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0)); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(10, 0, 0)); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(10, 10, 0)); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 10, 0)); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 10)); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(10, 0, 10)); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(10, 10, 10)); vertices.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 10, 10)); // build mesh faces List <IndexGroup> faces = new List <IndexGroup>(); faces.Add(IndexGroup.ByIndices(3, 2, 1, 0)); faces.Add(IndexGroup.ByIndices(4, 5, 1, 0)); faces.Add(IndexGroup.ByIndices(5, 6, 2, 1)); faces.Add(IndexGroup.ByIndices(6, 7, 3, 2)); faces.Add(IndexGroup.ByIndices(7, 4, 0, 3)); faces.Add(IndexGroup.ByIndices(7, 6, 5, 4)); // create the mesh Autodesk.DesignScript.Geometry.Mesh mesh = Autodesk.DesignScript.Geometry.Mesh.ByPointsFaceIndices(vertices, faces); if (returnBox) { return(mesh); } else { return(null); } }
/// <summary> /// This is another private method, so Dynamo won't show it when it loads the library as a Zero Touch plugin. /// This method takes an Autodesk.Revit.DB.Solid from the Revit element and tessellates it to get an /// Autodesk.Revit.DB.Mesh from it. This mesh is then converted using the Revit.GeometryConversion referance /// to go from the Autodesk.Revit.DB.Mesh to an Autodesk.DesignScript.Geometry.Mesh. /// </summary> /// <param name="solid">Autodesk.Revit.DB.Solid geometry object to mesh.</param> /// <returns>An Autodesk.DesignScript.Geometry.Mesh from the solid.</returns> private static dsGeo.Mesh SolidToMesh(Solid solid) { dsGeo.Mesh mesh = null; // Each face of a solid is tessellated separately into a unique mesh, so we first // Collect all of the meshes that represent a solid's face. List <dsGeo.Mesh> unjoinedMeshes = new List <dsGeo.Mesh>(); foreach (Face f in solid.Faces) { // call the Triangulate method for the Autodesk.Revit.DB.Face Mesh rMesh = f.Triangulate(); // Use Revit.GeometryConversion.RevitToProtoMesh.ToProtoType method to convert the // Autodesk.Revit.DB.Mesh to an Autodesk.DesignScript.Geometry.Mesh dsGeo.Mesh dMesh = RevitToProtoMesh.ToProtoType(rMesh, true); unjoinedMeshes.Add(dMesh); } // Join meshes if (unjoinedMeshes.Count == 1) { mesh = unjoinedMeshes[0]; } else { // Join all of the meshes into a single mesh representing the input solid. List <dsGeo.Point> vertices = new List <dsGeo.Point>(); List <dsGeo.IndexGroup> indexGroups = new List <dsGeo.IndexGroup>(); foreach (dsGeo.Mesh m in unjoinedMeshes) { if (m == null) { continue; } // A count of the verticies that exist at the start of adding the current mesh. // This is the base index for specifying the vertex index for each mesh face. int baseCount = vertices.Count; // Then add the vertices of this current mesh to the list. vertices.AddRange(m.VertexPositions); // Build the Mesh Faces (Autodesk.DesignScript.Geometry.IndexGroup) for this mesh and add it to // the list of Autodesk.DesignScript.Geometry.IndexGroups. foreach (dsGeo.IndexGroup ig in m.FaceIndices) { // Three vertices for the face if (ig.Count == 3) { // The current meshes vertex indices starts at 0, but the new one will start at baseCount. dsGeo.IndexGroup iGroup = dsGeo.IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount)); indexGroups.Add(iGroup); } // Four vertices for the face. else { // The current meshes vertex indices starts at 0, but the new one will start at baseCount. dsGeo.IndexGroup iGroup = dsGeo.IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount), (uint)(ig.D + baseCount)); indexGroups.Add(iGroup); } } } // Create a new Autodesk.DesignScript.Geometry.Mesh based on the new list of Vertices and IndexGroups (mesh faces) dsGeo.Mesh joinedMesh = dsGeo.Mesh.ByPointsFaceIndices(vertices, indexGroups); if (joinedMesh != null) { mesh = joinedMesh; } } return(mesh); }
/// <summary> /// Iterate through the elements to /// </summary> /// <param name="elements"></param> /// <param name="currentViewOnly"></param> /// <param name="elemsInView"></param> /// <returns></returns> private static List <List <dsGeo.Mesh> > GetMeshes(List <rElems.Element> elements, bool currentViewOnly, List <int> elemsInView) { List <List <dsGeo.Mesh> > dynamoMeshes = new List <List <dsGeo.Mesh> >(); foreach (rElems.Element rElem in elements) { List <dsGeo.Mesh> elemMeshes = new List <dsGeo.Mesh>(); if (rElem != null) { // If the optional CurrentViewOnly input for the node is true, check to make // sure the element that we're looking for is actually visible in the view. // There's no sense in getting it's geometry if it's not there to begin with. if (currentViewOnly && !elemsInView.Contains(rElem.Id)) { elemMeshes.Add(null); } else { // Get an Autodesk.Revit.DB.Element from the Revit.Elements.Element's Id property. Element revElem = rDoc.GetElement(new ElementId(rElem.Id)); // Get the GeometryElement for the current revElem GeometryElement geoElement = revElem.get_Geometry(geoOpt); // Check to see if the geoElement is null, and if so return add a list with a single null object and continue. if (null == geoElement) { elemMeshes.Add(null); dynamoMeshes.Add(elemMeshes); continue; } // If the GeometryElement is not null, lets continue by grabbing the objects in it. foreach (GeometryObject geoObj in geoElement) { // The GeometryObject could be a GeometryInstasnce if we're dealing with a typical family or even an import // but will just start returning the geometry objects (Solid, Mesh, Line, etc.) if it's a System Family. // Check if it's a geometry object we'll need to go deeper, otherwise we'll just need to check for the right geometry. if (geoObj is GeometryInstance) { // Iterate through the objects in the instance to get the appropriate geometry. GeometryInstance geoInst = geoObj as GeometryInstance; foreach (GeometryObject instObj in geoInst.GetInstanceGeometry()) { if (instObj is Solid) { Solid solid = instObj as Solid; if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size) { continue; } else { // Convert the Solid to a Dynamo Mesh dsGeo.Mesh dMesh = SolidToMesh(solid); elemMeshes.Add(dMesh); } } else if (instObj is Mesh) { Mesh rMesh = instObj as Mesh; if (null == rMesh || 0 == rMesh.Vertices.Count) { continue; } else { dsGeo.Mesh dMesh = RevitToProtoMesh.ToProtoType(rMesh, true); elemMeshes.Add(dMesh); } } } } else if (geoObj is Solid) { Solid solid = geoObj as Solid; if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size) { continue; } else { // Convert the Solid to a Dynamo Mesh dsGeo.Mesh dMesh = SolidToMesh(solid); elemMeshes.Add(dMesh); } } else if (geoObj is Mesh) { Mesh rMesh = geoObj as Mesh; if (null == rMesh || 0 == rMesh.Vertices.Count) { continue; } else { dsGeo.Mesh dMesh = RevitToProtoMesh.ToProtoType(rMesh, true); elemMeshes.Add(dMesh); } } } } } if (elemMeshes.Count == 0) { elemMeshes.Add(null); } dynamoMeshes.Add(elemMeshes); } return(dynamoMeshes); }
public MeshBinder(Autodesk.DesignScript.Geometry.Mesh mesh) : this(mesh, DynaShapeDisplay.DefaultMeshFaceColor) { }
private static Autodesk.DesignScript.Geometry.Mesh SolidToMesh(Autodesk.Revit.DB.Solid solid) { Autodesk.DesignScript.Geometry.Mesh mesh = null; List <Autodesk.DesignScript.Geometry.Mesh> unjoinedMeshes = new List <Autodesk.DesignScript.Geometry.Mesh>(); foreach (Autodesk.Revit.DB.Face f in solid.Faces) { Autodesk.Revit.DB.Mesh rMesh = f.Triangulate(); Autodesk.DesignScript.Geometry.Mesh dMesh = RevitToProtoMesh.ToProtoType(rMesh, true); unjoinedMeshes.Add(dMesh); } // Join meshes if (unjoinedMeshes.Count == 0) { mesh = unjoinedMeshes[0]; } else { // Join all of the meshes? List <Autodesk.DesignScript.Geometry.Point> vertices = new List <Autodesk.DesignScript.Geometry.Point>(); List <IndexGroup> indexGroups = new List <IndexGroup>(); foreach (Autodesk.DesignScript.Geometry.Mesh m in unjoinedMeshes) { if (m == null) { continue; } int baseCount = vertices.Count; foreach (Autodesk.DesignScript.Geometry.Point pt in m.VertexPositions) { vertices.Add(pt); } foreach (IndexGroup ig in m.FaceIndices) { if (ig.Count == 3) { IndexGroup iGroup = IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount)); indexGroups.Add(iGroup); } else { IndexGroup iGroup = IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount), (uint)(ig.D + baseCount)); indexGroups.Add(iGroup); } } } try { Autodesk.DesignScript.Geometry.Mesh joinedMesh = Autodesk.DesignScript.Geometry.Mesh.ByPointsFaceIndices(vertices, indexGroups); if (joinedMesh != null) { mesh = joinedMesh; simpleMeshes.Add(joinedMesh); } } catch { // For now just add them all as is } } return(mesh); }
public static Parasite_Mesh ToParasiteType(Autodesk.DesignScript.Geometry.Mesh mesh, Dictionary <string, string> properties = null) { throw new NotImplementedException(); }
/// <summary> /// Create a new DirectShape element from given /// list of faces and return the number of faces /// processed. /// Return -1 if a face vertex index exceeds the /// total number of available vertices, /// representing a fatal error. /// </summary> public static DirectShape NewDirectShape( //List<XYZ> vertices, Autodesk.DesignScript.Geometry.Mesh mesh, //FaceCollection faces, //UIDocument UIdoc, //ElementId graphicsStyleId, //string appGuid, string shapeName) { int nFaces = 0; int nFacesFailed = 0; Document doc = DocumentManager.Instance.CurrentDBDocument; string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString(); // Retrieve "<Sketch>" graphics style, // if it exists. FilteredElementCollector collector = new FilteredElementCollector(doc) .OfClass(typeof(GraphicsStyle)); GraphicsStyle style = collector.Cast <GraphicsStyle>() .FirstOrDefault <GraphicsStyle>(gs => gs.Name.Equals("<Sketch>")); ElementId graphicsStyleId = null; if (style != null) { graphicsStyleId = style.Id; } TessellatedShapeBuilder builder = new TessellatedShapeBuilder(); builder.LogString = shapeName; List <Autodesk.DesignScript.Geometry.Point> corners = new List <Autodesk.DesignScript.Geometry.Point>(4); List <XYZ> XYZcorners = new List <XYZ>(4); builder.OpenConnectedFaceSet(false); // foreach (Face f in faces) //{ builder.LogInteger = nFaces; if (corners.Capacity < mesh.FaceIndices.Length) { corners = new List <Autodesk.DesignScript.Geometry.Point>(mesh.FaceIndices.Length); XYZcorners = new List <XYZ>(mesh.FaceIndices.Length); } corners.Clear(); XYZcorners.Clear(); foreach (IndexGroup i in mesh.FaceIndices) { //Debug.Assert(vertices.Count > i.vertex, // "how can the face vertex index be larger " // + "than the total number of vertices?"); corners.Add(mesh.VertexPositions[i.A]); XYZcorners.Add(new XYZ(mesh.VertexPositions[(int)i.A].X, mesh.VertexPositions[(int)i.A].Y, mesh.VertexPositions[(int)i.A].Z)); corners.Add(mesh.VertexPositions[(int)i.B]); XYZcorners.Add(new XYZ(mesh.VertexPositions[(int)i.B].X, mesh.VertexPositions[(int)i.B].Y, mesh.VertexPositions[(int)i.B].Z)); corners.Add(mesh.VertexPositions[(int)i.C]); XYZcorners.Add(new XYZ(mesh.VertexPositions[(int)i.C].X, mesh.VertexPositions[(int)i.C].Y, mesh.VertexPositions[(int)i.C].Z)); if (i.Count > 3) { corners.Add(mesh.VertexPositions[(int)i.D]); XYZcorners.Add(new XYZ(mesh.VertexPositions[(int)i.D].X, mesh.VertexPositions[(int)i.D].Y, mesh.VertexPositions[(int)i.D].Z)); } } try { builder.AddFace(new TessellatedFace(XYZcorners, ElementId.InvalidElementId)); ++nFaces; } catch (Autodesk.Revit.Exceptions.ArgumentException ex) { // Remember something went wrong here. ++nFacesFailed; Debug.Print( "Revit API argument exception {0}\r\n" + "Failed to add face with {1} corners: {2}", ex.Message, corners.Count, string.Join(", ", XYZcorners.Select <XYZ, string>( p => Util.PointString(p)))); } //} builder.CloseConnectedFaceSet(); // Refer to StlImport sample for more clever // handling of target and fallback and the // possible combinations. TessellatedShapeBuilderResult r = builder.Build( TessellatedShapeBuilderTarget.Mesh, TessellatedShapeBuilderFallback.Salvage, graphicsStyleId); ConversionLog myLog = new ConversionLog("c:\\conversionLogFileName.txt"); DataConversionMonitorScope myLoggingScope = new DataConversionMonitorScope(myLog); TessellatedShapeBuilderOutcome testOutcome = r.Outcome; IList <GeometryObject> test = r.GetGeometricalObjects(); try { TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); DirectShape ds = DirectShape.CreateElement( doc, _categoryId, appGuid, shapeName); ds.SetShape(r.GetGeometricalObjects()); ds.Name = shapeName; Debug.Print( "Shape '{0}': added {1} face{2}, {3} face{4} failed.", shapeName, nFaces, Util.PluralSuffix(nFaces), nFacesFailed, Util.PluralSuffix(nFacesFailed)); TransactionManager.Instance.TransactionTaskDone(); return(ds); } catch (Exception ex) { Debug.Print( "Problem with adding DirectShape: " + ex.Message.ToString()); return(null); } }
public MeshBinder(Autodesk.DesignScript.Geometry.Mesh mesh, Color color) { StartingPositions = mesh.VertexPositions.ToTriples().ToArray(); Color = color; faces = mesh.FaceIndices; }