OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: MiD-AwE on December 18, 2013, 12:31:00 PM

Title: switch between drawings?
Post by: MiD-AwE on December 18, 2013, 12:31:00 PM
Dialog content or/and the variables are not updated when the user switches between drawings.
Using the event OnDocActivated I have been unable to make the dialog content reliable. It holds on to the previous drawings data.

What must I do to force the dialog to display only information for the active document?  :-\

Thank you for any help.
Title: Re: switch between drawings?
Post by: owenwengerd on December 18, 2013, 01:33:51 PM
It's hard to guess what's wrong with your code without seeing it.
Title: Re: switch between drawings?
Post by: MiD-AwE on December 18, 2013, 02:35:55 PM
I suppose a more specific question is, how do I clear all controls?

I there some ambiguous method for clear all?

:-[
Title: Re: switch between drawings?
Post by: owenwengerd on December 18, 2013, 02:44:43 PM
No, you have to manage each control individually.
Title: Re: switch between drawings?
Post by: MiD-AwE on December 18, 2013, 02:54:33 PM
Ok,
That'll nearly double the code. At least a thousand lines. (I better get typing)

Thank you.
Title: Re: switch between drawings?
Post by: owenwengerd on December 18, 2013, 02:58:03 PM
In most cases you can use common code to initialize or re-initialize controls in the OnInitialize and OnDocActivated event handlers.
Title: Re: switch between drawings?
Post by: MiD-AwE on January 31, 2014, 12:45:21 PM
I'm finally getting back to this.  ???

Is there an example anywhere for your
Quoteuse common code to initialize or re-initialize controls in the OnInitialize and OnDocActivated event handlers
suggestion. Is it as easy as:
Code (autolisp) Select

(foreach cntrl 'list
  (dcl_Control_SetText cntrl "")
)
(foreach cntrl 'list
  (DCL_CONTROL_SETPICTURE cntrl "")
)
etc...


Or, what can you suggest?

Thank you in advance for any suggestions.
Title: Re: switch between drawings?
Post by: owenwengerd on January 31, 2014, 07:23:21 PM
By "common" I meant "shared". Like this:

Code (autolisp) Select

(defun DoInitialization ()
...
)

(defun c:OnInitialize()
  (DoInitialization)
)

(defun c:OnDocActivated()
  (DoInitialization)
)
Title: Re: switch between drawings?
Post by: MiD-AwE on February 03, 2014, 10:20:46 AM
 :) Thank you. I've done a little more digging around in the help and examples and have assembled this generic code so far:

Code (autolisp) Select
(DEFUN ReSetOdclControl (odclfile / chkbx optlst project props)
  (FOREACH form (DCL_PROJECT_GETFORMS odclfile)
    (FOREACH cntrl (DCL_FORM_GETCONTROLS form)
      (PROGN
(SETQ props (DCL_CONTROL_GETPROPERTIES cntrl))
(COND
  ((MEMBER "Text" props)
   (PROGN
     (SETQ teXt (DCL_CONTROL_GETPROPERTY cntrl "Text"))
     (IF (/= teXt "")
       (DCL_CONTROL_SETTEXT cntrl "")
     )
   )
  )
  ((MEMBER "Value" props)
   (PROGN
     (SETQ chkbx (DCL_CONTROL_GETPROPERTY cntrl "Value"))
     (IF (/= chkbx "Unchecked")
       (DCL_CONTROL_SETVALUE cntrl "Unchecked")
     )
   )
  )
  ((MEMBER "Current Selection" props)
   (PROGN
     (SETQ optlst (DCL_CONTROL_GETPROPERTY cntrl "Current Selection"))
     (IF (/= optlst 0)
       (DCL_CONTROL_SETVALUE cntrl 0)
     )
   )
  )
)
      )
    )
  )
)


Along with your clarification it seems to be working. Maybe the above could be helpful to others too.

- It was quite frustrating getting to this point. I know I used clear English in my question but I felt like the simple thing I was asking was lost in translation. Ultimately I used an example in the help file for the obscure thing of changing the size of font of a project. I would assume the thing I'm trying to do would be MUCH more common and useful. Go figure  :o
Title: Re: switch between drawings?
Post by: owenwengerd on February 03, 2014, 03:26:56 PM
I'm glad you got it figured out. The sledge hammer approach is good if that's what you needed, but I think most use cases call for being selective about what and how to change control properties (which as you said is more work for the programmer -- but them's the breaks).
Title: Re: switch between drawings?
Post by: MiD-AwE on February 04, 2014, 07:02:00 AM
I get it. I just happen to be working with OpenDCL for production, where we often work with several drawings simultaneously and no two drawings have anything to do with each other.

The only alternative was to quit AutoCAD completely and reopen. That is a huge time killer. This method of making certain the data displayed by OpenDCL is only reflective of the active document is vital. It would be a deal breaker for us if the data from one project ended up in another; not to mention someone would loose their job over such an error.   :'(

Again thank you Owen for all of your help.  :)
Title: Re: switch between drawings?
Post by: owenwengerd on February 04, 2014, 08:06:49 AM
It just occurred to me that you may be able to achieve the same end (and as a bonus, save your job in the process) by simply reloading the project by passing T as the 'ForceReload' argument to (dcl-Project-Load (http://www.opendcl.com/HelpFiles/index.php?page=Reference/Method/Project/Load.htm)).
Title: Re: switch between drawings?
Post by: MiD-AwE on February 06, 2014, 08:23:04 AM
Thanks Owen,  :)

The 'ForceReload' was a good idea. I jumped right on it to test if it would really cause the project to reflect the values of the Active Document. Unfortunately an error popped up complaining about nil values for every control, and finally AutoCAD crashed. I tried it 3 times with drawings at various stages. Only a fully completed project could have all controls manipulated; and then not all projects utilize every control.

I'm not sure of the problem but it sure was worth a try. For now I'll stick with the "ReSetOdclControl" function, it has it's quirks but it does not crash AutoCAD. The nil value thing may be the way that I populate the controls by loading existing values from Global variable assigned in another lsp file. A simple thing actually. I assign xdata as the user works with the drawing, the refering lsp file reads the xdata into a long list of globals that are also reference by fields in tables and title-block. The OpenDCL "CNTRL-PNL" project is used to manipulate the xdata, the refering lsp file is reloaded and the globals are refreshed. It quite fast, but not fail proof without  the "ReSetOdclControl" function.