How can I get a control object from his name or varname ?

Started by krunch, October 02, 2010, 08:15:51 AM

Previous topic - Next topic

krunch

Hello there, and thanks for this great system !

As I have an array of controls, I need a reference to control objects from their name or varname, wich is a string argument..
How can I do that ? there's no 'GetControl' méthod..

owenwengerd

You can either specify controls by name rather than reference, or you can get the control reference by concatenating and evaluating the control's symbol name at runtime.

krunch

Ok but how can I do that ?

I miss a basic syntax, tentatively I made this...
Quote(defun GetControl (name / tmp u)
  (setq tmp (dcl_Form_GetControls Proj_Form))
  (car(vl-remove-if-not '(lambda(u) (= (dcl_Control_Getname u) name)) tmp))
)





Fred Tomke

Hi, just use

Code (autolisp) Select
(dcl_Control_SetText myproj_myform_mytextbox "That's all!")
Please note that the variable myproj_myform_mytextbox will only be set during the form is visible.

Or you do it that way:

Code (autolisp) Select
(dcl_Control_SetText "myproj" "myform" "mytextbox" "That's all!")

With the last sample you can do:

Code (autolisp) Select
(mapcar '(lambda (strCtrl strValue) (dcl_Control_SetText "myproj" "myform" strCtrl strValue))  '("mytextbox1" "mytextbox2") '("A" "B"))

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

krunch

Ok, I missed your 2nd (and 3rd) syntax ("mytextbox" is in a string handler).

Thanks a lot

Slavko Ivanovic

#5
hello krunch.

I have published one demo that i think part of it include things u are looking for.
I will give you preview and upload here only one file from that demo.

Code (autolisp) Select

;;;MID:SI-LBE-PUB-41/09 25. November 09
;;;OpenDCL_LanguageFile_Sample_f2/3
;;;dcl_xt_LibPart
;;;=====================================================================================================
;;; Slavko Solutions for AutoCAD
;;; ArchiTools, LandTools, ToolsPlus, LBE
;;; PROGRAM © by SLAVKO IVANOVIC
;;; slavko.ivanovich@gmail.com
;;; www.SlavkoSolutions.com[url=http://][/url][url=http://][/url]
;;;-----------------------------------------------------------------------------------------------------
;;; License Agreement (Author's request)
;;;
;;; * You are free to use, modify this programs and code segments under following conditions:
;;; 1. If you applying some changes on this code, save file with different name,
;;;   so original file content can always be traceable.
;;; 2. If you are re-publishing original file, or partial content, leave Copyright Header.
;;; 3. Don't expect from me any kind of support, but you can email me though.
;;;-----------------------------------------------------------------------------------------------------
;;; * Content:
;;;
;;; This file contains some of functions that are part of My DCL Extented Functions (dcl_xt) library.  
;;;
;;; They are referenced with my -OpenDCL Language File Demo- so I decided to provide them Open as well.
;;;
;;; But then, this file is also Sample by its self, so i will add description header.
;;;=====================================================================================================





;;;=====================================================================================================
;;;  ***
;;;    Description:
;;;
;;;  Loading Odcl Project, user actually "fill" Acad namespace with Enames - OpenDCL Control Pointers.
;;;  When Project is loaded, in runtime enviorment you can change almost everything in Project.
;;;
;;;  To make life easier to programer, OpenDCL automaticly (rhythmically) generate Symbol_Names
;;;  and bound with specific ENAME handle, somelike (setq Symbol Value), and after set that symbol
;;;  name to NIL (recycle) when acces to Control is "no longer needed".
;;;  
;;;  For example:
;;;   In case of Project (MyProject.odcl), with one form (Form1), with one button (Button1),
;;;  By defailt, OpenDCL do following:
;;;    (Dcl_Project_Load "MyProject.odcl")
;;; -> This loads project and return string, but also allocate "first set" of Symbol_Names,
;;;   to enable access to Forms. In this example symbol is one >> MyProject_Form1.
;;;   Note that exposed Forms through symbols remain exposed.
;;;    (Dcl_Form_Show MyProject_Form1)
;;; -> This show a Form1, but also allocate set of symbols for each Control in a Form,
;;;   in this example symbol is one >> MyProject_Form1_Button1.
;;;   Note that after (Dcl_Form_Close MyProject_Form1) this symbol is nil.
;;;
;;;  When Form is active, you can catch this handle, iex (setq SaveMeControl MyProject_Form1_Button1),
;;;  but what if you want to access ALL Controls and theirs Properties without Showing Forms?
;;;-----------------------------------------------------------------------------------------------------
;;;  
;;;  Functions in this Example File demonstrate powerful possibility to access and manipilate
;;;  with Forms, Controls, Properties and Events immediately after calling (Dcl_Project_Load)
;;;
;;;  OpenDCL Runtime Enviorment provide few but Essential functions (methods) to Start digging
;;;  OpenDCL Control Pointers that are represented as a ENAMEs.
;;;
;;;  For better understanding of this functions important is to note:
;;; * Both (Forms and Controls) are actually Controls.
;;; * Both (Properties and Events) are actually Properties.
;;;
;;;  - this kind of Opendcl handling is good for:
;;; - TRANSLATION, DIAGNOSTIC, MULTIPLE CONTORLS EDITING (check function dcl_Project_SaveAs),
;;;  VLX NAMESPACE HANDLING, ERROR TRAPPING, ... ... and expanding ideas ;)
;;;
;;; Slavko Ivanovic, designer/drafter/programmer
;;; Included (dcl_xt) Functions :
;;; ========================================================
;;; dcl_Project_GetControls
;;; dcl_Project_GetControlsSpecial
;;; dcl_Project_ExposeControls
;;; dcl_Control_PropertyAvlb-p
;;; dcl_Control_FilterCommon
;;; dcl_Control_FilterExclusive
;;; dcl_Control_Type
;;; dcl_Control_GetAvlbProperties
;;; Dcl_Control_GetForm
;;; dcl_Control_GetEvents
;;; dcl_Lng_PrepareFromat
;;; dcl_Lng_ReadFile
;;;
;;;=============================================



Demo with all files was published here:  http://www.opendcl.com/forum/index.php?topic=1031.0

and here is lisp from preview.


***  siCAD Solutions for AutoCAD  ***
ArchiTools l ToolsPlus l LandTools l LBE

daka90

Quote from: Fred Tomke on October 03, 2010, 02:01:14 AM
Hi, just use

Code (autolisp) Select
(dcl_Control_SetText myproj_myform_mytextbox "That's all!")
Please note that the variable myproj_myform_mytextbox will only be set during the form is visible.

Or you do it that way:

Code (autolisp) Select
(dcl_Control_SetText "myproj" "myform" "mytextbox" "That's all!")

With the last sample you can do:

Code (autolisp) Select
(mapcar '(lambda (strCtrl strValue) (dcl_Control_SetText "myproj" "myform" strCtrl strValue))  '("mytextbox1" "mytextbox2") '("A" "B"))

Fred

THANK YOU FRED
Those examples should really be added to the helpfile ! I was fighting for 2 hours until I found this post.
here is the part about control name from the doc:

Quote[..] In such cases, the control can be identified either by passing the control handle that is stored automatically in the AutoLISP symbol named in the control's VarName property, or by passing the project name, form name, and control name (or in the case of forms, only the project name and form name) as strings.

From that I never thought I should separate literally the parts of the control name string

Thank you very much again

owenwengerd

Quote from: daka90 on February 11, 2014, 01:58:07 AM
Those examples should really be added to the helpfile !

Thanks for the feedback. I am looking at the documentation now to see how this could be improved. The Concepts\Object Model page only shows an example using the symbol name, and I will change this now to add an additional example using separate strings. The reference section of the help file that you quote is intended to be very short and concise, so I think it's best to not duplicate the examples there, but I'm open to suggestions for improving the wording to make the meaning more clear.