<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to let the user stop a for-loop (DGModelessHandler?) in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10976#M7116</link>
    <description>Hi Akos &lt;E&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/E&gt; &lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt;Akos wrote:&lt;BR /&gt; &lt;BR /&gt;
Try to use a palette instead. Modeless dialogs are special to ArchiCAD. 
&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
Ok, now my test class creates a palette the old way (DGCreateBlankPalette) and looks like that: &lt;BR /&gt;
 
&lt;PRE&gt; 
class CTest3Window 
   { 
   public: 
      CTest3Window(); //creates a pallette with "DGCreateBlankPalette" 
      ~CTest3Window(); 
      void live(); //invokes "DGGetMousePosition" 
      static short int DGCALLBACK mainEventHandler( 
         short  message, 
         short  dialId, 
         short  itemId, 
         long   userData, 
         long   msgData 
         ); 
   private: 
      short mDialogId; 
   }; 
&lt;/PRE&gt; &lt;BR /&gt;
 
&lt;PRE&gt;   CTest3Window::CTest3Window() 
   { 
      mDialogId = DGCreateBlankPalette   ( 
         200,                   //   hSize, 
         200,                   //   vSize, 
         DG_DLG_NOGROW,         //   growFlag, 
         DG_DLG_CLOSE,          //   closeFlag, 
         0,                     //   captionFlag, 
         DG_DLG_NORMALFRAME,    //   frameFlag, 
         this-&amp;gt;mainEventHandler,//   dCallBack, 
         0                      //userData 
         ); 
      DGShowModelessDialog(mDialogId); 
      DGBeginProcessEvents(mDialogId); 
      DGSetModelessDialogStatus(mDialogId, DG_DS_ENABLED); 
   } 
    
   CTest3Window::~CTest3Window() 
   { 
      DGEndProcessEvents(mDialogId);       
      DGDestroyModelessDialog(mDialogId); 
   } 
    
   void CTest3Window::live() 
   { 
      DGMousePosData mpd; 
      short mouseStatus = DGGetMousePosition(mDialogId, &amp;amp;mpd); 
   } 
   
&lt;/PRE&gt; &lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt; &lt;BR /&gt;
To make the loop breakable try calling something like DGGetMousePosition inside the loop; that lets other event handlers run. 
&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
In CTest3Window::live() I invoke "DGGetMousePosition" and the for loop looks like that: 
&lt;PRE&gt;for (int i = 0; (i &amp;lt; 10) &amp;amp;&amp;amp; !abort; i++) 
{ 
  window.live(); //invokes "DGGetMousePosition" 
  Sleep(500); 
} 
&lt;/PRE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
The eventhandler assigned to the palette is still not invoked during the for-loop &lt;E&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/E&gt; &lt;BR /&gt;
I tried the the same going the object-orientated way using DG::Palette, but the attached Event-Observer is not notified neither. &lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt;The example you are referring to is the test application for the Dialog Manager (a.k.a DG) module. 
&lt;/BLOCKQUOTE&gt;
 &lt;BR /&gt;
Yes, this does not seem to be an addon.  &lt;BR /&gt;
Do you have an idea how to use DGModelessHandler in a normal addon? &lt;BR /&gt;
 &lt;BR /&gt;
Greeting, &lt;BR /&gt;
 John</description>
    <pubDate>Tue, 20 Jun 2006 19:33:13 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-06-20T19:33:13Z</dc:date>
    <item>
      <title>how to let the user stop a for-loop (DGModelessHandler?)</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10974#M7114</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hi! &lt;BR /&gt;&lt;BR /&gt;I am searching for a way to enable the user to stop a for-loop started by the addon. &lt;BR /&gt;&lt;BR /&gt;Example:
&lt;PRE&gt; 
{ 
   bool abort = false; 
   CTestWindow window(abort); //modeless window with access to "abort" 
   for (int i = 0; (i &amp;lt; 10) &amp;amp;&amp;amp; !abort; i++) 
   { 
      Sleep(500); 
      PRINT(GET(i)); 
   } 
} 
&lt;/PRE&gt;
&lt;BR /&gt;&lt;BR /&gt;The user should be able to stop the for-loop via the created modeless-window. &lt;BR /&gt;But the window is not responding during the for-loop. &lt;BR /&gt;&lt;BR /&gt;I tried to use the objectorientated way (inheriting or using DG::ModelessDialog) and the old way &lt;BR /&gt;(using DGCreateBlankModelessDialog, DGBeginProcessEvents, ...). &lt;BR /&gt;&lt;BR /&gt;I found the docu of "DGModelessHandler" which i do not understand. &lt;BR /&gt;This method seems to belong to the 'old way'. &lt;BR /&gt;In the docu there is a passage which describes the scenario i am facing: &lt;BR /&gt;&lt;BR /&gt;&amp;gt; The usage of the dialog status flag can be explain by the following &lt;BR /&gt;&amp;gt; example. Suppose that an application begins a long process such as a &lt;BR /&gt;&amp;gt; time-consuming calculation. In this case, it is advisable to show a &lt;BR /&gt;&amp;gt; process indicator dialog with a Stop button until the calculation is &lt;BR /&gt;&amp;gt; finished. When handling system-specific messages during this period, &lt;BR /&gt;&amp;gt; you should call DGModelessHandler with onlyUpdate of value true. This &lt;BR /&gt;&amp;gt; ensures that modeless dialogs of DG_DS_NORMAL state do not handle any &lt;BR /&gt;&amp;gt; messages except the update messages (this way they do not respond to &lt;BR /&gt;&amp;gt; any user actions). The status of the process indicator dialog should &lt;BR /&gt;&amp;gt; be set to DG_DS_ENABLED in order to enable the user to press the Stop &lt;BR /&gt;&amp;gt; button and cancel the process. &lt;BR /&gt;&lt;BR /&gt;But i have no idea how to use "DGModelessHandler" &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; &lt;BR /&gt;&lt;BR /&gt;It seems that this method does not belong into the code of an Addon: &lt;BR /&gt;&amp;gt; Call this function just after receiving a system-specific message &lt;BR /&gt;&amp;gt; in the application's message loop. &lt;BR /&gt;&lt;BR /&gt;This method is used in the following file of the api-examples: &lt;BR /&gt;"...\API Development Kit 5\Examples\DGTest\Sources.win\DGTestWin.cpp" &lt;BR /&gt;&lt;BR /&gt;This does not look like an Addon but like an application. &lt;BR /&gt;&lt;BR /&gt;Hmm, very strange. &lt;BR /&gt;&lt;BR /&gt;I hope someone has a hint how to start a modeless dialog which keeps responding. &lt;BR /&gt;I would prefer the object orientated way using the class DG::ModelessDialog. &lt;BR /&gt;&lt;BR /&gt;Perhaps there is a ArchiCad-way to use threads? &lt;BR /&gt;&lt;BR /&gt;The process-window which could be created with "ACAPI_Interface(APIIo_InitProcessWindowID,.." does not seem to work properly. &lt;BR /&gt;&lt;BR /&gt;regards, &lt;BR /&gt;John&lt;/DIV&gt;</description>
      <pubDate>Mon, 07 Aug 2023 09:13:15 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10974#M7114</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-07T09:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to let the user stop a for-loop (DGModelessHandler?)</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10975#M7115</link>
      <description>Hello John,&lt;BR /&gt;
&lt;BR /&gt;
Try to use a palette instead. Modeless dialogs are special to ArchiCAD.&lt;BR /&gt;
&lt;BR /&gt;
To make the loop breakable try calling something like DGGetMousePosition inside the loop; that lets other event handlers run.&lt;BR /&gt;
&lt;BR /&gt;
The example you are referring to is the test application for the Dialog Manager (a.k.a DG) module.&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
&lt;BR /&gt;
Akos</description>
      <pubDate>Tue, 20 Jun 2006 16:32:30 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10975#M7115</guid>
      <dc:creator>Akos Somorjai</dc:creator>
      <dc:date>2006-06-20T16:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to let the user stop a for-loop (DGModelessHandler?)</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10976#M7116</link>
      <description>Hi Akos &lt;E&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/E&gt; &lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt;Akos wrote:&lt;BR /&gt; &lt;BR /&gt;
Try to use a palette instead. Modeless dialogs are special to ArchiCAD. 
&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
Ok, now my test class creates a palette the old way (DGCreateBlankPalette) and looks like that: &lt;BR /&gt;
 
&lt;PRE&gt; 
class CTest3Window 
   { 
   public: 
      CTest3Window(); //creates a pallette with "DGCreateBlankPalette" 
      ~CTest3Window(); 
      void live(); //invokes "DGGetMousePosition" 
      static short int DGCALLBACK mainEventHandler( 
         short  message, 
         short  dialId, 
         short  itemId, 
         long   userData, 
         long   msgData 
         ); 
   private: 
      short mDialogId; 
   }; 
&lt;/PRE&gt; &lt;BR /&gt;
 
&lt;PRE&gt;   CTest3Window::CTest3Window() 
   { 
      mDialogId = DGCreateBlankPalette   ( 
         200,                   //   hSize, 
         200,                   //   vSize, 
         DG_DLG_NOGROW,         //   growFlag, 
         DG_DLG_CLOSE,          //   closeFlag, 
         0,                     //   captionFlag, 
         DG_DLG_NORMALFRAME,    //   frameFlag, 
         this-&amp;gt;mainEventHandler,//   dCallBack, 
         0                      //userData 
         ); 
      DGShowModelessDialog(mDialogId); 
      DGBeginProcessEvents(mDialogId); 
      DGSetModelessDialogStatus(mDialogId, DG_DS_ENABLED); 
   } 
    
   CTest3Window::~CTest3Window() 
   { 
      DGEndProcessEvents(mDialogId);       
      DGDestroyModelessDialog(mDialogId); 
   } 
    
   void CTest3Window::live() 
   { 
      DGMousePosData mpd; 
      short mouseStatus = DGGetMousePosition(mDialogId, &amp;amp;mpd); 
   } 
   
&lt;/PRE&gt; &lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt; &lt;BR /&gt;
To make the loop breakable try calling something like DGGetMousePosition inside the loop; that lets other event handlers run. 
&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
In CTest3Window::live() I invoke "DGGetMousePosition" and the for loop looks like that: 
&lt;PRE&gt;for (int i = 0; (i &amp;lt; 10) &amp;amp;&amp;amp; !abort; i++) 
{ 
  window.live(); //invokes "DGGetMousePosition" 
  Sleep(500); 
} 
&lt;/PRE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
The eventhandler assigned to the palette is still not invoked during the for-loop &lt;E&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/E&gt; &lt;BR /&gt;
I tried the the same going the object-orientated way using DG::Palette, but the attached Event-Observer is not notified neither. &lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt;The example you are referring to is the test application for the Dialog Manager (a.k.a DG) module. 
&lt;/BLOCKQUOTE&gt;
 &lt;BR /&gt;
Yes, this does not seem to be an addon.  &lt;BR /&gt;
Do you have an idea how to use DGModelessHandler in a normal addon? &lt;BR /&gt;
 &lt;BR /&gt;
Greeting, &lt;BR /&gt;
 John</description>
      <pubDate>Tue, 20 Jun 2006 19:33:13 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10976#M7116</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-20T19:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to let the user stop a for-loop (DGModelessHandler?)</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10977#M7117</link>
      <description>Hi &lt;E&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/E&gt; &lt;BR /&gt;

&lt;BLOCKQUOTE&gt;John wrote:&lt;BR /&gt; &lt;BR /&gt;
 &lt;BR /&gt;
The process-window which could be created with "ACAPI_Interface(APIIo_InitProcessWindowID,.." does not seem to work properly.  &lt;BR /&gt;
 
&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
Now, I am using "APIIo_InitProcessWindowID" after all... &lt;BR /&gt;
It takes a long time before the process-window appears. &lt;BR /&gt;
So if the process does not takes long enough you don't see this window. Thats why i thought it would not work. 
&lt;PRE&gt; 
bool abort = false; 
short nPhase = 1; 
long maxval = 100; 
 
ACAPI_Interface (APIIo_InitProcessWindowID, "incremental search", &amp;amp;nPhase); 
ACAPI_Interface (APIIo_SetNextProcessPhaseID, "working...", &amp;amp;maxval); 
 
for (int i = 0; (i &amp;lt; maxval) &amp;amp;&amp;amp; !abort; i++) 
{ 
   Sleep(500); 
   PRINT(GET(i)); 
   ACAPI_Interface(APIIo_SetProcessValueID, &amp;amp;i, NULL); 
   if (ACAPI_Interface(APIIo_IsProcessCanceledID, NULL, NULL)) 
   { 
      abort = true; 
   } 
} 
ACAPI_Interface (APIIo_CloseProcessWindowID, NULL, NULL); 
&lt;/PRE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
[Threads]&lt;BR /&gt;
An other way i tried was the following: &lt;BR /&gt;
I coded a Status-Window which is able to invoke the method whose status is to be monitored in a new thread. &lt;BR /&gt;
But there were several problems: &lt;BR /&gt;
1. The thread I used is not OS-independent and I think you should avoid OS-specific code in AC-Addons. &lt;BR /&gt;
2. ArchiCAD often crashes, if the method running in the thread is selecting elements or changing the AC-database. &lt;BR /&gt;
 &lt;BR /&gt;
But perhaps someone still has a hint how to start a window which keeps reacting while an other method is working. &lt;BR /&gt;
 &lt;BR /&gt;
cu, &lt;BR /&gt;
 John</description>
      <pubDate>Thu, 22 Jun 2006 15:35:30 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10977#M7117</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-22T15:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to let the user stop a for-loop (DGModelessHandler?)</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10978#M7118</link>
      <description>&lt;BLOCKQUOTE&gt;John wrote:&lt;BR /&gt;
Now, I am using "APIIo_InitProcessWindowID" after all... &lt;BR /&gt;
It takes a long time before the process-window appears. &lt;BR /&gt;
So if the process does not takes long enough you don't see this window. Thats why i thought it would not work. 
&lt;/BLOCKQUOTE&gt;
John,&lt;BR /&gt;
&lt;BR /&gt;
The API process window has a built-in delay before appearing, which unfortunately cannot be modified. The delay is far too long in my opinion - a user could easily think the software has crashed.&lt;BR /&gt;

&lt;BLOCKQUOTE&gt;John wrote:&lt;BR /&gt; &lt;BR /&gt;
[Threads]&lt;BR /&gt;
An other way i tried was the following: &lt;BR /&gt;
I coded a Status-Window which is able to invoke the method whose status is to be monitored in a new thread. &lt;BR /&gt;
But there were several problems: &lt;BR /&gt;
1. The thread I used is not OS-independent and I think you should avoid OS-specific code in AC-Addons. &lt;BR /&gt;
2. ArchiCAD often crashes, if the method running in the thread is selecting elements or changing the AC-database. 
&lt;/BLOCKQUOTE&gt;
The crux of the problem is that much of ArchiCAD has not been designed to support threading. That's why it crashes when a separate thread attempts to access the database.</description>
      <pubDate>Sat, 24 Jun 2006 08:14:10 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/how-to-let-the-user-stop-a-for-loop-DGModelessHandler/m-p/10978#M7118</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2006-06-24T08:14:10Z</dc:date>
    </item>
  </channel>
</rss>

