OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: svranic on December 21, 2010, 08:43:55 PM

Title: OpenDCL beginner - referencing to form item
Post by: svranic on December 21, 2010, 08:43:55 PM
Hello everyone. I'm beginner in OpenDCL and for a few days I'm having trouble with creating a smiple form. I downloaded OpenDCL tutorial and loaded level 1 example into AutoCAD 2007 and it worked. After that I tried to add new button which will open a new dcl message box with different message. When I loaded that file in AutoCAD it didn't open a new dcl messagebox but the same as I clicked on button1. I have a feeling like I'm not referencing to right name of object in form. I noticed that in all examples varNames of form items are empty. Why is that. Anyway I attached files I have been working on so I hope someone will have solution for me.
Title: Re: OpenDCL beginner - referencing to form item
Post by: Kerry on December 22, 2010, 03:04:41 AM
In the ODCL file,
The On_Clicked Event Function for BOTH buttons is the same
ie: c:HelloWorld_Form1_TextButton1_OnClicked

From the Menu select Tools->ResetEventNames

or in Button2 Event Tab, deselect and re-select the Clicked Event.

The first Option may be best.

This probably happened because you copied the button2 from button1 .... and the event function name came with the copy :)

added:
I haven't looked at your lisp code, so if the problem remains after the changes I mention please post back.

Title: Re: OpenDCL beginner - referencing to form item
Post by: svranic on December 22, 2010, 04:14:53 AM
Ok. I got it working. Thank you very much. I didn't know that it is necessary to click on the checkbox in Events tab for every event that we want to handle. If I'm correct by checking certain event we are enabling usage of that event in autolisp file. Right?
Is it VarName mandatory or optional attribute? In what cases can we get an element through his VarName or we can get an element through his Name?
Title: Re: OpenDCL beginner - referencing to form item
Post by: Fred Tomke on December 22, 2010, 05:10:52 AM
Hi, svranic,

at first, welcome on board, svranic!

It is not necessary to uncheck and to re-check the toggle for a certain event in the events tab. Unchecking and rechecking is only needed if you copy a control. All properties of this control are copied, too. And since events are handled like properties, the event names which were set by checking the event toggle, they are copied, too. If the control shall do something different to the other control, you can either rename the functionname of the event by hand (I do that very seldom), or you uncheck and re-check the toggle or - like Kerry wrote - you use the ResetEventNames command from the menue. But the ResetEventNames command does it for all the controls of the active form (dialog or active tab!).

You can avoid that if you do not copy controls but draw them anew each time. Then you have only to check the needed event(s). And that is necessary because some controls support many events and they can influence the control's behavior and other events. So it is recommended to activate only the events you really need.

There are sereval ways to get the function names in your code:

The VarName is internally set automatically. We recommend you not to add a custom value to avoid problems addressing the controls. In principal you have both possibilities:

You can address controls via name and via VarName. We recommend you to use the VarName property. So you can test if the VarName myproject_myform_mycontrol is nil in lisp - then the form is either not loaded yet or you just have deleted the control or the control was newly added and you haven't reloaded the project yet. If you try to address a control only by name, then you have no control. It is also said that using the VarName property is faster for addressing controls because the variable already contains the control object. When using the name the control must be found at first.

Sample using adressing by name:
Code (autolisp) Select
(foreach strControl '("pb_Cancel" "pb_Accept" "pb_Help")
 (dcl_control_setvisible "MyProj" "MyForm" strControl nil)
); foreach


Sample using adressing by VarName:
Code (autolisp) Select
(foreach oControl (list MyProj_MyForm_pb_Cancel MyProj_MyForm_pb_Accept MyProj_MyForm_pb_Help)
 (dcl_control_setvisible oControl nil)
); foreach


But also can combine the use of names with the speed of VarName:
Code (autolisp) Select

(defun control (strControl) (eval (read (strcat "MyProj_MyForm_" strControl))))
(defun invisible (oControl) (dcl_control_setvisible oControl nil))
(mapcar 'invisible '("pb_Cancel" "pb_Accept" "pb_Help"))


Hope that helps.
Fred
Title: Re: OpenDCL beginner - referencing to form item
Post by: svranic on December 22, 2010, 08:08:02 AM
Thank you Fred for this extensive answer. I will continue to learn OpenDCL because I'm thrilled with it.