.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Progress Meter code works but donot show on Autocad UI

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
mr_anildangi
151 Views, 2 Replies

Progress Meter code works but donot show on Autocad UI

I have this code in C# where the code compiles perfectly but i do not see progress meter on ACAD UI.

[CommandMethod("PilePlacement")]
public static void Main() 
{
   doc = Application.DocumentManager.MdiActiveDocument;
	ed = doc.Editor;
	db = doc.Database;
	try
	{
      // Show progress bar window on a separate thread
      //progressBarThread = new Thread(() =>
      //{
      //   progressBarWindow = new ProgressBarWindow();
      //   progressBarWindow.Show();
      //   System.Windows.Threading.Dispatcher.Run();
      //});

      //progressBarThread.SetApartmentState(ApartmentState.STA);
      //progressBarThread.Start();
      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");

      // Start the progress meter
      // Start the progress meter
      ProgressMeter progressMeter = new ProgressMeter();
      progressMeter.Start("Placing piles...");
      progressMeter.SetLimit(tableNames.Count);

      foreach (string tableName in tableNames)
		{
			string currTable = tableName;
			if(currTable.Contains("(Ext)")) currTable = currTable.Replace("(Ext)", "");
			AddPileDrawingToDB(tableName, allBlockReferences[currTable][0]);

         // Update the progress meter
         progressMeter.MeterProgress();

         // This allows AutoCAD to repaint
         System.Windows.Forms.Application.DoEvents();
      }
		ChangeVisibility();

      // Close the progress bar window on the UI thread
      //if (progressBarWindow != null && progressBarWindow.Dispatcher != null)
      //{
      //   progressBarWindow.Dispatcher.Invoke(() => progressBarWindow.Close());
      //};

      // Stop the progress meter
      progressMeter.Stop();

      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);
   }
   //finally
   //{
   //   // Ensure the progress bar thread is closed
   //   if (progressBarThread != null && progressBarThread.IsAlive)
   //   {
   //      progressBarThread.Join();
   //   }
   //}
}
2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: mr_anildangi

ProgressMeter is not reliable visual indicator of looped code execution running. It would highly depend on what the code does and how AutoCAD/Windows OS decide when some of AutoCAD window components being updated. From my years of .NET plugin development experience, the only reliable way to show visual progress of looped AutoCAD code execution is to use MODAL form, as @ActivistInvestor suggested in your other post, which you have accept as the solution to your question.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
mr_anildangi
in reply to: mr_anildangi

Thanks for the insight. I have created Modal WPF window for that purpose but I was trying to exploit inbuilt ProgressMeter class for the said purpose. Again Thanks for info.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report