void ExportElements( IJtFaceEmitter emitter, FilteredElementCollector collector, Options opt) { int nElements = 0; int nSolids = 0; // 导出所有构建 foreach (Element e in collector) { nElements += ExportElement(emitter, e, opt, ref nSolids); } int nFaces = emitter.GetFaceCount(); int nTriangles = emitter.GetTriangleCount(); int nVertices = emitter.GetVertexCount(); string msg = string.Format( "{0} element{1} with {2} solid{3}, " + "{4} face{5}, {6} triangle{7} and " + "{8} vertice{9} exported.", nElements, ObjExportUtil.PluralSuffix(nElements), nSolids, ObjExportUtil.PluralSuffix(nSolids), nFaces, ObjExportUtil.PluralSuffix(nFaces), nTriangles, ObjExportUtil.PluralSuffix(nTriangles), nVertices, ObjExportUtil.PluralSuffix(nVertices)); InfoMsg(msg); }
/// <summary> /// Export a non-empty solid. /// </summary> bool ExportSolid( IJtFaceEmitter emitter, Document doc, Solid solid, Color color, int transparency) { Material m; Color c; int t; foreach (Face face in solid.Faces) { m = doc.GetElement( face.MaterialElementId) as Material; c = (null == m) ? color : m.Color; t = (null == m) ? transparency : m.Transparency; emitter.EmitFace(face, (null == c) ? DefaultColor : c, t); } return(true); }
/// <summary> /// Export an element, i.e. all non-empty solids /// encountered, and return the number of elements /// exported. /// If the element is a group, this method is /// called recursively on the group members. /// </summary> int ExportElement( IJtFaceEmitter emitter, Element e, Options opt, ref int nSolids) { if (e is Group group) { int n = 0; foreach (ElementId id in group.GetMemberIds()) { Element e2 = e.Document.GetElement(id); n += ExportElement(emitter, e2, opt, ref nSolids); } return(n); } string desc = ObjExportUtil.ElementDescription(e); Category cat = e.Category; if (null == cat) { Debug.Print("Element '{0}' has no category.", desc); return(0); } Material material = cat.Material; // Column category has no material, maybe all // family instances have no defualt material, // so we cannot simply skip them here: //if( null == material ) //{ // Debug.Print( "Category '{0}' of element '{1}' " // + "has no material.", cat.Name, desc ); // return 0; //} Color color = material?.Color; int transparency = (null == material) ? 0 : material.Transparency; //Debug.Assert( null != color, // "expected a valid category material colour" ); nSolids += ExportSolids(emitter, e, opt, color, transparency); return(1); }
int ExportSolids( IJtFaceEmitter emitter, Element e, Options opt, Color color, int shininess, int transparency) { int nSolids = 0; GeometryElement geo = e.get_Geometry(opt); Solid solid; if (null != geo) { Document doc = e.Document; if (e is FamilyInstance) { geo = geo.GetTransformed(Transform.Identity); } GeometryInstance inst = null; foreach (GeometryObject obj in geo) { solid = obj as Solid; if (null != solid && 0 < solid.Faces.Size && ExportSolid(emitter, doc, solid, color, shininess, transparency)) { ++nSolids; } inst = obj as GeometryInstance; } if (0 == nSolids && null != inst) { geo = inst.GetSymbolGeometry(); foreach (GeometryObject obj in geo) { solid = obj as Solid; if (null != solid && 0 < solid.Faces.Size && ExportSolid(emitter, doc, solid, color, shininess, transparency)) { ++nSolids; } } } } return(nSolids); }
int ExportElement( IJtFaceEmitter emitter, Element e, Options opt, ref int nSolids) { Group group = e as Group; if (null != group) { int n = 0; foreach (ElementId id in group.GetMemberIds()) { Element e2 = e.Document.GetElement(id); n += ExportElement(emitter, e2, opt, ref nSolids); } return(n); } string desc = Util.ElementDescription(e); Category cat = e.Category; if (null == cat) { Debug.Print("Element '{0}' has no " + "category.", desc); return(0); } Material material = cat.Material; Color color = (null == material) ? null : material.Color; int transparency = (null == material) ? 0 : material.Transparency; int shininess = (null == material) ? 0 : material.Shininess; nSolids += ExportSolids(emitter, e, opt, color, shininess, transparency); return(1); }
/// <summary> /// Export all non-empty solids found for /// the given element. Family instances may have /// their own non-empty solids, in which case /// those are used, otherwise the symbol geometry. /// The symbol geometry could keep track of the /// instance transform to map it to the actual /// project location. Instead, we ask for /// transformed geometry to be returned, so the /// resulting solids are already in place. /// </summary> int ExportSolids( IJtFaceEmitter emitter, Element e, Options opt, Color color, int transparency) { int nSolids = 0; GeometryElement geo = e.get_Geometry(opt); Solid solid; if (null != geo) { Document doc = e.Document; if (e is FamilyInstance) { geo = geo.GetTransformed(Transform.Identity); } GeometryInstance inst = null; //Transform t = Transform.Identity; // Some columns have no solids, and we have to // retrieve the geometry from the symbol; // others do have solids on the instance itself // and no contents in the instance geometry // (e.g. in rst_basic_sample_project.rvt). foreach (GeometryObject obj in geo) { solid = obj as Solid; if (null != solid && 0 < solid.Faces.Size && ExportSolid(emitter, doc, e, solid, color, transparency)) { ++nSolids; } inst = obj as GeometryInstance; } if (0 == nSolids && null != inst) { geo = inst.GetSymbolGeometry(); //t = inst.Transform; foreach (GeometryObject obj in geo) { solid = obj as Solid; if (null != solid && 0 < solid.Faces.Size && ExportSolid(emitter, doc, e, solid, color, transparency)) { ++nSolids; } } } } return(nSolids); }
/// <summary> /// Export all non-empty solids found for /// the given element. Family instances may have /// their own non-empty solids, in which case /// those are used, otherwise the symbol geometry. /// The symbol geometry could keep track of the /// instance transform to map it to the actual /// project location. Instead, we ask for /// transformed geometry to be returned, so the /// resulting solids are already in place. /// </summary> int ExportSolids( IJtFaceEmitter emitter, Element e, Options opt, Color color, int transparency ) { int nSolids = 0; GeometryElement geo = e.get_Geometry( opt ); Solid solid; if( null != geo ) { Document doc = e.Document; if( e is FamilyInstance ) { geo = geo.GetTransformed( Transform.Identity ); } GeometryInstance inst = null; //Transform t = Transform.Identity; // Some columns have no solids, and we have to // retrieve the geometry from the symbol; // others do have solids on the instance itself // and no contents in the instance geometry // (e.g. in rst_basic_sample_project.rvt). foreach( GeometryObject obj in geo ) { solid = obj as Solid; if( null != solid && 0 < solid.Faces.Size && ExportSolid( emitter, doc, solid, color, transparency ) ) { ++nSolids; } inst = obj as GeometryInstance; } if( 0 == nSolids && null != inst ) { geo = inst.GetSymbolGeometry(); //t = inst.Transform; foreach( GeometryObject obj in geo ) { solid = obj as Solid; if( null != solid && 0 < solid.Faces.Size && ExportSolid( emitter, doc, solid, color, transparency ) ) { ++nSolids; } } } } return nSolids; }
/// <summary> /// Export a non-empty solid. /// </summary> bool ExportSolid( IJtFaceEmitter emitter, Document doc, Solid solid, Color color, int transparency ) { Material m; Color c; int t; foreach( Face face in solid.Faces ) { m = doc.GetElement( face.MaterialElementId ) as Material; c = ( null == m ) ? color : m.Color; t = ( null == m ) ? transparency : m.Transparency; emitter.EmitFace( face, (null == c) ? DefaultColor : c, t ); } return true; }
void ExportElements( IJtFaceEmitter emitter, FilteredElementCollector collector, Options opt ) { int nElements = 0; int nSolids = 0; foreach( Element e in collector ) { nElements += ExportElement( emitter, e, opt, ref nSolids ); } int nFaces = emitter.GetFaceCount(); int nTriangles = emitter.GetTriangleCount(); int nVertices = emitter.GetVertexCount(); string msg = string.Format( "{0} element{1} with {2} solid{3}, " + "{4} face{5}, {6} triangle{7} and " + "{8} vertice{9} exported.", nElements, Util.PluralSuffix( nElements ), nSolids, Util.PluralSuffix( nSolids ), nFaces, Util.PluralSuffix( nFaces ), nTriangles, Util.PluralSuffix( nTriangles ), nVertices, Util.PluralSuffix( nVertices ) ); InfoMsg( msg ); }
/// <summary> /// Export an element, i.e. all non-empty solids /// encountered, and return the number of elements /// exported. /// If the element is a group, this method is /// called recursively on the group members. /// </summary> int ExportElement( IJtFaceEmitter emitter, Element e, Options opt, ref int nSolids ) { Group group = e as Group; if( null != group ) { int n = 0; foreach( ElementId id in group.GetMemberIds() ) { Element e2 = e.Document.GetElement( id ); n += ExportElement( emitter, e2, opt, ref nSolids ); } return n; } string desc = Util.ElementDescription( e ); Category cat = e.Category; if( null == cat ) { Debug.Print( "Element '{0}' has no " + "category.", desc ); return 0; } Material material = cat.Material; // Column category has no material, maybe all // family instances have no defualt material, // so we cannot simply skip them here: //if( null == material ) //{ // Debug.Print( "Category '{0}' of element '{1}' " // + "has no material.", cat.Name, desc ); // return 0; //} Color color = ( null == material ) ? null : material.Color; int transparency = ( null == material ) ? 0 : material.Transparency; //Debug.Assert( null != color, // "expected a valid category material colour" ); nSolids += ExportSolids( emitter, e, opt, color, transparency ); return 1; }