public void UploadTobimsync(UI.ModelSelection modelSelection, string access_token) { RestClient client = new RestClient("https://api.bimsync.com"); string filename = Path.GetFileName(_path); string comment = Services.RemoveControlCharacters(modelSelection.Comment); //Upload the IFC model RestRequest revisionRequest = new RestRequest("v2/projects/" + modelSelection.ProjectId + "/revisions", Method.POST); revisionRequest.AddHeader("Authorization", "Bearer " + access_token); revisionRequest.AddHeader("Content-Type", "application/ifc"); revisionRequest.AddHeader("Bimsync-Params", "{" + "\"callbackUrl\": \"http://127.0.0.1:63842/\"," + "\"comment\": \"" + comment + "\"," + "\"filename\": \"" + filename + "\"," + "\"model\": \"" + modelSelection.ModelId + "\"}"); byte[] data = File.ReadAllBytes(_path); revisionRequest.AddParameter("application/ifc", data, RestSharp.ParameterType.RequestBody); IRestResponse reponseUpload = client.Execute(revisionRequest); if (reponseUpload.ErrorException != null) { string message = "Opps! There has been an error while uploading your model. " + reponseUpload.ErrorException.Message; throw new Exception(message); } }
public void ExportToIFC(Document doc, UI.ModelSelection modelSelection) { // Prepare the export options IFCExportOptions IFCOptions = new IFCExportOptions(); UI.IFCExportConfigurationCustom selectedConfig = modelSelection.Configuration; ElementId activeViewId = GenerateActiveViewIdFromDocument(doc); selectedConfig.ActiveViewId = selectedConfig.UseActiveViewGeometry ? activeViewId.IntegerValue : -1; selectedConfig.UpdateOptions(IFCOptions, activeViewId); string folder = System.IO.Path.GetTempPath(); string name = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + System.IO.Path.GetFileNameWithoutExtension(doc.PathName) + ".ifc"; _path = Path.Combine(folder, name); doc.Export(folder, name, IFCOptions); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; using (Transaction tx = new Transaction(doc)) { try { //Refresh the token and save it Token token = Services.RefreshToken(Properties.Settings.Default["Token"] as Token); Properties.Settings.Default["Token"] = token; Properties.Settings.Default.Save(); string access_token = token.access_token; //Load the interface to select these project and model UI.ModelSelection modelSelection = new UI.ModelSelection(access_token, doc, uiapp); if (modelSelection.ShowDialog() == true) { tx.Start("Export to bimsync"); //If necessary, add Shared parameters to store bimsync model and project AddSharedParameters(app, doc); //Write the values to these parameters WriteOnParam("project_id", doc, modelSelection.ProjectId); WriteOnParam("model_id", doc, modelSelection.ModelId); //Export IFC ExportToIFC(doc, modelSelection); CompressFile(); UploadTobimsync(modelSelection, access_token); File.Delete(_path); tx.Commit(); // Return Success return(Result.Succeeded); } else { return(Autodesk.Revit.UI.Result.Cancelled); } } catch (Autodesk.Revit.Exceptions.OperationCanceledException exceptionCanceled) { message = exceptionCanceled.Message; if (tx.HasStarted() == true) { tx.RollBack(); } return(Autodesk.Revit.UI.Result.Cancelled); } catch (Exception ex) { // unchecked exception cause command failed message = ex.Message; //Trace.WriteLine(ex.ToString()); if (tx.HasStarted() == true) { tx.RollBack(); } return(Autodesk.Revit.UI.Result.Failed); } } }