Author Topic: switch between drawings?  (Read 883 times)

MiD-AwE

  • Member
  • *
  • Posts: 28
switch between drawings?
« on: December 18, 2013, 01: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.
« Last Edit: December 18, 2013, 01:32:43 PM by MiD-AwE »

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 2594
    • Outside The Box
Re: switch between drawings?
« Reply #1 on: December 18, 2013, 02:33:51 PM »
It's hard to guess what's wrong with your code without seeing it.

MiD-AwE

  • Member
  • *
  • Posts: 28
Re: switch between drawings?
« Reply #2 on: December 18, 2013, 03:35:55 PM »
I suppose a more specific question is, how do I clear all controls?

I there some ambiguous method for clear all?

 :-[

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 2594
    • Outside The Box
Re: switch between drawings?
« Reply #3 on: December 18, 2013, 03:44:43 PM »
No, you have to manage each control individually.

MiD-AwE

  • Member
  • *
  • Posts: 28
Re: switch between drawings?
« Reply #4 on: December 18, 2013, 03:54:33 PM »
Ok,
That'll nearly double the code. At least a thousand lines. (I better get typing)

Thank you.

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 2594
    • Outside The Box
Re: switch between drawings?
« Reply #5 on: December 18, 2013, 03:58:03 PM »
In most cases you can use common code to initialize or re-initialize controls in the OnInitialize and OnDocActivated event handlers.

MiD-AwE

  • Member
  • *
  • Posts: 28
Re: switch between drawings?
« Reply #6 on: January 31, 2014, 01:45:21 PM »
I'm finally getting back to this.  ???

Is there an example anywhere for your
Quote
use common code to initialize or re-initialize controls in the OnInitialize and OnDocActivated event handlers
suggestion. Is it as easy as:
  1. (foreach cntrl 'list
  2.   (dcl_Control_SetText cntrl "")
  3. )
  4. (foreach cntrl 'list
  5.   (DCL_CONTROL_SETPICTURE cntrl "")
  6. )
  7. etc...
  8.  

Or, what can you suggest?

Thank you in advance for any suggestions.

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 2594
    • Outside The Box
Re: switch between drawings?
« Reply #7 on: January 31, 2014, 08:23:21 PM »
By "common" I meant "shared". Like this:

  1. (defun DoInitialization ()
  2. ...
  3. )
  4.  
  5. (defun c:OnInitialize()
  6.   (DoInitialization)
  7. )
  8.  
  9. (defun c:OnDocActivated()
  10.   (DoInitialization)
  11. )
  12.  

MiD-AwE

  • Member
  • *
  • Posts: 28
Re: switch between drawings?
« Reply #8 on: February 03, 2014, 11: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:

  1. (DEFUN ReSetOdclControl (odclfile / chkbx optlst project props)
  2.   (FOREACH form (DCL_PROJECT_GETFORMS odclfile)
  3.     (FOREACH cntrl (DCL_FORM_GETCONTROLS form)
  4.       (PROGN
  5.         (SETQ props (DCL_CONTROL_GETPROPERTIES cntrl))
  6.         (COND
  7.           ((MEMBER "Text" props)
  8.            (PROGN
  9.              (SETQ teXt (DCL_CONTROL_GETPROPERTY cntrl "Text"))
  10.              (IF (/= teXt "")
  11.                (DCL_CONTROL_SETTEXT cntrl "")
  12.              )
  13.            )
  14.           )
  15.           ((MEMBER "Value" props)
  16.            (PROGN
  17.              (SETQ chkbx (DCL_CONTROL_GETPROPERTY cntrl "Value"))
  18.              (IF (/= chkbx "Unchecked")
  19.                (DCL_CONTROL_SETVALUE cntrl "Unchecked")
  20.              )
  21.            )
  22.           )
  23.           ((MEMBER "Current Selection" props)
  24.            (PROGN
  25.              (SETQ optlst (DCL_CONTROL_GETPROPERTY cntrl "Current Selection"))
  26.              (IF (/= optlst 0)
  27.                (DCL_CONTROL_SETVALUE cntrl 0)
  28.              )
  29.            )
  30.           )
  31.         )
  32.       )
  33.     )
  34.   )
  35. )

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

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 2594
    • Outside The Box
Re: switch between drawings?
« Reply #9 on: February 03, 2014, 04: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).

MiD-AwE

  • Member
  • *
  • Posts: 28
Re: switch between drawings?
« Reply #10 on: February 04, 2014, 08: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.  :)

owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 2594
    • Outside The Box
Re: switch between drawings?
« Reply #11 on: February 04, 2014, 09: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).

MiD-AwE

  • Member
  • *
  • Posts: 28
Re: switch between drawings?
« Reply #12 on: February 06, 2014, 09: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.