/// <summary> /// Export FBX format /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); views.Insert(m_activeDoc.ActiveView); FBXExportOptions options = new FBXExportOptions(); exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); return exported; }
/// <summary> /// Export FBX format /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); views.Insert(m_activeDoc.ActiveView); FBXExportOptions options = new FBXExportOptions(); exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); return(exported); }
private bool ExportFBX(DesignAutomationData data) { if (data == null) { return(false); } Application app = data.RevitApp; if (app == null) { return(false); } string modelPath = data.FilePath; if (string.IsNullOrWhiteSpace(modelPath)) { return(false); } var doc = data.RevitDoc; if (doc == null) { return(false); } using (var collector = new FilteredElementCollector(doc)) { LogTrace("Collecting 3D views..."); var exportPath = Path.Combine(Directory.GetCurrentDirectory(), "exported"); if (!Directory.Exists(exportPath)) { try { Directory.CreateDirectory(exportPath); } catch (Exception ex) { this.PrintError(ex); return(false); } } LogTrace(string.Format("Export Path: {0}", exportPath)); var veiwIds = collector.WhereElementIsNotElementType() .OfClass(typeof(View3D)) .WhereElementIsNotElementType() .Cast <View3D>() .Where(v => !v.IsTemplate) .Select(v => v.Id); if (veiwIds == null || veiwIds.Count() <= 0) { LogTrace("No 3D views to be exported..."); return(false); } LogTrace("Starting the export task..."); try { foreach (var viewId in veiwIds) { var exportOpts = new FBXExportOptions(); exportOpts.StopOnError = true; exportOpts.WithoutBoundaryEdges = true; var view = doc.GetElement(viewId) as View3D; var name = view.Name; name = name.Replace("{", "_").Replace("}", "_").ReplaceInvalidFileNameChars(); var filename = string.Format("{0}.fbx", name); LogTrace(string.Format("Exporting {0}...", filename)); var viewSet = new ViewSet(); viewSet.Insert(view); doc.Export(exportPath, filename, viewSet, exportOpts); } } catch (Autodesk.Revit.Exceptions.InvalidPathArgumentException ex) { this.PrintError(ex); return(false); } catch (Autodesk.Revit.Exceptions.ArgumentException ex) { this.PrintError(ex); return(false); } catch (Autodesk.Revit.Exceptions.InvalidOperationException ex) { this.PrintError(ex); return(false); } catch (Exception ex) { this.PrintError(ex); return(false); } } return(true); }
Stream(ArrayList data, FBXExportOptions fbxExpOptions) { data.Add(new Snoop.Data.ClassSeparator(typeof(FBXExportOptions))); data.Add(new Snoop.Data.Bool("Stop on error", fbxExpOptions.StopOnError)); }
CollectEvent(object sender, CollectorEventArgs e) { // cast the sender object to the SnoopCollector we are expecting Collector snoopCollector = sender as Collector; if (snoopCollector == null) { Debug.Assert(false); // why did someone else send us the message? return; } // see if it is a type we are responsible for Color color = e.ObjToSnoop as Color; if (color != null) { Stream(snoopCollector.Data(), color); return; } LayoutRule layoutRule = e.ObjToSnoop as LayoutRule; if (layoutRule != null) { Stream(snoopCollector.Data(), layoutRule); return; } FormatOptions formatOptions = e.ObjToSnoop as FormatOptions; if (formatOptions != null) { Stream(snoopCollector.Data(), formatOptions); return; } CurtainGrid curtainGrid = e.ObjToSnoop as CurtainGrid; if (curtainGrid != null) { Stream(snoopCollector.Data(), curtainGrid); return; } CurtainCell curtainCell = e.ObjToSnoop as CurtainCell; if (curtainCell != null) { Stream(snoopCollector.Data(), curtainCell); return; } RebarHostData rebarHostData = e.ObjToSnoop as RebarHostData; if (rebarHostData != null) { Stream(snoopCollector.Data(), rebarHostData); return; } Leader leader = e.ObjToSnoop as Leader; if (leader != null) { Stream(snoopCollector.Data(), leader); return; } AreaVolumeSettings areaSettings = e.ObjToSnoop as AreaVolumeSettings; if (areaSettings != null) { Stream(snoopCollector.Data(), areaSettings); return; } ViewSheetSetting viewSheetSetting = e.ObjToSnoop as ViewSheetSetting; if (viewSheetSetting != null) { Stream(snoopCollector.Data(), viewSheetSetting); return; } Autodesk.Revit.UI.Events.DialogBoxData dlgBoxData = e.ObjToSnoop as Autodesk.Revit.UI.Events.DialogBoxData; if (dlgBoxData != null) { Stream(snoopCollector.Data(), dlgBoxData); return; } Construction construct = e.ObjToSnoop as Construction; if (construct != null) { Stream(snoopCollector.Data(), construct); return; } FamilyElementVisibility famElemVisib = e.ObjToSnoop as FamilyElementVisibility; if (famElemVisib != null) { Stream(snoopCollector.Data(), famElemVisib); return; } FamilyManager famManager = e.ObjToSnoop as FamilyManager; if (famManager != null) { Stream(snoopCollector.Data(), famManager); return; } FamilyParameter famParam = e.ObjToSnoop as FamilyParameter; if (famParam != null) { Stream(snoopCollector.Data(), famParam); return; } FamilyType famType = e.ObjToSnoop as FamilyType; if (famType != null) { Stream(snoopCollector.Data(), famType); return; } MEPSpaceConstruction mepSpaceConstuct = e.ObjToSnoop as MEPSpaceConstruction; if (mepSpaceConstuct != null) { Stream(snoopCollector.Data(), mepSpaceConstuct); return; } BuildingSiteExportOptions bldSiteExpOptions = e.ObjToSnoop as BuildingSiteExportOptions; if (bldSiteExpOptions != null) { Stream(snoopCollector.Data(), bldSiteExpOptions); return; } DGNExportOptions dgnExpOptions = e.ObjToSnoop as DGNExportOptions; if (dgnExpOptions != null) { Stream(snoopCollector.Data(), dgnExpOptions); return; } DWFExportOptions dwfExpOptions = e.ObjToSnoop as DWFExportOptions; if (dwfExpOptions != null) { Stream(snoopCollector.Data(), dwfExpOptions); return; } DWGExportOptions dwgExpOptions = e.ObjToSnoop as DWGExportOptions; if (dwgExpOptions != null) { Stream(snoopCollector.Data(), dwgExpOptions); return; } DWGImportOptions dwgImpOptions = e.ObjToSnoop as DWGImportOptions; if (dwgImpOptions != null) { Stream(snoopCollector.Data(), dwgImpOptions); return; } FBXExportOptions fbxExpOptions = e.ObjToSnoop as FBXExportOptions; if (fbxExpOptions != null) { Stream(snoopCollector.Data(), fbxExpOptions); return; } TrussMemberInfo trussInfo = e.ObjToSnoop as TrussMemberInfo; if (trussInfo != null) { Stream(snoopCollector.Data(), trussInfo); return; } VertexIndexPair vertIndPair = e.ObjToSnoop as VertexIndexPair; if (vertIndPair != null) { Stream(snoopCollector.Data(), vertIndPair); return; } PointElementReference ptElemRef = e.ObjToSnoop as PointElementReference; if (ptElemRef != null) { Stream(snoopCollector.Data(), ptElemRef); return; } Autodesk.Revit.DB.Architecture.BoundarySegment boundSeg = e.ObjToSnoop as Autodesk.Revit.DB.Architecture.BoundarySegment; if (boundSeg != null) { Stream(snoopCollector.Data(), boundSeg); return; } PointLocationOnCurve ptLocOnCurve = e.ObjToSnoop as PointLocationOnCurve; if (ptLocOnCurve != null) { Stream(snoopCollector.Data(), ptLocOnCurve); return; } Entity entity = e.ObjToSnoop as Entity; if (entity != null) { Stream(snoopCollector.Data(), entity); return; } Field field = e.ObjToSnoop as Field; if (field != null) { Stream(snoopCollector.Data(), field); return; } ExtensibleStorageField storeagefield = e.ObjToSnoop as ExtensibleStorageField; if (storeagefield != null) { Stream(snoopCollector.Data(), storeagefield); return; } IList <Autodesk.Revit.DB.BoundarySegment> boundSegs = e.ObjToSnoop as IList <Autodesk.Revit.DB.BoundarySegment>; if (boundSegs != null) { Stream(snoopCollector.Data(), boundSegs); return; } if (e.ObjToSnoop is KeyValuePair <String, String> ) { KeyValuePair <String, String> stringspair = (KeyValuePair <String, String>)e.ObjToSnoop; Stream(snoopCollector.Data(), stringspair); return; } Schema schema = e.ObjToSnoop as Schema; if (schema != null) { Stream(snoopCollector.Data(), schema); return; } ElementId elemId = e.ObjToSnoop as ElementId; if (elemId != null) { Stream(snoopCollector.Data(), elemId); return; } PlanViewRange plvr = e.ObjToSnoop as PlanViewRange; if (plvr != null) { Stream(snoopCollector.Data(), plvr); return; } //TF RebarConstraintsManager rbcm = e.ObjToSnoop as RebarConstraintsManager; if (rbcm != null) { Stream(snoopCollector.Data(), rbcm); return; } RebarConstrainedHandle rbch = e.ObjToSnoop as RebarConstrainedHandle; if (rbch != null) { Stream(snoopCollector.Data(), rbch); return; } RebarConstraint rbc = e.ObjToSnoop as RebarConstraint; if (rbc != null) { Stream(snoopCollector.Data(), rbc); return; } //TFEND if (Utils.IsSupportedType(e.ObjToSnoop) && e.ObjToSnoop != null) { Utils.StreamWithReflection(snoopCollector.Data(), e.ObjToSnoop.GetType(), e.ObjToSnoop); } }
/// <summary> /// Exports all elements in 3D View to separate .fbx files. /// </summary> public string Export(Autodesk.Revit.DB.Document document) { Autodesk.Revit.DB.Document doc = document; Autodesk.Revit.DB.View activeView = doc.ActiveView; FBXExportOptions options = new FBXExportOptions(); if (activeView.ViewType != ViewType.ThreeD) { TaskDialog.Show("Warning", "Can only be run in 3D View."); return("Failed"); } ElementOwnerViewFilter elementOwnerViewFilter = new ElementOwnerViewFilter(activeView.Id); FilteredElementCollector col = new FilteredElementCollector(doc, activeView.Id) .WhereElementIsNotElementType(); ICollection <ElementId> allAlements = col.ToElementIds(); IList <Element> viewElements = col.ToElements(); using (System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog()) { if (folderDialog.ShowDialog() != DialogResult.OK) { return("No folder chosen."); } string folder = folderDialog.SelectedPath; // Filtered element collector is iterable ViewSet viewSet = new ViewSet(); int c = 0; foreach (Element e in col) { using (Transaction tx = new Transaction(doc)) { tx.Start(String.Format("Export element {0}", e.Id.ToString())); activeView.IsolateElementTemporary(e.Id); activeView.ConvertTemporaryHideIsolateToPermanent(); viewSet.Insert(activeView); doc.Export(folder, e.Id.ToString(), viewSet, options); activeView.UnhideElements(allAlements); doc.Regenerate(); tx.Commit(); } viewSet.Clear(); c++; } string runMessage = String.Format("Run {0} times", c); TaskDialog.Show("Result", runMessage); return(String.Format("Successfully exported {0} elements", c)); } }
private string ExportToFbx() { try { double building_width = 0; double building_length = 0; ElementCategoryFilter eleFilter;//the class varies from Autodesk.Revit.DB? y FilteredElementCollector collector;//the class varies from Autodesk.Revit.DB? y IList<Element> filteredObject;// the interface of System.Collections.Generic? y where did it state it is the interface? in .net lib string semanticInfo = "";//store all semantic information string commentParameter = "";//store the comment parameter in left column revit //get ground objects //read semantic information from revit file //for floor eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);// get all floor objects in revit project collector = new FilteredElementCollector(uidoc.Document);//the same way to get objects in revit filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements();// the same way to get objects in revit //we create filter instance and all objects instance. then we pass filter into all objects to get filteredbojects. foreach (Element e in filteredObject)//go throught each item/objects in revit model { commentParameter = GetParameterInformation(e.Parameters, uidoc.Document, "Comments"); string level = GetParameterInformation(e.Parameters, uidoc.Document, "Level"); if (level.ToLower() == "level 0") { CalculateArea(e.Parameters, uidoc.Document, ref building_width, ref building_length); if (building_width > 100 || building_length > 100) { TaskDialog.Show("Error", "W: " + building_width + ", L: " + building_length + ". Size is too big for our application."); return "Size Error."; } } if (commentParameter == "emergency") semanticInfo += e.Id + "-emergency,"+level+"\n";// explain this please. put id and emergency into the whole semantic information list with different line. else semanticInfo += e.Id + "-ground," + level + "\n"; } //for stairs eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Stairs); collector = new FilteredElementCollector(uidoc.Document); filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements(); foreach (Element e in filteredObject) { semanticInfo += e.Id + "-stair\n"; } //get obstacle objects///for walls eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);//I get all walls collector = new FilteredElementCollector(uidoc.Document); filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements(); foreach (Element e in filteredObject)//I loop each wall. I want to check the COMMENT property of each wall { /*//this block is used to get Comment property in revit commentParameter = "";//this parameter store Comment property value foreach (Parameter para in e.Parameters)//loop each property { try { commentParameter = GetParameterInformation(para, uidoc.Document).ToLower(); if (commentParameter == "wood") break; } catch (Exception ex) { //cannot get info, we know it and we don't need to write it } } //if it is wood, we set wood to the semantic file, otherwise it is obstable (brick) if (commentParameter == "wood") semanticInfo += e.Id + "-wood\n"; //else if (status == "somethingelse") //content += e.Id + "-somethingelse\n"; else*/ semanticInfo += e.Id + "-obstacle\n"; } //for doors eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); collector = new FilteredElementCollector(uidoc.Document); filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements(); foreach (Element e in filteredObject) { commentParameter = GetParameterInformation(e.Parameters, uidoc.Document, "Comments"); if (commentParameter == "closed") semanticInfo += e.Id + "-obstacle\n"; else if (commentParameter == "opened") semanticInfo += e.Id + "-openeddoor\n"; else semanticInfo += e.Id + "-openeddoor\n"; // else mean the default status??? yes SetParameter(e.Parameters, "Comments", "test"); } string path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); CreateTempFolder(path + "\\revitfbx\\"); //output //System.IO.Directory.CreateDirectory("revitfbx"); System.IO.File.Delete(path + "\\revitfbx\\building.fbx"); System.IO.File.Delete(path + "\\revitfbx\\semantic.txt"); //we write new fbx //////////////////////////// ViewSet views = new ViewSet(); views.Insert(uidoc.ActiveView); FBXExportOptions exportoption = new FBXExportOptions(); //here, revit forces us to use a folder. I forgot that. so we have to use a folder. uidoc.Document.Export(path + "\\revitfbx", "building.fbx", views, exportoption);//generate fbx file ///////////////////////////// //we write new semantic Utility.WriteFile(path + "\\revitfbx\\semantic.txt", semanticInfo, false); //send semantic and 3d fbx model to PHP server NameValueCollection paras = new NameValueCollection(); paras.Add("sid", selectedSid); paras.Add("act", "ClientSendModelFile"); string web = client.UploadFileEx(path + "\\revitfbx\\building.fbx", AppConst.SERVER_DOMAIN + AppConst.SERVER_PATH, "building", null, paras); if (web.Trim() != "") return "Unknown error"; paras = new NameValueCollection(); paras.Add("sid", selectedSid); paras.Add("act", "ClientSendSemanticFile"); client.UploadFileEx(path + "\\revitfbx\\semantic.txt", AppConst.SERVER_DOMAIN + AppConst.SERVER_PATH, "semantic", null, paras); return "done"; } /////////////////////////// catch (Exception ex) { TaskDialog.Show("Error", ex.Message); return ex.Message; } }
/// <summary> /// Exports all elements in 3D View to separate .fbx files. /// </summary> public static string Export(Autodesk.Revit.DB.Document document, System.Windows.Forms.ProgressBar progressBar, System.Windows.Forms.Label label, System.Windows.Forms.Label percent) { Autodesk.Revit.DB.Document doc = document; Autodesk.Revit.DB.View activeView = doc.ActiveView; FBXExportOptions options = new FBXExportOptions(); if (activeView.ViewType != ViewType.ThreeD) { TaskDialog.Show("Warning", "Can only be run in 3D View."); return("Failed"); } ElementOwnerViewFilter elementOwnerViewFilter = new ElementOwnerViewFilter(activeView.Id); FilteredElementCollector col = new FilteredElementCollector(doc, activeView.Id) .WhereElementIsNotElementType(); ICollection <ElementId> allAlements = col.ToElementIds(); using (System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog()) { if (folderDialog.ShowDialog() != DialogResult.OK) { return("No folder chosen."); } string folder = folderDialog.SelectedPath; // Filtered element collector is iterable ViewSet viewSet = new ViewSet(); int c = 0; ICollection <ElementId> removedElements = new List <ElementId>(); //Hide everything first using (Transaction t = new Transaction(doc, "Hide all")) { t.Start(); foreach (ElementId e in allAlements) { if (e == null) { continue; } try { if (doc.GetElement(e).Category.Name.Contains("Curtain") || doc.GetElement(e).Category.Name.Contains("Lines") || doc.GetElement(e).Category.Name.Contains("Top Rails") || doc.GetElement(e).Category.Name.Contains("Shaft Openings")) { removedElements.Add(e); continue; } } catch (Exception) { } ICollection <ElementId> element = new List <ElementId>() { e }; try { activeView.HideElements(element); } catch (Exception ex) { Console.WriteLine(ex); removedElements.Add(e); } } t.Commit(); } foreach (var obj in removedElements) { allAlements.Remove(obj); } progressBar.Minimum = 0; progressBar.Maximum = allAlements.Count; string regexSearch = new string(System.IO.Path.GetInvalidFileNameChars()); //Unhide each element one by one and export a view with it foreach (ElementId e in allAlements) { ICollection <ElementId> element = new List <ElementId>() { e }; if (e == null) { continue; } var el = doc.GetElement(e); if (el.Category == null) { continue; } if (el.Category.Name == null) { continue; } string category = el.Category.Name; string famtype = el.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString(); string name = String.Format("{0}-{1}-id{2}", category, famtype, e.ToString()); Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch))); name = r.Replace(name, ""); using (Transaction tx = new Transaction(doc)) { tx.Start(String.Format("Export element {0}", e.ToString())); activeView.UnhideElements(element); doc.Regenerate(); viewSet.Insert(activeView); try { doc.Export(folder, name, viewSet, options); } catch (Exception ex) { TaskDialog.Show("Error", String.Format("There has been a problem executing this script.{0}{1}", Environment.NewLine, ex.Message)); } activeView.HideElements(element); tx.Commit(); } viewSet.Clear(); progressBar.Value++; label.Text = String.Format("Exported {0} of {1}", progressBar.Value.ToString(), progressBar.Maximum.ToString()); label.Refresh(); percent.Text = String.Format("{0}{1}", (Convert.ToInt16((progressBar.Value / (progressBar.Maximum * 1.0)) * 100)).ToString(), "%"); percent.Refresh(); c++; } //Finally unhide everything back using (Transaction t = new Transaction(doc, "Hide all")) { t.Start(); activeView.UnhideElements(allAlements); t.Commit(); } string runMessage = String.Format("Successfully exported {0} elements", c); TaskDialog.Show("Result", runMessage); return(runMessage); } }
private bool ExportFBX(DesignAutomationData data) { if (data == null) { return(false); } Application app = data.RevitApp; if (app == null) { LogTrace("Error occured"); LogTrace("Invalid Revit App"); return(false); } string modelPath = data.FilePath; if (string.IsNullOrWhiteSpace(modelPath)) { LogTrace("Error occured"); LogTrace("Invalid File Path"); return(false); } var doc = data.RevitDoc; if (doc == null) { LogTrace("Error occured"); LogTrace("Invalid Revit DB Document"); return(false); } var inputParams = JsonConvert.DeserializeObject <InputParams>(File.ReadAllText("params.json")); if (inputParams == null) { LogTrace("Invalid Input Params or Empty JSON Input"); return(false); } using (var collector = new FilteredElementCollector(doc)) { LogTrace("Creating export folder..."); var exportPath = Path.Combine(Directory.GetCurrentDirectory(), "exportedFBXs"); if (!Directory.Exists(exportPath)) { try { Directory.CreateDirectory(exportPath); } catch (Exception ex) { this.PrintError(ex); return(false); } } LogTrace(string.Format("Export Path: {0}", exportPath)); LogTrace("Collecting 3D views..."); IEnumerable <ElementId> viewIds = null; if (inputParams.ExportAll == true) { viewIds = collector.WhereElementIsNotElementType() .OfClass(typeof(View3D)) .WhereElementIsNotElementType() .Cast <View3D>() .Where(v => !v.IsTemplate) .Select(v => v.Id); } else { try { if (inputParams.ViewIds == null || inputParams.ViewIds.Count() <= 0) { throw new InvalidDataException("Invalid input viewIds while the exportAll value is false!"); } var viewElemIds = new List <ElementId>(); foreach (var viewGuid in inputParams.ViewIds) { var view = doc.GetElement(viewGuid); if (view == null || (!(view is View3D))) { throw new InvalidDataException(string.Format("3D view not found with guid `{0}`", viewGuid)); } viewElemIds.Add(view.Id); } viewIds = viewElemIds; } catch (Exception ex) { this.PrintError(ex); return(false); } } if (viewIds == null || viewIds.Count() <= 0) { LogTrace("Error occured"); LogTrace("No 3D views to be exported..."); return(false); } LogTrace("Starting the export task..."); try { foreach (var viewId in viewIds) { var exportOpts = new FBXExportOptions(); exportOpts.StopOnError = true; exportOpts.WithoutBoundaryEdges = true; var view = doc.GetElement(viewId) as View3D; var name = view.Name; name = name.Replace("{", "_").Replace("}", "_").ReplaceInvalidFileNameChars(); var filename = string.Format("{0}.fbx", name); LogTrace(string.Format("Exporting {0}...", filename)); var viewSet = new ViewSet(); viewSet.Insert(view); doc.Export(exportPath, filename, viewSet, exportOpts); } } catch (Autodesk.Revit.Exceptions.InvalidPathArgumentException ex) { this.PrintError(ex); return(false); } catch (Autodesk.Revit.Exceptions.ArgumentException ex) { this.PrintError(ex); return(false); } catch (Autodesk.Revit.Exceptions.InvalidOperationException ex) { this.PrintError(ex); return(false); } catch (Exception ex) { this.PrintError(ex); return(false); } } LogTrace("Exporting completed..."); return(true); }