How to update progress bar simultaneously with some code execution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I creating a simple Addin for Revit for joining wall and column.
That addin contain form. When I click addin it display the windows form as I attached the image.
If I select item wall and column from drop down list and click the button It join wall and column successfully and show message.For this is create a class name as WCjoin.cs.This class I call from form button click event.
But I dont want to do that I want progress bar which update the progress bar when class is executing and wall column is joining.
I write the code for that but it update the progress bar after class is executed.
This is the code:
Form Code:-
using System;
using System.Windows.Forms;
using Autodesk.Revit.UI;
namespace JoinGeometry
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public partial class AdvanceJoin : Form
{
ExternalCommandData commandData;
public AdvanceJoin(ExternalCommandData commandDatax)
{
commandData = commandDatax;
InitializeComponent();
}
private void AdvanceJoin_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Wall and Column");
}
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Value = 0;
timer1.Stop();
timer1.Start();
if (comboBox1.SelectedItem == "Wall" && comboBox2.SelectedItem == "Column")
{
try
{
WCjoin wcj = new WCjoin();
wcj.Execute(commandData);
label2.Text = "WALL COLUMN JOINED";
}
catch (Exception g)
{
TaskDialog.Show("revit", "error is occured" + g);
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Increment(5);
}
}
}
Code :Class WCjoin.cs
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace JoinGeometry
{
[Transaction(TransactionMode.Manual)]
class WCjoin
{
bool check;
public Result Execute(ExternalCommandData commandData)
{
UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;
FilteredElementCollector collWalls = new FilteredElementCollector(doc, doc.ActiveView.Id);
collWalls.OfClass(typeof(Wall));
foreach (Wall w in collWalls)
{
FilteredElementCollector collColumnsOnThisWall = new FilteredElementCollector(doc, doc.ActiveView.Id);
collColumnsOnThisWall.OfClass(typeof(FamilyInstance));
collColumnsOnThisWall.OfCategory(BuiltInCategory.OST_StructuralColumns);
BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView);
Outline outline = new Outline(bb.Min, bb.Max);
BoundingBoxIntersectsFilter bbfilter =new BoundingBoxIntersectsFilter(outline);
collColumnsOnThisWall.WherePasses(bbfilter);
foreach (FamilyInstance column in collColumnsOnThisWall)
{
using (Transaction t = new Transaction(doc, "Join All Walls/Column"))
{
t.Start();
check = JoinGeometryUtils.AreElementsJoined(doc, w, column);
if (check == true)
{
}
else
{
JoinGeometryUtils.JoinGeometry(doc, w, column);
}
t.Commit();
}
}
}
return Result.Succeeded;
}
}
}
I want to update progress bar while WCjoin class is executing and after the class WCjoin has been successfully completed the progress bar has been stoped with full 100%
What I should do for achieveing my target.