private Boolean WritePLYFile(LuxExporter.PLY.PLY_By_Material item, String sOutputPathSceneFile) { try { //get lists List<String> VerticesIndexList = item.GetIndecisList(); List<String> VerticesList = item.GetVerticesList(); //check whether file exists System.IO.FileInfo finfo = new System.IO.FileInfo(sOutputPathSceneFile); if (finfo.Exists) { System.Windows.Forms.MessageBox.Show("WritePLYFile::Element id: " + vRevitElement.Id.ToString()+" OutPut:"+sOutputPathSceneFile); // throw new System.InvalidOperationException("FileExists"); ; } //write list out to geometry file using (System.IO.StreamWriter PLYFile = new System.IO.StreamWriter(sOutputPathSceneFile)) { Int32 iNumberofVertices = item.NoOfVertice(); Int32 iNumberofFaces = item.NoofFaces; //write out PLY header string[] lines_Header = {"ply", "format ascii 1.0", "comment Created by LuxExporter Revit 0.1 exporter for LuxRender - www.luxrender.net", "element vertex "+iNumberofVertices.ToString(), //add number of vertices here "property float x", "property float y", "property float z", "property float nx", "property float ny", "property float nz", // "property float s", // "property float t", "element face "+iNumberofFaces.ToString(), //add number of faces here "property list uchar uint vertex_indices", "end_header"}; foreach (String Header in lines_Header) { PLYFile.WriteLine(Header); } //write out index list foreach (String Index in VerticesList) { PLYFile.WriteLine(Index); } //write out index list foreach (String Index in VerticesIndexList) { PLYFile.WriteLine(Index); } //close PLY file PLYFile.Close(); } return true; } catch (Exception) { System.Windows.Forms.MessageBox.Show("Error in module Revit_Geometry_Worker (WritePLYFile) "); return false; } }
private String ExportElementList(IEnumerable<Element> ElementList, View3D ExportView, Autodesk.Revit.DB.Options GeometryOption, String sOutputPathGeoFile, String sPLYFilePath, LuxExporter.Revit_Linked_Files RevitLink) { //set up export string list List<StringBuilder> ListExport = new List<StringBuilder>(); //setup list containing topo information List<Autodesk.Revit.DB.TopographySurface> lTopos = new List<TopographySurface>(); //setup list containing Lights List<FamilyInstance> Lights = new List<FamilyInstance>(); //setup list containing instance information List<LuxExporter.Revit_Instance> lFamilyInstances = new List<Revit_Instance>(); List<String> LDebug = new List<string>(); //loop through all elements and export foreach (Element item in ElementList) { //check when link if item is visible in view if (!IsHiddenElementOrCategory(item,ExportView)) { //debug LDebug.Add(item.Id.ToString() + " " + item.GetType().ToString()); //check for topo surface and add to collection if true for later processing if (item.GetType() == typeof(Autodesk.Revit.DB.TopographySurface)) { lTopos.Add(item as Autodesk.Revit.DB.TopographySurface); //jump to next item continue; } //check whether we have a link file and add link identifier to object name String LinkName = ""; if (RevitLink!=null) { LinkName = RevitLink.LinkShortName; } else { LinkName = null; } //check whether we can instance the element //create unique family type name LuxExporter.Revit_Instance objInstance = new Revit_Instance(item, vDoc,LinkName); //flag for bounding box check Boolean BoundingBoxOK = true; //only if view has sectionbox active! if (ExportView.SectionBox.Enabled) { //get boundingbox of item BoundingBoxXYZ ElementBounding = item.get_BoundingBox(ExportView); //if link I will need to transform the items boundingbox by the link transformatio if (RevitLink!=null) { //get the first transform (models clashing with section box will only have one) Transform t= RevitLink.Transformations[0]; //ElementBounding = new BoundingBoxXYZ(t.OfPoint(ElementBounding.Max, t.OfPoint(ElementBounding.Min))); } //get sectionbox Autodesk.Revit.DB.BoundingBoxXYZ ViewSectionBox = ExportView.SectionBox; //check whether element bounding box is completely enclosed in view bounding box if not disable instancing! LuxExporter.Revit_BoundingBox_Checker checker = new Revit_BoundingBox_Checker(); BoundingBoxOK = checker.BoundingBox_Checker(ElementBounding, ViewSectionBox); } //check whether we have a lighting fixture family if (objInstance.CategoryName == "lighting fixtures") { //add family to list Lights.Add(item as Autodesk.Revit.DB.FamilyInstance); } //check whether family contains light sources List<FamilyInstance> NestedLights = objInstance.GetNestedLightFamilies(); if (NestedLights != null) { //add nested families to list foreach (FamilyInstance iLight in NestedLights) { Lights.Add(iLight); } } //check if we have a family vs system family and whether family is completely within section box if (!objInstance.ElementIsSystemFamily && BoundingBoxOK) { //export geometry //get the export string from geometry class try { StringBuilder dummy = new StringBuilder(""); //check whether item is allready in list if (lFamilyInstances.Contains(objInstance)) { //instanciate lux object dummy.AppendLine(CreateLuxObjectInstanceFromFamily(objInstance, RevitLink).ToString()); //add to output ListExport.Add(dummy); } else { // instanciate worker class and pass geo element to it Revit_Geometry_Worker Exporter = new Revit_Geometry_Worker(item, sPLYFilePath, vDoc); //get geo data without transformation StringBuilder ExportString = Exporter.ExportToPLY_Solid(GeometryOption,false); //need to check whether instance has location point if yes add to list other wise no instancing enabled!! Boolean CheckForInsertionPoint = objInstance.HasInsertionPoint(); String sPrefix = ""; //check whether this item comes from linked file if (objInstance.HostName!=null) { sPrefix = objInstance.HostName + "_"; } //check whether item has insertion point if (CheckForInsertionPoint) { //'add the instance to list only if instance has an insertion point rather then a insertion curve lFamilyInstances.Add(objInstance); dummy.AppendLine("ObjectBegin " + "\"" + sPrefix + objInstance.GetUniqueFamilyInstanceName.ToString() + "\""); } else { dummy.AppendLine("ObjectBegin " + "\"" + sPrefix + item.UniqueId.ToString() + "\""); } if (ExportString != null) { ListExport.Add(dummy); //add ply data to list... ListExport.Add(ExportString); //place an instance of the object dummy = new StringBuilder(""); dummy.AppendLine("ObjectEnd"); dummy.AppendLine(""); dummy.AppendLine(CreateLuxObjectInstanceFromFamily(objInstance, RevitLink).ToString()); ListExport.Add(dummy); } } } catch (Exception) { MessageBox.Show("Error while trying to export family instance"); throw; } } else //system family { try { // instanciate worker class and pass geo element to it Revit_Geometry_Worker Exporter = new Revit_Geometry_Worker(item, sPLYFilePath, vDoc); //get geo data StringBuilder ExportString = Exporter.ExportToPLY_Solid(GeometryOption,false); //set up lux string if (ExportString != null) { StringBuilder dummy = new StringBuilder(""); //get export string dummy=CreateLuxAttribute(ExportString, RevitLink, item.UniqueId.ToString()); //add to export list ListExport.Add(dummy); if (RevitLink!=null) { ///if this is a link file add instance stuff dummy = CreateLuxInstanceFromSystemFamily(RevitLink, item.UniqueId.ToString()); //add to export list ListExport.Add(dummy); } } } catch (Exception) { MessageBox.Show("Error while trying to eport system family"); throw; } } } //debugging //write out element id String sOutputPathDebugFile = ""; if (RevitLink!=null) { sOutputPathDebugFile = vOutputFilePath + "/" + "Debug_" + RevitLink.UniqueLinkName.ToString() + ".txt"; } else { sOutputPathDebugFile = vOutputFilePath + "/" + "Debug.txt"; } using (System.IO.StreamWriter DebugFile = new System.IO.StreamWriter(sOutputPathDebugFile)) { foreach (String debug in LDebug) { DebugFile.WriteLine(debug); } } } try { //process any topography surface if found if (lTopos.Count > 0) { //loop through all topos found foreach (TopographySurface itemT in lTopos) { // instanciate worker class and pass geo element to it Revit_Geometry_Worker Exporter = new Revit_Geometry_Worker(itemT, sPLYFilePath, vDoc); //get geo data StringBuilder ExportString = Exporter.ExportToPLY_Mesh(GeometryOption,RevitLinkTransform); if (ExportString != null) { StringBuilder dummy = new StringBuilder(""); //get formatted export string dummy = CreateLuxAttribute(ExportString, RevitLink, itemT.UniqueId.ToString()); //add to export list ListExport.Add(dummy); if (RevitLink != null) { //if this is a link file add instance stuff dummy = CreateLuxInstanceFromSystemFamily(RevitLink, itemT.UniqueId.ToString()); //add to export list ListExport.Add(dummy); } } } } } catch (Exception) { MessageBox.Show("Failed to export topo"); throw; } try { //process any lights found foreach (FamilyInstance item in Lights) { //check whether familyinstance already processed before... //process lights //LuxExporter.Revit_Light_Worker LightProcessor = new Revit_Light_Worker(item, vDoc); //StringBuilder ExportString = LightProcessor.ExportLight(GeometryOption); //if (ExportString != null) //{ // //StringBuilder dummy = new StringBuilder(""); // //dummy = CreateLuxAttribute(ExportString, RevitLink, item.UniqueId.ToString()); // //ListExport.Add(dummy); // //if (RevitLink != null) // //{ // // dummy = CreateLuxInstanceFromNonFamily(RevitLink, item.UniqueId.ToString()); // // ListExport.Add(dummy); // //} //} } //create geo file try { //write list out to geometry file using (System.IO.StreamWriter GeoFile = new System.IO.StreamWriter(sOutputPathGeoFile)) { foreach (StringBuilder line in ListExport) { GeoFile.WriteLine(line); } } } catch (Exception) { MessageBox.Show("Failed to write geoFile"); throw; } return sOutputPathGeoFile; } catch (Exception) { MessageBox.Show("Failed To Export Lights"); throw; } }
private StringBuilder CreateLuxInstanceFromSystemFamily(LuxExporter.Revit_Linked_Files RevitLink, String ObjectName) { StringBuilder dummy = new StringBuilder(""); foreach (Transform item in RevitLink.Transformations) { dummy.AppendLine("AttributeBegin"); dummy.AppendLine("TransformBegin"); //calculate Transformation matrix LuxExporter.Revit_Transform TransFormMatrix = new Revit_Transform(); String sTransFormMatrix = TransFormMatrix.TransformationInHost(item); //finalise output string dummy.AppendLine("#Revit T CreateLuxInstanceFromNonFamily"); dummy.AppendLine("Transform [" + sTransFormMatrix + "]"); dummy.AppendLine("ObjectInstance \"" + RevitLink.LinkShortName + "_" + ObjectName + "\""); dummy.AppendLine("TransformEnd"); dummy.AppendLine("AttributeEnd"); dummy.AppendLine(""); } return dummy; }
private StringBuilder CreateLuxObjectInstanceFromFamily(LuxExporter.Revit_Instance objInstance, LuxExporter.Revit_Linked_Files RevitLink) { StringBuilder dummy = new StringBuilder(); if (RevitLink==null) { dummy.AppendLine("AttributeBegin"); dummy.AppendLine("TransformBegin"); //calculate Transformation matrix LuxExporter.Revit_Transform TransFormMatrix = new Revit_Transform(); String sTransFormMatrix = TransFormMatrix.TransformationInHost(objInstance.FamilyTransform); //finalise output string dummy.AppendLine("#Revit T CreateLuxObjectInstanceFromFamily"); dummy.AppendLine("Transform [" + sTransFormMatrix + "]"); dummy.AppendLine("ObjectInstance \"" + objInstance.GetUniqueFamilyInstanceName.ToString() + "\""); dummy.AppendLine("TransformEnd"); dummy.AppendLine("AttributeEnd"); } else { foreach (Transform item in RevitLink.Transformations) { dummy.AppendLine("AttributeBegin"); dummy.AppendLine("TransformBegin"); //calculate Transformation matrix LuxExporter.Revit_Transform TransFormMatrix = new Revit_Transform(); String sTransFormMatrix = TransFormMatrix.TransformationInLink(objInstance, item); //finalise output string dummy.AppendLine("#Revit T ..."); dummy.AppendLine("Transform [" + sTransFormMatrix + "]"); dummy.AppendLine("ObjectInstance \"" + objInstance.HostName+"_"+ objInstance.GetUniqueFamilyInstanceName.ToString() + "\""); dummy.AppendLine("TransformEnd"); dummy.AppendLine("AttributeEnd"); dummy.AppendLine(""); } } return dummy; }
private StringBuilder CreateLuxAttribute(StringBuilder ExportString, LuxExporter.Revit_Linked_Files RevitLink, String ObjectName) { StringBuilder dummy = new StringBuilder(""); if (RevitLink==null) { //add export string dummy.AppendLine(ExportString.ToString()); //add blank line dummy.AppendLine(""); } else { //add object namw dummy.AppendLine("ObjectBegin " + "\"" + RevitLink.LinkShortName + "_" + ObjectName + "\""); //add export string dummy.AppendLine(ExportString.ToString()); //close object dummy.AppendLine("ObjectEnd"); } //return new list return dummy; }