how to show a custom progress bar in Autocad using wpf

how to show a custom progress bar in Autocad using wpf

mr_anildangi
Contributor Contributor
996 Views
2 Replies
Message 1 of 3

how to show a custom progress bar in Autocad using wpf

mr_anildangi
Contributor
Contributor

I have created this xaml for progress bar for tasks which takes time.

but when i load my dll containg this xaml and run it it minimizes.

<Window x:Class="SolarInfraCADAutomate.UI.ProgressBarWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SolarInfraCADAutomate.UI"
        mc:Ignorable="d"
        Title="ProgressBarWindow" Height="200" Width="400"
        WindowStartupLocation="CenterScreen"
        WindowStyle="None"
        Background="Transparent"
        >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.5*" />
            <RowDefinition Height="0.5*" />
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Center">
            <Label FontSize="32" FontWeight="Bold" Foreground="Beige">Loading ...</Label>
        </StackPanel>

        <StackPanel Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center">
            <ProgressBar Minimum="0" Maximum="100" Name="pbStatus" IsIndeterminate="True" Height="32" />
        </StackPanel>
    </Grid>
</Window>

 and implementation is like this

[assembly: CommandClass(typeof(SolarInfraCADAutomate.Piling.PilePlacement))]

namespace SolarInfraCADAutomate.Piling
{
	/// <summary>
	/// Class <c>PilePlacement</c> Places specific piles on user selected tables.
	/// </summary>
	internal class PilePlacement
	{
		private static Document doc;
		private static Editor ed;
		private static Database db;
		// Progress bar window.
		private static ProgressBarWindow progressBarWindow;
      // Member variable to check whether the type of table is fixtilt or tracker.
      public static bool isFixTilt = false;
		/// <summary>
		/// Method <b>PlacePiles</b> Places specific piles on user selected tables.
		/// </summary>
		public static void PlacePiles()
		{
			doc = Application.DocumentManager.MdiActiveDocument;
			UtilityFunctions.UnlockAllLayers(doc, doc.Editor, doc.Database, false);
         LayerOperations.HideTables();
         Log.Logger.Log("Initialized the document in PlacePiles funtion");
			Log.Logger.Log("Calling PilePlacement command");
			doc.SendStringToExecute("PilePlacement ", true, false, false);
         // Show progress bar window on the UI thread
         Dispatcher.CurrentDispatcher.Invoke(() => {
            progressBarWindow = new ProgressBarWindow();
            progressBarWindow.Show();
         });
      }
		
		[CommandMethod("PilePlacement")]
		public static void Main() 
		{
         doc = Application.DocumentManager.MdiActiveDocument;
			ed = doc.Editor;
			db = doc.Database;
			try
			{
				List<string> tableNames = MMSData.tables;
				MMSData.tablePiling = true;
				Dictionary <string, List < BlockReference >> allBlockReferences = MMSData.mmsTablesDict;
				Log.Logger.Log("Get list of table names and dictionary of table name and blocks from MMSData");
				//iterate through all the tables selected by user
				//string[] tableNames = { "MMS Table (32.2920 x 4.5760)", "MMS Table (128.58 x 2.278)" };
				Log.Logger.Log("iterate through all the tables selected by user");
				foreach (string tableName in tableNames)
				{
					string currTable = tableName;
					if(currTable.Contains("(Ext)")) currTable = currTable.Replace("(Ext)", "");
					AddPileDrawingToDB(tableName, allBlockReferences[currTable][0]);
				}
				ChangeVisibility();
            // Close the progress bar window on the UI thread
            Dispatcher.CurrentDispatcher.Invoke(() => {
               progressBarWindow.Close();
            });
            MessageBox.Show("Piles placed successfully !!", "Piling Automation", MessageBoxButton.OK, MessageBoxImage.Information);
			}
         catch (Autodesk.AutoCAD.Runtime.Exception ex)
         {
            Log.Logger.LogException(ex);
         }
         catch (System.Exception ex)
         {
            Log.Logger.LogException(ex);
         }
      }
0 Likes
Accepted solutions (1)
997 Views
2 Replies
Replies (2)
Message 2 of 3

ActivistInvestor
Mentor
Mentor
Accepted solution

You show the window using Show(), which shows the window modelessly.

 

Application.ShowModalWindow(), shows the window as a modal window, but blocks until the windows is closed, so you must initiate your processing from the Window (e.g., the Loaded event or something like that), and await the call to start the process, so that it doesn't block the UI from updating. You can pass a callback function to the process whose progress your window is reporting on, which the process would call periodically to update its progress. The callback can then update your UI each time it's called.

0 Likes
Message 3 of 3

mr_anildangi
Contributor
Contributor

Thanks for this great insight .

0 Likes