Author Topic: AcCoreConsole causes AutoCAD to flicker  (Read 16780 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #15 on: January 31, 2015, 02:27:33 AM »
See how this performs.
Probably easiest to just attach a little WPF app and let me know if any problems.
Project attached at bottom
  • Put dwg files in folder DwgFiles located in solution's root folder. Drawings in List Box on Left
  • Put script files in folder ScriptFiles located in solution's root folder. Files in List Box on right
  • Click Settings and make sure path to accoreconsole.exe is correct and change maximum seconds to run process before killing it if not yet finished.
Select a script file a click run script and see how performance is.

 
 
Class that does most of the work
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace WpfTestAcCoreConsole.Scripting
  9. {
  10.     public class ScriptProcessor
  11.     {
  12.         public string AcCoreLocation { get; set; }
  13.         public string ScriptFilepath { get; set; }
  14.         public string Language { get; set; }
  15.         public string Isolate { get; set; }
  16.         private CancellationTokenSource CTokenSource;
  17.         private int MaxTime { get; set; }
  18.         private string Arguments(string drawingPath)
  19.         {
  20.  
  21.             return String.Format("/i \"{0}\" /s \"{1}\" /l \"{2} \"/isolate\" {3}", drawingPath, ScriptFilepath,
  22.                 Language, Isolate);
  23.         }
  24.  
  25.         public ScriptProcessor(string acCoreLocation, string scriptFilePath, string isolate = "CoreConsole",
  26.             string language = "en-us")
  27.         {
  28.             AcCoreLocation = acCoreLocation;
  29.             ScriptFilepath = scriptFilePath;
  30.             Isolate = isolate;
  31.             Language = language;
  32.             CTokenSource = new CancellationTokenSource();
  33.             MaxTime = Properties.Settings.Default.MaxWaitTime * 1000;
  34.         }
  35.         private ProcessStartInfo CreateProcessStartInfo(FileInfo fi)
  36.         {
  37.             return new ProcessStartInfo()
  38.             {
  39.                 FileName = AcCoreLocation,
  40.                 Arguments = Arguments(fi.FullName),
  41.                 UseShellExecute = false,
  42.                 CreateNoWindow = true
  43.             };
  44.         }
  45.         public void Cancel()
  46.         {
  47.             CTokenSource.Cancel();
  48.         }
  49.         private ConcurrentQueue<FileInfo> fileQueue;
  50.         public async void ProcessFiles(ICollection<FileInfo> fileInfos, IProgress<ProgressInfo> pinfo)
  51.         {
  52.             fileQueue = new ConcurrentQueue<FileInfo>(fileInfos);
  53.             int cores = Interop.User32.NumberOfCores();
  54.             Task[] tasks = new Task[cores];
  55.             for (int i = 0; i < cores; i++)
  56.             {
  57.                 tasks[i] = RunAcCoreConsole(fileQueue, CTokenSource.Token, pinfo);
  58.             }
  59.             await Task.WhenAll(tasks);
  60.         }
  61.    
  62.    
  63.         private Task RunAcCoreConsole(ConcurrentQueue<FileInfo> que, CancellationToken ct, IProgress<ProgressInfo> pinfo)
  64.         {
  65.             return Task.Run(() =>
  66.             {
  67.                 FileInfo file;
  68.                 while (que.TryDequeue(out file))
  69.                 {
  70.                     ProgressInfo pi = new ProgressInfo(file.FullName, "Processing");
  71.                     DateTime orgDateTime = file.LastWriteTimeUtc;
  72.                     if (ct.IsCancellationRequested)
  73.                     {
  74.                         pi.Status = "Canceled";
  75.                         return;
  76.                     }
  77.                     pinfo.Report(pi);
  78.                     try
  79.                     {
  80.                         using (Process process = new Process())
  81.                         {
  82.                             process.StartInfo = CreateProcessStartInfo(file);
  83.                             process.Start();
  84.                             if (!process.WaitForExit(MaxTime))
  85.                             {
  86.                                 pi.Status = "Max Time Reached";
  87.                                 process.CloseMainWindow();
  88.                                 if (!process.WaitForExit(2000))
  89.                                 {
  90.                                     process.Kill();
  91.                                 }
  92.                                 continue;
  93.                             }
  94.  
  95.                         }
  96.                         file.Refresh();
  97.                         pi.Status = orgDateTime < file.LastWriteTimeUtc ? "Updated" : "Not Processed";
  98.                     }
  99.                     catch (Exception)
  100.                     {
  101.                         pi.Status = "Error";
  102.                     }
  103.                    
  104.                 }
  105.             }, ct);
  106.         }
  107.     }
  108. }
  109.  
  110.  

weslleywang

  • Mosquito
  • Posts: 3
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #16 on: February 02, 2015, 12:28:46 PM »
Hi Jeff:

  I cannot say thank you enough, it works prefect. I will digest and absorb every piece of it.


Thank you a thousand
Wes

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #17 on: February 02, 2015, 01:21:32 PM »
Just quickly off the top of my head so might be off but the main difference is previous version was creating a task for each drawing and this one creates a task for each core then each grab info from a Concurrent Collection.

So for a 4-core processor at first were creating 400 tasks and 400 process for 400 drawings,
but now 4 tasks and 400 process(100 each) for 400 drawings.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #18 on: August 22, 2015, 12:34:46 AM »
Looks like 2016 they made some changes but for the good.

It now correctly redirects the command line, and seems to run faster.

Attached is a updated version that displays the selected processed drawings command line.


djee

  • Newt
  • Posts: 49
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #19 on: August 25, 2015, 01:53:09 PM »
This is awesome work! Is it normal that it's not using the hyperthreaded cores (Logical Cores)... I got a 24 cores computer & i'm only seing 12 threads working? Also, could it be modified for selecting a script file (FilePrompt) instead of putting it in the script folder?
Nice work & thanks for sharing...
« Last Edit: August 25, 2015, 08:44:24 PM by djee »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #20 on: August 25, 2015, 02:53:12 PM »
Is it normal that it's not using the hyperthreaded cores...
Do not know what those are so not sure
Here is what gets them
Code - C#: [Select]
  1.             int cores = 0;
  2.             foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
  3.             {
  4.                 cores += int.Parse(item["NumberOfCores"].ToString());
  5.             }
  6.             return cores;
  7.  

and hyperthreaded cores and ManagementObjectSearcher bring this link up
http://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c

Also, could it be modified for selecting a script file (FilePrompt) instead of putting it in the script folder?
The same type of object is used for .dwg files that is used for .scr files.
Look button that adds .dwg from files of folders and can do the same for .scr.


Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #21 on: August 26, 2015, 12:59:06 AM »
Just updated for setting xrefs path to relative and just batched 188 files in 2~3 minutes setting all xrefs path to relative if anyone wants new version uploaded. Still in testing phase if not already obvious.




tbrammer

  • Guest
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #22 on: November 10, 2015, 05:59:51 AM »
Hi there,

I'm using ACC 2016 (SP1) for batch "plotting" with a very similiar approach to this discussed here.
I also start up to <NuberOfCores>-1 parallel instances of the ACC with ::CreateProcess().
And I also noticed the flicker problem on my 2-monitor system.

Q1) Flicker:
Is the flicker-issue gone for ACC 2016 and your latest changes?
If so: Can you tell what made it go away?

Q2) Script out of sync problem:
I put "plotting" in quotes becaus I actually create file output like PDF, PNG,...
ACC is started with pre-created .scr files like this:
Code: [Select]
FILEDIA
0
EXPERT
5
;---
_-PLOT
_no
1
A4-PDF


_no
_yes
;----
_-PLOT
_no
1
A4-PNG


_no
_yes
;
----

The two blank lines before _no _yes choose the default Device and default filename given in the page setup.
Problem: I don't know the output filename. So it may happen that the file already exists. In this case ACC will ask me whether I want to overwrite the file (regardless of the EXPERT value). Thus the rest of the script gets mis-interpreted.

Is there a way to determine the output plot-filename for a given page setup?
It would also help to find out the filename extension (.pdf / .png).
I could provide a meaningful output filename than and make sure it does not exist.
Obviously the name will depend upon the PC3-file used. Any ideas?

Cheers
--Thomas

tbrammer

  • Guest
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #23 on: December 14, 2015, 06:25:52 AM »
I've done a lot of R&D around the ACC of AutoCAD 2016 in the past weeks.
For me the flicker-issue disappears, if I use /isolate <regkey> <work_dir> and /p acad switches as argumets of accoreconsole.exe.

If you want to run multiple instances of ACC parallel it is absolutely required to use /isolate <regkey> <working_dir> :

   accoreconsole /i c:\drwA.dwg /s c:\myscript.scr /isolate user1 c:\temp\acc1
   accoreconsole /i c:\drwB.dwg /s c:\myscript.scr /isolate user2 c:\temp\acc2
   ...
   accoreconsole /i c:\drwX.dwg /s c:\myscript.scr /isolate user7 c:\temp\acc7


See also http://adndevblog.typepad.com/autocad/2015/02/parallel-aggregation-using-accoreconsole.html

ACC will create a temporary registry path like
  HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R20.1\CoreUser\user2
It will always contain the user profiles <<Unnamed Profile>> and acad.
Never specifiy a non-existing profile name!  /p acad  works great in my tests.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #24 on: December 14, 2015, 08:59:22 PM »
Thanks for info tbrammer!

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: AcCoreConsole causes AutoCAD to flicker
« Reply #25 on: October 25, 2017, 10:33:09 PM »
I tried Parallel.ForEach() but it would launch 2-100+ accoreconsole processes(depending on number of drawings) and that was the only way I knew to keep it down to a certain number.
yeah, years later but this may be handy for Googlers - you can limit the parallelism there. see https://stackoverflow.com/a/9290531/492

I haven't really been near core console since they broke it in v2015: https://forums.autodesk.com/t5/net/accoreconsole-exe-in-2015-doesn-t-do-system-console-writeline/td-p/5539352