+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21
  1. #1
    Senior Member AIberto's Avatar
    Using
    AutoCAD 2012
    Join Date
    May 2014
    Posts
    202

    Idea Need help with DCL

    Registered forum members do not see this ad.

    Hi all

    We meet again Happly 2017

    I don't know how to write lisp for this DCL. Please give a example……

    Two "edit_box" , two "button"
    When pressing the right button, Temporarily closes the dialog box and returns to the drawing area, Can pick a dimension or pick two point, get the value.
    Then return to the dialog box. put this value in the left edit_box

    test.png
    Code:
    :dialog {
        label = "test" ;
        :column {
            :row {
                :edit_box {
                    key = "ed1" ;
                    label = "Length:" ;
                }
                :button {
                    key = "me1" ;
                    label = "measure" ;
                }
            }
            :row {
                :edit_box {
                    key = "ed2" ;
                    label = "Width: " ;
                }
                :button {
                    key = "me2" ;
                    label = "measure" ;
                }
            }
        }
        :row {
            :button {
                key = "oki" ;
                label = "ok" ;
            }
            cancel_button;
        }
    }
    Thanks a lot.
    Lover with addition, subtraction resentment with, with the multiplication of gratitude and division with melancholy.

  2. #2
    Senior Member AIberto's Avatar
    Using
    AutoCAD 2012
    Join Date
    May 2014
    Posts
    202

    Default

    Is there anyone can help me???
    Lover with addition, subtraction resentment with, with the multiplication of gratitude and division with melancholy.

  3. #3
    Full Member
    Using
    AutoCAD not applicable
    Join Date
    Oct 2014
    Posts
    94

    Default

    There's a walk-through and an example of hiding dialog boxes on AfraLISP:

    http://www.afralisp.net/dialog-contr...ted-part-1.php

  4. #4
    Super Moderator
    Computer Details
    rkmcswain's Computer Details
    Operating System:
    Windows 7 Pro x64
    Computer:
    HP ZBook 17
    CPU:
    i7-4810MQ @ 2.80 GHZ
    RAM:
    16GB
    Graphics:
    Nvidia Quadro K4100M
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB SATA
    Monitor:
    (2) HP 23"
    Discipline
    Civil
    rkmcswain's Discipline Details
    Discipline
    Civil
    Details
    CAD Manager
    Using
    Civil 3D 2017
    Join Date
    Sep 2005
    Location
    Houston
    Posts
    4,351

    Default

    There is also a tutorial on this in the Autolisp documentation from Autodesk.

    It's not as easy to find this as it was in the days of printed books, but there you go. Good luck.
    R.K. McSwain
    CAD Panacea | twitter

  5. #5
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    743

    Default

    Heres my attempt (its close - but it doesn't work properly):

    Code:
    (defun c:test ( / *error* dch dcl des lst rundlg )
      (and 
        (setq *error*
          '(   ( m )
            (if (< 0 dch) (unload_dialog dch))
            (if (= 'file (type des)) (close des))
            (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl))
          )
        )
        (setq dcl (vl-filename-mktemp nil nil ".dcl"))
        (setq des (open dcl "w"))
        (write-line
          (strcat
            "dlgname :dialog"
            "{"
            "  label = \"test\" ;"
            "  :column {"
            "    :row {"
            "      :edit_box {"
            "        key = \"ed1\" ;"
            "        label = \"Length:\" ;"
            "      }"
            "      :button {"
            "        key = \"me1\" ;"
            "        label = \"measure\" ;"
            "      }"
            "    }"
            "    :row {"
            "      :edit_box {"
            "        key = \"ed2\" ;"
            "        label = \"Width: \" ;"
            "      }"
            "      :button {"
            "        key = \"me2\" ;"
            "        label = \"measure\" ;"
            "      }"
            "    }"
            "  }"
            "  :row"
            "  {"
            "    ok_cancel;"
            "  }"
            "}"
          )
          des
        )
        (not (setq des (close des)))
        (< 0 (setq dch (load_dialog dcl)))
        (progn
          (defun rundlg ( len wid / dlgRtn rtn )
            (new_dialog "dlgname" dch)
            
            (action_tile "ed1" "(setq len $value)")
            (action_tile "ed2" "(setq wid $value)")
            (if len (set_tile "ed1" (rtos len)))
            (if wid (set_tile "ed2" (rtos wid)))
            (action_tile "me1" "(done_dialog 2)")
            (action_tile "me2" "(done_dialog 3)")
            (action_tile "accept" "(setq rtn (list (get_tile \"ed1\") (get_tile \"ed2\"))) (done_dialog)")
    
            (setq dlgRtn (start_dialog))
            (cond
              ((= 2 dlgRtn)
                (setq len (getdist "\nSpecify length: "))
                (rundlg len wid)
              )
              ((= 3 dlgRtn)
                (setq wid (getdist "\nSpecify width: "))
                (rundlg len wid)
              )
            )
            rtn
          ); defun rundlg 
          (setq lst (rundlg nil nil))
          (if lst (alert (strcat "\n" (car lst) "\n" (cadr lst))))
        ); progn
      ); and 
      (*error* nil) (princ)
    )
    Never had luck with the action_tile part
    And I used Lee Mac's template for loading DCL files on the fly.

  6. #6
    Super Moderator
    Computer Details
    rkmcswain's Computer Details
    Operating System:
    Windows 7 Pro x64
    Computer:
    HP ZBook 17
    CPU:
    i7-4810MQ @ 2.80 GHZ
    RAM:
    16GB
    Graphics:
    Nvidia Quadro K4100M
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB SATA
    Monitor:
    (2) HP 23"
    Discipline
    Civil
    rkmcswain's Discipline Details
    Discipline
    Civil
    Details
    CAD Manager
    Using
    Civil 3D 2017
    Join Date
    Sep 2005
    Location
    Houston
    Posts
    4,351

    Default

    Here is a basic framework:


    Code:
    (defun c:test (/ dcl_id what_next cnt)
      (setq dcl_id (load_dialog "test.dcl"))  ; Load the dialog box.
      (setq what_next 2)
      (setq cnt 1)
      (while (>= what_next 2)                    ; Begin display loop.
        (if (null (new_dialog "test" dcl_id)) ; Initialize dialog
          (exit)                                 ; box, exit if nil
        ) ; endif                                ; returned.
    
        ; Set action to take if a button is pressed. Either button
        ; results in a done_dialog call to close the dialog box.
        ; Each button associates a specific status code with
        ; done_dialog, and this status code is returned by
        ; start_dialog.
        (action_tile "accept" "(done_dialog 1)") ; Set action for OK.
        (action_tile "me1" "(done_dialog 4)")    ; Set action for PickMe.
        (action_tile "me2" "(done_dialog 4)")
        (setq what_next (start_dialog))          ; Display dialog box.
    
        (cond
          ((= what_next 4)                      ; Prompt user to
            (getdist "\npick a point")          ; pick pt.
          )
          ((= what_next 0)
            (prompt "\nuser cancelled dialog")
          )
        )
      )
      (unload_dialog dcl_id)
     (princ)
    )

    Code:
    test: dialog {
        label = "test" ;
        :column {
            :row {
                :edit_box {
                    key = "ed1" ;
                    label = "Length:" ;
                }
                :button {
                    key = "me1" ;
                    label = "measure" ;
                }
            }
            :row {
                :edit_box {
                    key = "ed2" ;
                    label = "Width: " ;
                }
                :button {
                    key = "me2" ;
                    label = "measure" ;
                }
            }
        }
        :row {
            :button {
                key = "oki" ;
                label = "ok" ;
            }
            cancel_button;
        }
    }
    R.K. McSwain
    CAD Panacea | twitter

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    18,969

    Default

    Here is an alternative way to structure the GUI code:
    Code:
    (defun c:dims ( / *error* dcf dch dcl des len tmp wid )
    
        (defun *error* ( msg )
            (if (< 0 dch) (unload_dialog dch))
            (if (= 'file (type des)) (close des))
            (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl))
            (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (if
            (and
                (setq dcl (vl-filename-mktemp "dims.dcl"))
                (setq des (open dcl "w"))
                (princ
                    (strcat
                        "edit : edit_box"
                        "{"
                        "    edit_width = 10;"
                        "    width = 22;"
                        "    fixed_width = true;"
                        "    alignment = left;"
                        "    allow_accept = true;"
                        "}"
                        "dims : dialog"
                        "{"
                        "    label = \"Dimensions\";"
                        "    spacer;"
                        "    : row"
                        "    {"
                        "        : edit   { key = \"ed1\"; label = \"Length:\"; }"
                        "        : button { key = \"me1\" ; label = \">>\"; }"
                        "    }"
                        "    : row"
                        "    {"
                        "        : edit   { key = \"ed2\"; label = \"Width:\"; }"
                        "        : button { key = \"me2\" ; label = \">>\"; }"
                        "    }"
                        "    spacer;"
                        "    ok_cancel_help_errtile;"
                        "}"
                    )
                    des
                )
                (not (setq des (close des)))
                (< 0 (setq dch (load_dialog dcl)))
            )
            (progn
                (setq len "" wid "")
                (while (not (member dcf '(0 1)))
                    (cond
                        (   (new_dialog "dims" dch)
                            (set_tile    "ed1" len)
                            (set_tile    "ed2" wid)
                            (action_tile "ed1"  "(setq len $value)")
                            (action_tile "ed2"  "(setq wid $value)")
                            (action_tile "me1"  "(done_dialog 2)")
                            (action_tile "me2"  "(done_dialog 3)")
                            (action_tile "help" "(set_tile \"error\" \"Enter a length & width above.\")")
                            (action_tile "accept"
                                (vl-prin1-to-string
                                   '(cond
                                        (   (not (and (distof len) (< 0.0 (distof len))))
                                            (set_tile "error" "Please enter a positive numerical length.")
                                        )
                                        (   (not (and (distof wid) (< 0.0 (distof wid))))
                                            (set_tile "error" "Please enter a positive numerical width.")
                                        )
                                        (   (done_dialog 1))
                                    )
                                )
                            )
                            (setq dcf (start_dialog))
                        )
                        (   (princ "\nUnable to display dialog")
                            (setq dcf 0)
                        )
                    )
                    (cond
                        (   (= 2 dcf)
                            (if (setq tmp (getdist "\nSpecify a length: "))
                                (setq len (rtos tmp))
                            )
                        )
                        (   (= 3 dcf)
                            (if (setq tmp (getdist "\nSpecify a width: "))
                                (setq wid (rtos tmp))
                            )
                        )
                    )
                )
                (if (= 1 dcf)
                    (princ (strcat "\nUser entered dimensions: " len " x " wid))
                    (princ "\n*Cancel*")
                )
            )
            (princ "\nUnable to write & load DCL file.")
        )
        (*error* nil)
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    743

    Default

    Quote Originally Posted by Lee Mac View Post
    Here is an alternative way to structure the GUI code:
    Code:
    (defun c:dims ( / *error* dcf dch dcl des len tmp wid )
    
        (defun *error* ( msg )
            (if (< 0 dch) (unload_dialog dch))
            (if (= 'file (type des)) (close des))
            (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl))
            (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (if
            (and
                (setq dcl (vl-filename-mktemp "dims.dcl"))
                (setq des (open dcl "w"))
                (princ
                    (strcat
                        "edit : edit_box"
                        "{"
                        "    edit_width = 10;"
                        "    width = 22;"
                        "    fixed_width = true;"
                        "    alignment = left;"
                        "    allow_accept = true;"
                        "}"
                        "dims : dialog"
                        "{"
                        "    label = \"Dimensions\";"
                        "    spacer;"
                        "    : row"
                        "    {"
                        "        : edit   { key = \"ed1\"; label = \"Length:\"; }"
                        "        : button { key = \"me1\" ; label = \">>\"; }"
                        "    }"
                        "    : row"
                        "    {"
                        "        : edit   { key = \"ed2\"; label = \"Width:\"; }"
                        "        : button { key = \"me2\" ; label = \">>\"; }"
                        "    }"
                        "    spacer;"
                        "    ok_cancel_help_errtile;"
                        "}"
                    )
                    des
                )
                (not (setq des (close des)))
                (< 0 (setq dch (load_dialog dcl)))
            )
            (progn
                (setq len "" wid "")
                (while (not (member dcf '(0 1)))
                    (cond
                        (   (new_dialog "dims" dch)
                            (set_tile    "ed1" len)
                            (set_tile    "ed2" wid)
                            (action_tile "ed1"  "(setq len $value)")
                            (action_tile "ed2"  "(setq wid $value)")
                            (action_tile "me1"  "(done_dialog 2)")
                            (action_tile "me2"  "(done_dialog 3)")
                            (action_tile "help" "(set_tile \"error\" \"Enter a length & width above.\")")
                            (action_tile "accept"
                                (vl-prin1-to-string
                                   '(cond
                                        (   (not (and (distof len) (< 0.0 (distof len))))
                                            (set_tile "error" "Please enter a positive numerical length.")
                                        )
                                        (   (not (and (distof wid) (< 0.0 (distof wid))))
                                            (set_tile "error" "Please enter a positive numerical width.")
                                        )
                                        (   (done_dialog 1))
                                    )
                                )
                            )
                            (setq dcf (start_dialog))
                        )
                        (   (princ "\nUnable to display dialog")
                            (setq dcf 0)
                        )
                    )
                    (cond
                        (   (= 2 dcf)
                            (if (setq tmp (getdist "\nSpecify a length: "))
                                (setq len (rtos tmp))
                            )
                        )
                        (   (= 3 dcf)
                            (if (setq tmp (getdist "\nSpecify a width: "))
                                (setq wid (rtos tmp))
                            )
                        )
                    )
                )
                (if (= 1 dcf)
                    (princ (strcat "\nUser entered dimensions: " len " x " wid))
                    (princ "\n*Cancel*")
                )
            )
            (princ "\nUnable to write & load DCL file.")
        )
        (*error* nil)
        (princ)
    )
    I was secretly hoping for you to answer.
    DCL is my weakness and I always try to help/participate in such threads.
    Thank you for tutoring us (including me: since I'm registered on cadtutor) !

  9. #9
    Senior Member AIberto's Avatar
    Using
    AutoCAD 2012
    Join Date
    May 2014
    Posts
    202

    Default

    Thank you everyone here replies !!! Lee ,Good example! Good forum! Good people !
    Lover with addition, subtraction resentment with, with the multiplication of gratitude and division with melancholy.

  10. #10
    Senior Member gS7's Avatar
    Computer Details
    gS7's Computer Details
    Operating System:
    Windows Xp sp3
    RAM:
    4 GB
    Monitor:
    Viewsonic
    Discipline
    Surveying
    gS7's Discipline Details
    Occupation
    Drafts man / Surveyor
    Discipline
    Surveying
    Using
    AutoCAD 2009
    Join Date
    May 2012
    Location
    Udupi,INDIA
    Posts
    218

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Lee Mac View Post
    Here is an alternative way to structure the GUI code:
    Code:
    (defun c:dims ( / *error* dcf dch dcl des len tmp wid )
    
        (defun *error* ( msg )
            (if (< 0 dch) (unload_dialog dch))
            (if (= 'file (type des)) (close des))
            (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl))
            (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (if
            (and
                (setq dcl (vl-filename-mktemp "dims.dcl"))
                (setq des (open dcl "w"))
                (princ
                    (strcat
                        "edit : edit_box"
                        "{"
                        "    edit_width = 10;"
                        "    width = 22;"
                        "    fixed_width = true;"
                        "    alignment = left;"
                        "    allow_accept = true;"
                        "}"
                        "dims : dialog"
                        "{"
                        "    label = \"Dimensions\";"
                        "    spacer;"
                        "    : row"
                        "    {"
                        "        : edit   { key = \"ed1\"; label = \"Length:\"; }"
                        "        : button { key = \"me1\" ; label = \">>\"; }"
                        "    }"
                        "    : row"
                        "    {"
                        "        : edit   { key = \"ed2\"; label = \"Width:\"; }"
                        "        : button { key = \"me2\" ; label = \">>\"; }"
                        "    }"
                        "    spacer;"
                        "    ok_cancel_help_errtile;"
                        "}"
                    )
                    des
                )
                (not (setq des (close des)))
                (< 0 (setq dch (load_dialog dcl)))
            )
            (progn
                (setq len "" wid "")
                (while (not (member dcf '(0 1)))
                    (cond
                        (   (new_dialog "dims" dch)
                            (set_tile    "ed1" len)
                            (set_tile    "ed2" wid)
                            (action_tile "ed1"  "(setq len $value)")
                            (action_tile "ed2"  "(setq wid $value)")
                            (action_tile "me1"  "(done_dialog 2)")
                            (action_tile "me2"  "(done_dialog 3)")
                            (action_tile "help" "(set_tile \"error\" \"Enter a length & width above.\")")
                            (action_tile "accept"
                                (vl-prin1-to-string
                                   '(cond
                                        (   (not (and (distof len) (< 0.0 (distof len))))
                                            (set_tile "error" "Please enter a positive numerical length.")
                                        )
                                        (   (not (and (distof wid) (< 0.0 (distof wid))))
                                            (set_tile "error" "Please enter a positive numerical width.")
                                        )
                                        (   (done_dialog 1))
                                    )
                                )
                            )
                            (setq dcf (start_dialog))
                        )
                        (   (princ "\nUnable to display dialog")
                            (setq dcf 0)
                        )
                    )
                    (cond
                        (   (= 2 dcf)
                            (if (setq tmp (getdist "\nSpecify a length: "))
                                (setq len (rtos tmp))
                            )
                        )
                        (   (= 3 dcf)
                            (if (setq tmp (getdist "\nSpecify a width: "))
                                (setq wid (rtos tmp))
                            )
                        )
                    )
                )
                (if (= 1 dcf)
                    (princ (strcat "\nUser entered dimensions: " len " x " wid))
                    (princ "\n*Cancel*")
                )
            )
            (princ "\nUnable to write & load DCL file.")
        )
        (*error* nil)
        (princ)
    )
    Lee always rocks
    Ganesh Shetty

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts