OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: borsa on May 11, 2011, 02:33:00 AM

Title: listbox_addlist problem for a beginner
Post by: borsa on May 11, 2011, 02:33:00 AM
Hello,
I've programmed with DCL and now I'm trying to migrate to OpenDCL becauseit is more complete but I have some problems on the trials.
I try to fill a listbox with a list but does not write anything when display the dialog (only has a listbox)
I have read the forum Mesg but I'm lost. What am I doing wrong?

I tried addlist and setlist but no success

I'm sorry because English is not my native language

Thank you for teaching


Code (autolisp) Select

(defun C:ODCL0200 ( / )
 (getTowN)
 (command "_OPENDCL")
 (dcl_Project_Load "D:/design/lisp_cim/0300.odcl" T)
 (dcl_Form_Show 0300_ODCL02 )
 (princ)
)

(defun c:odcl_0200_OnInicialize (/)
;  (dcl_ListBox_Clear TowListN)
;  (dcl_Control_SetList 0300_ODCL02_ListBox1 aux01)
 (dcl_ListBox_AddList 0300_ODCL02_ListBox1 Aux01)

)

(defun GetTowN (/ aux01 )
 (setq k 12)
 (setq n 1)
 (setq aux01 (list nil))
 (Repeat k
   (setq aux01 (append aux01 (list (strcat "Item N." (Itoa n)))))
   (setq n (1+ n))
) )


Title: Re: listbox_addlist problem for a beginner
Post by: roy_043 on May 11, 2011, 04:10:06 AM
Hi borsa,

There are two problems with your code:
- wrong name for initialize function
- GetTowN did not function correctly.

Code (autolisp) Select

(defun C:ODCL0200 ( / )
 (command "_OPENDCL")
 (dcl_Project_Load "D:/design/lisp_cim/0300.odcl" T)
 (dcl_Form_Show 0300_ODCL02 )
 (princ)
)

(defun c:0300_ODCL02_OnInitialize (/)
 (dcl_ListBox_Clear 0300_ODCL02_ListBox1)
 (dcl_ListBox_AddList 0300_ODCL02_ListBox1 (GetTowN))
)

(defun GetTowN (/ aux01 n k)
 (setq k 12)
 (setq n 1)
 (repeat k
   (setq aux01 (append aux01 (list (strcat "Item N." (Itoa n)))))
   (setq n (1+ n))
 )
 aux01
)


Note: you must check the initialize event for your form.

Regards, Roy.
Title: Re: listbox_addlist problem for a beginner
Post by: borsa on May 11, 2011, 08:44:09 AM
Hi Roy

Just one question, have you checked your lisp code attached?. I've loaded your code in cad and the listbox is still empty. Perhaps I have another mistake but I want to be sure.

In my lisp code "Aux01" is already alist so I can add it to the listbox with the function addlist and not through the function "GetTowN" as in your code. isn“t it?

Thanks for your help.
Title: Re: listbox_addlist problem for a beginner
Post by: BazzaCAD on May 11, 2011, 11:32:11 AM
Roy's code is correct.
If it's not working for you, you probably don't have the "OnInitialize" even checked, or you changed the name of one of your controls.
If you attach your .lsp & .odcl we can probably track down the issue.
Title: Re: listbox_addlist problem for a beginner
Post by: roy_043 on May 11, 2011, 11:43:58 AM
@ BazzaCAD: Thank you for that confirmation. And also thank you for your great OpenDCL Beginners Tutorial!

@ borsa:

Your function (GetTowN) doesn't work the way you think. Because aux01 is a local variable in (GetTowN) using

(dcl_ListBox_AddList 0300_ODCL02_ListBox1 Aux01)

in c:odcl_0200_OnInicialize will not work properly.
And after this code:

(setq aux01 (list nil))

aux01 is not an empty list but a list with one element: (nil)

Regards, Roy.
Title: Re: listbox_addlist problem for a beginner
Post by: Fred Tomke on May 11, 2011, 10:07:37 PM
Hi,

in addition to what was written I want to add dcl_control_setlist, because the listbox control still contains its items when re-showing the form:

Code (autolisp) Select

(defun c:0300_ODCL02_OnInitialize (/) 
  (dcl_ListBox_SetList 0300_ODCL02_ListBox1 (GetTowN)) 
); c:0300_ODCL02_OnInitialize


Regards, Fred
Title: Re: listbox_addlist problem for a beginner
Post by: borsa on May 12, 2011, 12:28:14 AM
I'm sorry. I'm checking the dialog and note the Initialize event is not marke, may be the result of all the changes I do to try and also my mistakes.

Now the code runs properly.

Thanks to everyone
Title: Re: listbox_addlist problem for a beginner
Post by: roy_043 on May 12, 2011, 05:02:31 AM
@ Fred: No doubt you mean: dcl_Control_SetList.

Title: Re: listbox_addlist problem for a beginner
Post by: Fred Tomke on May 12, 2011, 06:06:24 AM
Yes, you're right.  ;)

Fred