using Autodesk.Revit.DB;
|
using Autodesk.Revit.UI;
|
using MFire;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.IO;
|
using System.Linq;
|
using System.Reflection.Emit;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
namespace HStation.RevitDev.RevitToBimface.Forms
|
{
|
public partial class UploadFile : System.Windows.Forms.Form
|
{
|
private UIDocument _uiDocument;
|
private Document _doc;
|
private string bimAppKey = "";
|
private string bimAppSecret = "";
|
|
private long step = 0;
|
public UploadFile(ExternalCommandData data)
|
{
|
_uiDocument = data.Application.ActiveUIDocument;
|
_doc = _uiDocument.Document;
|
InitializeComponent();
|
|
backgroundWorker1.WorkerReportsProgress = true;
|
backgroundWorker1.DoWork += new DoWorkEventHandler(Do);
|
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(DoChanged);
|
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(DoCompleted);
|
}
|
|
private void button2_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
|
private void Do(object sender, DoWorkEventArgs e)
|
{
|
for (int i = 1; i <= 10; i++)
|
{
|
backgroundWorker1.ReportProgress(i * 10);
|
Thread.Sleep(int.Parse(step.ToString()));
|
}
|
}
|
|
private void DoChanged(object sender, ProgressChangedEventArgs e)
|
{
|
progressBar1.Value = e.ProgressPercentage;
|
label1.Text = "正在上传中... " + e.ProgressPercentage + "%";
|
label1.Refresh();
|
}
|
|
private void DoCompleted(object sender, RunWorkerCompletedEventArgs e)
|
{
|
label1.Text = "上传完成!";
|
label1.Refresh();
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
{
|
label1.Text = "正在上传中...";
|
label2.Text = "";
|
textBox1.Text = "";
|
textBox1.Visible = false;
|
var info = new FileInfo(_doc.PathName);
|
step = info.Length / 1024 / 1024 / 10 * 100;
|
backgroundWorker1.RunWorkerAsync();
|
|
var dir = "d:\\Rvt" + DateTime.Now.ToString("yyyyMM");
|
var newFilePath = dir + _doc.PathName.Substring(_doc.PathName.LastIndexOf("\\"));
|
if (!Directory.Exists(dir))
|
Directory.CreateDirectory(dir);
|
if (File.Exists(newFilePath))
|
File.Delete(newFilePath);
|
File.Copy(_doc.PathName, newFilePath);
|
|
var client = BimfaceClient.GetClient(bimAppKey, bimAppSecret);
|
|
var uploadResult = client.UploadFilePolicy(newFilePath);
|
if (uploadResult != null && uploadResult.status == "success")
|
{
|
|
label2.Text = "模型上传成功,请将此字符串复制到业务系统中:";
|
textBox1.Text = uploadResult.fileId.Value.ToString();
|
textBox1.Visible = true;
|
|
File.Delete(newFilePath);
|
var transResult = client.TranslateRvt(uploadResult.fileId.Value, MFire.Bimface.eRvtTranslateStyle.Real);
|
if (transResult != null && transResult.status == "success")
|
{
|
|
}
|
}
|
}
|
}
|
}
|