Jump to content

Recommended Posts

Posted

Hello to All,

I am tiro in dcl coding. So, can any one help me how to put a variable in label?

 

: dialog
{
label = "Hello" ;
  : row
  {
   : list_box
   {
   label = "[color=red]Here I want to put a today's date[/color]" ;
   key = "listTips" ;
   width = 60;
   height = 15;
   fixed_width = true;
   fixed_height = true;
   multiple_select = false;
   }

}

 

Thanks

Posted

Hi,

 

You can make this by creating a temp.dcl file at runtime through the lisp and access it.

To asign the variable value to the label property write the following

 

(write-line "label=\" <Variable Name> \";")

 

Cheers..........

Posted

Nope, not possible. Instead of a label to the list-box, you could add a text tile - which value you can set using set_tile.

 

If you want the functionality as per your example through lisp, then google OpenDCL.

Posted

Hi ireneb,

thank you for replay, but all in the quota, label = "var" , Dcl (autolisp) understand a string not a variable.

I can not understand how to insert list-box in label = "list-box" .

Posted

OK, assuming you know how to get the date into a string (e.g. see AfraLisp) then you need a separate text portion in the DCL and no label for the list box:

Test : dialog
{
label = "Hello" ;
  : column {
[color=darkred][b]     : text {
      key = "textDate";
      label = "Today's Date";
    }
[/b][/color]     : list_box
    {
      key = "listTips" ;
      width = 60;
      height = 15;
      fixed_width = true;
      fixed_height = true;
      multiple_select = false;
   }
 }
 ok_cancel;
}

Assume you've got the date value formatted to your liking in a variable dateValue. Now you can set the value in that text using:

(set_tile "textDate" dateValue)

It looks like the list box's label, but it's actually a separate piece of text - so you need to wrap it inside a column - otherwise you could find that the text gets placed next to the list instead of above it.

Posted

label = "";

key=*key*; your key

 

Throw this in as your (set_tile *key* CuDate)

 
(setq CuDate (strcase (menucmd "M=$(edtime,$(getvar,date),DDMONYY)")))

 

Try it

Posted

THANK YOU BOYS :) :) :)

THNAK YOU, THANK YOU you are great!!!!

It is working perfect!

Posted

Actually giskumar's method would also work, it's just that your Lisp then needs to create the DCL file. I.e. you need to open the DCL file for writing (preferably in your temp environment) then have a write-line for each of the lines in the original DCL (remember to prefix backslashes to special characters such as \"). I'd actually advise doing that even if you don't go with giskumar's approach. It helps that you then don't need to have the DCL saved into a support folder for the lisp to work correctly.

 

To make life simpler for myself, I've made a command which converts the DCL into a lisp function: Dialogs.LSPThe command in ACad is DCL2LSP.

Posted

absolutely irneb, your method is better than to write-line, open dcl file and so on...

Posted

To make life simpler for myself, I've made a command which converts the DCL into a lisp function: [ATTACH]24710[/ATTACH]The command in ACad is DCL2LSP.

 

Great, Never thought of doing a routine for that...

Nice Irneb

Posted

Welcome! It's rather simplistic, not excessively optimized or even error protected, but it does save me some time :wink:

  • 11 months later...
Posted

irneb,

I just found your DCL2LSP routine. Could you please explain how it is used.

If I understand you correctly, it will let me convert .dcl coding into lisp. And from there I can copy that code and put it into my existing LISP (which calls the .dcl)...

If that is how it is supposed to work, that is exactly what I am looking for.

 

I have run the LISP routine and then tried pasting it into the LISP code in various places - like at the end or before the final parenthesis... with no luck. So any help would be very helpful.

 

Thanks for sharing as well

 

~Greg

Posted

You've got the idea but going a bit far. All my code actually does is change the DCL into a defun which creates the DCL in your temp folder then loads that. So all that it actually replaces is the call to load_dialog. The rest you still have to do, things such as new_dialog, set_tile, action_tile, etc. still need to be called to initialize the dialog. And the you still use start_dialog to actually display it. Then also you still need to use unload_dialog to remove it from RAM after you're finished.

 

To get a one-stop-defun which opens a dialog with all initializations and callback actions, plus returns the value obtained from start_dialog after closing and unloading, is a bit of a huge task. Especially since the initialization values and callback actions may differ drastically from dialog to dialog, not to mention key values are also of an infinite set of possibilities.

 

Though your mention has given me an idea, I'll have to look into this and come back with a more comprehensive dialog defun.

Posted

Just added this feature as well:

;;; Convert a DCL file to LSP with a defun to replace load_dialog & add a run_dialog defun for each dialog
(defun c:DCL2LSP (/ dclFName dcl lspFName lsp str n dialogs)
 ;; Get the DCL file's name
 (setq dclFName (findfile (getfiled "Select DCL to convert to LSP" "" "dcl" (+ 4 )))

 ;; Calculate the new LSP file's name
 (setq lspFName (strcat (vl-filename-directory dclFName) "\\load_dialog_" (vl-filename-base dclFName) ".lsp"))

 (setq dcl (open dclFName "r") ;Open DCL for reading
       lsp (open lspFName "w") ;Open LSP for write
 ) ;_ end of setq

 ;; Start LSP
 (setq str (strcat ";;; Function to load "
                   (vl-filename-base dclFName)
                   " dialog\n"
                   "(defun load_dialog_"
                   (vl-filename-base dclFName)
                   " (/ fn f)\n"
                   "  (setq fn (strcat (getvar \"TEMPPREFIX\") \""
                   (vl-filename-base dclFName)
                   ".DCL\"))\n"
                   "  (setq f (open fn \"w\"))"
           ) ;_ end of strcat
 ) ;_ end of setq
 (write-line str lsp)

 ;; Read each line in DCL & write to LSP
 (while (setq str (read-line dcl))
   ;; Check if a new dialog is started
   (if (wcmatch str "*:*dialog*")
     (setq dialogs (cons str dialogs))
   )

   ;; prefix all back-slashes with a back-slash
   (setq n 1)
   (while (<= n (strlen str))
     (if (= (substr str n 1) "\\")
       (progn
         (if (= n 1)
           (setq str (strcat "\\" str))
           (setq str (strcat (substr str 1 (- n 1)) "\\" (substr str n)))
         ) ;_ end of if
         (setq n (+ n 2))
       ) ;_ end of progn
       (setq n (1+ n))
     ) ;_ end of if
   ) ;_ end of while

   ;; prefix all double quotes with a back-slash
   (setq n 1)
   (while (<= n (strlen str))
     (if (= (substr str n 1) "\"")
       (progn
         (if (= n 1)
           (setq str (strcat "\\" str))
           (setq str (strcat (substr str 1 (- n 1)) "\\" (substr str n)))
         ) ;_ end of if
         (setq n (+ n 2))
       ) ;_ end of progn
       (setq n (1+ n))
     ) ;_ end of if
   ) ;_ end of while

   ;; Write to file
   (write-line
     (strcat "  (write-line \"" str "\" f)")
     lsp
   ) ;_ end of write-line
 ) ;_ end of while

 ;; Cloase the loading defun
 (write-line "  (close f)" lsp)
 (write-line "  (load_dialog fn)" lsp)
 (write-line ") ;_ end of defun" lsp)

 ;; Generate a run_dialog defun for each dialog contained in the DCL file
 (foreach d dialogs
   (setq str "")
   (while (wcmatch d "?*:*dialog*")
     (setq str (strcat str (substr d 1 1))
           d   (substr d 2)
     )
   )
   (setq str (vl-string-trim " \t\r\n:" str))
   (while (wcmatch str "*[ \t\r\n]*") (setq str (substr str 2)))
   (if (not (eq str ""))
     (progn
       (write-line (strcat "\n\r;;; Function to run the " str " dialog") lsp)
       (write-line (strcat "(defun run_dialog_" str " (key_list extra / dcl return)") lsp)
       (write-line
         (strcat "  (if (and (setq dcl (load_dialog_"
                 (vl-filename-base dclFName)
                 ")) (new_dialog DictItemEdit_DATALINK_AcExcel dcl))"
         )
         lsp
       )
       (write-line "    (progn" lsp)
       (write-line "      (foreach key key_list" lsp)
       (write-line "        (if (cadr key)" lsp)
       (write-line "          (set_tile (car key) (cadr key))" lsp)
       (write-line "        )" lsp)
       (write-line "        (if (caddr key)" lsp)
       (write-line "          (action_tile (car key) (caddr key))" lsp)
       (write-line "        )" lsp)
       (write-line "        (if (cadddr key)" lsp)
       (write-line "          (progn" lsp)
       (write-line "            (start_list (car key))" lsp)
       (write-line "            (mapcar 'add_list (cdddr key))" lsp)
       (write-line "            (end_list)" lsp)
       (write-line "          )" lsp)
       (write-line "        )" lsp)
       (write-line "      )" lsp)
       (write-line "      (if extra (eval extra))" lsp)
       (write-line "      (setq return (start_dialog))" lsp)
       (write-line "      (unload_dialog dcl)" lsp)
       (write-line "    )" lsp)
       (write-line "  )" lsp)
       (write-line "  return" lsp)
       (write-line ") ;_ end of defun" lsp)
     )
   )
 )

 (close lsp)
 (close dcl)
) ;_ end of defun

The LSP file generate will now contain a defun for each dialog inside the DCL. This defun would be named run_dialog_> and the arguments must be as follows:

 

  1. A list in the following structure

    1. Tile key name as string
    2. Value of tile as string, nil if not to be set
    3. Action expression as string, nil if not to be set
    4. nil if nothing further, else 4, 5, 6, etc. to be the list of string values to add to a list tile.
    5.  

      [*]Any lisp expression which can be evaluated, else nil. This would allow for any specials.

      The return value would be nil if something failed - like the DCL file didn't load properly. Else it returns the same value as obtained from start_dialog.

       

       

      Example: Say you had a "MyDialog : Dialog {..." in the DCL file. You should now have a (defun run_dialog_MyDialog ..." function. You can call it thus:

      (setq return_val
            (run_dialog_MyDialog
              '(("key1" "Value 1" "(setq var1 $value)")
                ("key2" nil "(button_press_1)")
                ("key3" nil nil "List item 1" "List item 2" "List item 3" "List item 4")
               )
              '(alert "This is simply to show you could have anything")
            )
      )

Posted

Thanks for the reply. I am currently swamped here at work so I cant test/try what you have added to the post.

At my current work and at my last job (which I still help a little)... Their are people who are too inept to be able to place things in their support folder. And to be honest, I would rather they not mess around with their support files. So I would be willing to pay some $$ for a way to convert a .dcl to .lsp that is able to be appended to the original .lsp in order to run...

 

Thanks for your time and reply irneb. I will look at this later

Have a good day

~Greg

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...