modeless problem (with ssget?)

Started by funkitect, May 28, 2009, 11:34:52 AM

Previous topic - Next topic

funkitect

I am having problem with a modeless dialog box.  The dialog collects some data about a block (blockname, tag, attribute string).  After the data is collected the user can can press a button and the selected string will be pasted into the selected block(s) with matching blockname & tag.

If I run the program via the dialog the target blocks are never modified.  However, even if I leave the dialog box open and run the line manually that runs the subroutine the blocks are modified.  It seems the SSGET command may be causing the problem...I've fiddled with asynchronous vs. synchronous and with dcl_SetCmdBarFocus but I feel like I'm groping in the dark.  Does anyone know what is really going on?



This is the OnClicked event for the button (It just draws the data strings from the dialog and calls the subroutine:)

   (defun c:MatchAttributes_OnClicked (/ tBnameStr tTnameStr sData)
      (if (= "<not selected>" (dcl_Control_GetCaption Stname))
         (dcl_messagebox "You must specify a source block and tag")
         (progn
            (setq tBnameStr (dcl_Control_GetCaption Tbname))
            (setq tTnameStr (dcl_Control_GetCaption Ttname))
            (setq sData     (dcl_Control_GetCaption TagString))
            ;(dcl_Form_close MatchAttributes)
            (dcl_SetCmdBarFocus)  ;;Just trying this for kicks...saw some article and thought it might work...
            (maUpdateBlocks tBnameStr tTnameStr sData)
         )
      )
      (princ)
   )


This is the subroutine...

(defun maUpdateBlocks (sBlockName sTagName sNewValue / ss1 index ename e1)
   ;(setq tBnameStr "EW-PowerWall" tTnameStr "#LINE1" sData "X")
   ;(maUpdateBlocks "EW-PowerWall" "#LINE1" "X")
   ;(ccalert (list tBnameStr tTnameStr sdata))
   (princ "\nSelect target block(s):  ")
   (setq ss1 (ssget (list '(0 . "INSERT")(cons 2 sBlockName))))
   (setq index 0)
   (repeat (sslength ss1)
      (setq ename (ssname ss1 index))
      (setq ename (entnext ename))
      (WHILE (/= sTagName (cdr (assoc 2 (entget ename))))
         (setq ename (entnext ename))
      )
      (setq e1 (entget ename))
      (setq e1 (subst
            (cons 1 sNewValue)       ;new value
            (assoc 1 (entget ename)) ;old value
            e1                  ;elist
      ))
      (entmod e1)
      (entupd ename)
      (setq index (+ index 1))
   )
   (setq ss1 nil)
   (princ "\nDone...")
   (princ "\nCommand:")
)

Note: I had to add that last line (princ "\nCommand:") because the "problem" causes the resulting command line to be blank as though AutoCAD is waiting...but it isn't...I think.

Any help would be appreciated


James LeVieux

owenwengerd

Try changing your OnClicked event handler to call (dcl_SendString "UPDATEBLOCKS\n"), then defin (C:UPDATEBLOCKS) to gather the needed values from the dialog (but check first to ensure it's still open) and update the blocks.
Owen Wengerd (Outside The Box) / ManuSoft

funkitect

That did the trick Owen.  Thanks a million!

At the risk of making my head hurt...why does that work?

Sincerely,

James LeVieux

owenwengerd

By using (dcl_SendString), you allow Windows to complete its internal event handling and settle back into a quiescent state before the main code executes. I don't know what exactly your code is doing that causes the hiccup when it is executed directly from within the event handler, but the symptoms are indicative of executing code that causes state changes while another state change is still in progress.
Owen Wengerd (Outside The Box) / ManuSoft


owenwengerd

There will be a quiz next week...
Owen Wengerd (Outside The Box) / ManuSoft