Jump to content

Need help with DCL


AIberto

Recommended Posts

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

: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.

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • Grrr

    6

  • Lee Mac

    5

  • AIberto

    5

  • rkmcswain

    2

Top Posters In This Topic

Posted Images

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

 

(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.

Link to comment
Share on other sites

Here is a basic framework:

 

 

(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)
)

 

 

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;
   }
}

Link to comment
Share on other sites

Here is an alternative way to structure the GUI code:

([color=BLUE]defun[/color] c:dims ( [color=BLUE]/[/color] *error* dcf dch dcl des len tmp wid )

   ([color=BLUE]defun[/color] *error* ( msg )
       ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 dch) ([color=BLUE]unload_dialog[/color] dch))
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'file ([color=BLUE]type[/color] des)) ([color=BLUE]close[/color] des))
       ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'str ([color=BLUE]type[/color] dcl)) ([color=BLUE]findfile[/color] dcl)) ([color=BLUE]vl-file-delete[/color] dcl))
       ([color=BLUE]if[/color] ([color=BLUE]and[/color] msg ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color])))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg))
       )
       ([color=BLUE]princ[/color])
   )

   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] dcl ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"dims.dcl"[/color]))
           ([color=BLUE]setq[/color] des ([color=BLUE]open[/color] dcl [color=MAROON]"w"[/color]))
           ([color=BLUE]princ[/color]
               ([color=BLUE]strcat[/color]
                   [color=MAROON]"edit : edit_box"[/color]
                   [color=MAROON]"{"[/color]
                   [color=MAROON]"    edit_width = 10;"[/color]
                   [color=MAROON]"    width = 22;"[/color]
                   [color=MAROON]"    fixed_width = true;"[/color]
                   [color=MAROON]"    alignment = left;"[/color]
                   [color=MAROON]"    allow_accept = true;"[/color]
                   [color=MAROON]"}"[/color]
                   [color=MAROON]"dims : dialog"[/color]
                   [color=MAROON]"{"[/color]
                   [color=MAROON]"    label = \"Dimensions\";"[/color]
                   [color=MAROON]"    spacer;"[/color]
                   [color=MAROON]"    : row"[/color]
                   [color=MAROON]"    {"[/color]
                   [color=MAROON]"        : edit   { key = \"ed1\"; label = \"Length:\"; }"[/color]
                   [color=MAROON]"        : button { key = \"me1\" ; label = \">>\"; }"[/color]
                   [color=MAROON]"    }"[/color]
                   [color=MAROON]"    : row"[/color]
                   [color=MAROON]"    {"[/color]
                   [color=MAROON]"        : edit   { key = \"ed2\"; label = \"Width:\"; }"[/color]
                   [color=MAROON]"        : button { key = \"me2\" ; label = \">>\"; }"[/color]
                   [color=MAROON]"    }"[/color]
                   [color=MAROON]"    spacer;"[/color]
                   [color=MAROON]"    ok_cancel_help_errtile;"[/color]
                   [color=MAROON]"}"[/color]
               )
               des
           )
           ([color=BLUE]not[/color] ([color=BLUE]setq[/color] des ([color=BLUE]close[/color] des)))
           ([color=BLUE]<[/color] 0 ([color=BLUE]setq[/color] dch ([color=BLUE]load_dialog[/color] dcl)))
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] len [color=MAROON]""[/color] wid [color=MAROON]""[/color])
           ([color=BLUE]while[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] dcf '(0 1)))
               ([color=BLUE]cond[/color]
                   (   ([color=BLUE]new_dialog[/color] [color=MAROON]"dims"[/color] dch)
                       ([color=BLUE]set_tile[/color]    [color=MAROON]"ed1"[/color] len)
                       ([color=BLUE]set_tile[/color]    [color=MAROON]"ed2"[/color] wid)
                       ([color=BLUE]action_tile[/color] [color=MAROON]"ed1"[/color]  [color=MAROON]"(setq len $value)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"ed2"[/color]  [color=MAROON]"(setq wid $value)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"me1"[/color]  [color=MAROON]"(done_dialog 2)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"me2"[/color]  [color=MAROON]"(done_dialog 3)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"help"[/color] [color=MAROON]"(set_tile \"error\" \"Enter a length & width above.\")"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"accept"[/color]
                           ([color=BLUE]vl-prin1-to-string[/color]
                              '([color=BLUE]cond[/color]
                                   (   ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]distof[/color] len) ([color=BLUE]<[/color] 0.0 ([color=BLUE]distof[/color] len))))
                                       ([color=BLUE]set_tile[/color] [color=MAROON]"error"[/color] [color=MAROON]"Please enter a positive numerical length."[/color])
                                   )
                                   (   ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]distof[/color] wid) ([color=BLUE]<[/color] 0.0 ([color=BLUE]distof[/color] wid))))
                                       ([color=BLUE]set_tile[/color] [color=MAROON]"error"[/color] [color=MAROON]"Please enter a positive numerical width."[/color])
                                   )
                                   (   ([color=BLUE]done_dialog[/color] 1))
                               )
                           )
                       )
                       ([color=BLUE]setq[/color] dcf ([color=BLUE]start_dialog[/color]))
                   )
                   (   ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to display dialog"[/color])
                       ([color=BLUE]setq[/color] dcf 0)
                   )
               )
               ([color=BLUE]cond[/color]
                   (   ([color=BLUE]=[/color] 2 dcf)
                       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify a length: "[/color]))
                           ([color=BLUE]setq[/color] len ([color=BLUE]rtos[/color] tmp))
                       )
                   )
                   (   ([color=BLUE]=[/color] 3 dcf)
                       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify a width: "[/color]))
                           ([color=BLUE]setq[/color] wid ([color=BLUE]rtos[/color] tmp))
                       )
                   )
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 dcf)
               ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nUser entered dimensions: "[/color] len [color=MAROON]" x "[/color] wid))
               ([color=BLUE]princ[/color] [color=MAROON]"\n*Cancel*"[/color])
           )
       )
       ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to write & load DCL file."[/color])
   )
   (*error* [color=BLUE]nil[/color])
   ([color=BLUE]princ[/color])
)

Link to comment
Share on other sites

Here is an alternative way to structure the GUI code:
([color=BLUE]defun[/color] c:dims ( [color=BLUE]/[/color] *error* dcf dch dcl des len tmp wid )

   ([color=BLUE]defun[/color] *error* ( msg )
       ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 dch) ([color=BLUE]unload_dialog[/color] dch))
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'file ([color=BLUE]type[/color] des)) ([color=BLUE]close[/color] des))
       ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'str ([color=BLUE]type[/color] dcl)) ([color=BLUE]findfile[/color] dcl)) ([color=BLUE]vl-file-delete[/color] dcl))
       ([color=BLUE]if[/color] ([color=BLUE]and[/color] msg ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color])))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg))
       )
       ([color=BLUE]princ[/color])
   )

   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] dcl ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"dims.dcl"[/color]))
           ([color=BLUE]setq[/color] des ([color=BLUE]open[/color] dcl [color=MAROON]"w"[/color]))
           ([color=BLUE]princ[/color]
               ([color=BLUE]strcat[/color]
                   [color=MAROON]"edit : edit_box"[/color]
                   [color=MAROON]"{"[/color]
                   [color=MAROON]"    edit_width = 10;"[/color]
                   [color=MAROON]"    width = 22;"[/color]
                   [color=MAROON]"    fixed_width = true;"[/color]
                   [color=MAROON]"    alignment = left;"[/color]
                   [color=MAROON]"    allow_accept = true;"[/color]
                   [color=MAROON]"}"[/color]
                   [color=MAROON]"dims : dialog"[/color]
                   [color=MAROON]"{"[/color]
                   [color=MAROON]"    label = \"Dimensions\";"[/color]
                   [color=MAROON]"    spacer;"[/color]
                   [color=MAROON]"    : row"[/color]
                   [color=MAROON]"    {"[/color]
                   [color=MAROON]"        : edit   { key = \"ed1\"; label = \"Length:\"; }"[/color]
                   [color=MAROON]"        : button { key = \"me1\" ; label = \">>\"; }"[/color]
                   [color=MAROON]"    }"[/color]
                   [color=MAROON]"    : row"[/color]
                   [color=MAROON]"    {"[/color]
                   [color=MAROON]"        : edit   { key = \"ed2\"; label = \"Width:\"; }"[/color]
                   [color=MAROON]"        : button { key = \"me2\" ; label = \">>\"; }"[/color]
                   [color=MAROON]"    }"[/color]
                   [color=MAROON]"    spacer;"[/color]
                   [color=MAROON]"    ok_cancel_help_errtile;"[/color]
                   [color=MAROON]"}"[/color]
               )
               des
           )
           ([color=BLUE]not[/color] ([color=BLUE]setq[/color] des ([color=BLUE]close[/color] des)))
           ([color=BLUE]<[/color] 0 ([color=BLUE]setq[/color] dch ([color=BLUE]load_dialog[/color] dcl)))
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] len [color=MAROON]""[/color] wid [color=MAROON]""[/color])
           ([color=BLUE]while[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] dcf '(0 1)))
               ([color=BLUE]cond[/color]
                   (   ([color=BLUE]new_dialog[/color] [color=MAROON]"dims"[/color] dch)
                       ([color=BLUE]set_tile[/color]    [color=MAROON]"ed1"[/color] len)
                       ([color=BLUE]set_tile[/color]    [color=MAROON]"ed2"[/color] wid)
                       ([color=BLUE]action_tile[/color] [color=MAROON]"ed1"[/color]  [color=MAROON]"(setq len $value)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"ed2"[/color]  [color=MAROON]"(setq wid $value)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"me1"[/color]  [color=MAROON]"(done_dialog 2)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"me2"[/color]  [color=MAROON]"(done_dialog 3)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"help"[/color] [color=MAROON]"(set_tile \"error\" \"Enter a length & width above.\")"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"accept"[/color]
                           ([color=BLUE]vl-prin1-to-string[/color]
                              '([color=BLUE]cond[/color]
                                   (   ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]distof[/color] len) ([color=BLUE]<[/color] 0.0 ([color=BLUE]distof[/color] len))))
                                       ([color=BLUE]set_tile[/color] [color=MAROON]"error"[/color] [color=MAROON]"Please enter a positive numerical length."[/color])
                                   )
                                   (   ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]distof[/color] wid) ([color=BLUE]<[/color] 0.0 ([color=BLUE]distof[/color] wid))))
                                       ([color=BLUE]set_tile[/color] [color=MAROON]"error"[/color] [color=MAROON]"Please enter a positive numerical width."[/color])
                                   )
                                   (   ([color=BLUE]done_dialog[/color] 1))
                               )
                           )
                       )
                       ([color=BLUE]setq[/color] dcf ([color=BLUE]start_dialog[/color]))
                   )
                   (   ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to display dialog"[/color])
                       ([color=BLUE]setq[/color] dcf 0)
                   )
               )
               ([color=BLUE]cond[/color]
                   (   ([color=BLUE]=[/color] 2 dcf)
                       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify a length: "[/color]))
                           ([color=BLUE]setq[/color] len ([color=BLUE]rtos[/color] tmp))
                       )
                   )
                   (   ([color=BLUE]=[/color] 3 dcf)
                       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify a width: "[/color]))
                           ([color=BLUE]setq[/color] wid ([color=BLUE]rtos[/color] tmp))
                       )
                   )
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 dcf)
               ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nUser entered dimensions: "[/color] len [color=MAROON]" x "[/color] wid))
               ([color=BLUE]princ[/color] [color=MAROON]"\n*Cancel*"[/color])
           )
       )
       ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to write & load DCL file."[/color])
   )
   (*error* [color=BLUE]nil[/color])
   ([color=BLUE]princ[/color])
)

 

I was secretly hoping for you to answer. :cute:

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) !

Link to comment
Share on other sites

Here is an alternative way to structure the GUI code:
([color=BLUE]defun[/color] c:dims ( [color=BLUE]/[/color] *error* dcf dch dcl des len tmp wid )

   ([color=BLUE]defun[/color] *error* ( msg )
       ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 dch) ([color=BLUE]unload_dialog[/color] dch))
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'file ([color=BLUE]type[/color] des)) ([color=BLUE]close[/color] des))
       ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'str ([color=BLUE]type[/color] dcl)) ([color=BLUE]findfile[/color] dcl)) ([color=BLUE]vl-file-delete[/color] dcl))
       ([color=BLUE]if[/color] ([color=BLUE]and[/color] msg ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color])))
           ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg))
       )
       ([color=BLUE]princ[/color])
   )

   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] dcl ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"dims.dcl"[/color]))
           ([color=BLUE]setq[/color] des ([color=BLUE]open[/color] dcl [color=MAROON]"w"[/color]))
           ([color=BLUE]princ[/color]
               ([color=BLUE]strcat[/color]
                   [color=MAROON]"edit : edit_box"[/color]
                   [color=MAROON]"{"[/color]
                   [color=MAROON]"    edit_width = 10;"[/color]
                   [color=MAROON]"    width = 22;"[/color]
                   [color=MAROON]"    fixed_width = true;"[/color]
                   [color=MAROON]"    alignment = left;"[/color]
                   [color=MAROON]"    allow_accept = true;"[/color]
                   [color=MAROON]"}"[/color]
                   [color=MAROON]"dims : dialog"[/color]
                   [color=MAROON]"{"[/color]
                   [color=MAROON]"    label = \"Dimensions\";"[/color]
                   [color=MAROON]"    spacer;"[/color]
                   [color=MAROON]"    : row"[/color]
                   [color=MAROON]"    {"[/color]
                   [color=MAROON]"        : edit   { key = \"ed1\"; label = \"Length:\"; }"[/color]
                   [color=MAROON]"        : button { key = \"me1\" ; label = \">>\"; }"[/color]
                   [color=MAROON]"    }"[/color]
                   [color=MAROON]"    : row"[/color]
                   [color=MAROON]"    {"[/color]
                   [color=MAROON]"        : edit   { key = \"ed2\"; label = \"Width:\"; }"[/color]
                   [color=MAROON]"        : button { key = \"me2\" ; label = \">>\"; }"[/color]
                   [color=MAROON]"    }"[/color]
                   [color=MAROON]"    spacer;"[/color]
                   [color=MAROON]"    ok_cancel_help_errtile;"[/color]
                   [color=MAROON]"}"[/color]
               )
               des
           )
           ([color=BLUE]not[/color] ([color=BLUE]setq[/color] des ([color=BLUE]close[/color] des)))
           ([color=BLUE]<[/color] 0 ([color=BLUE]setq[/color] dch ([color=BLUE]load_dialog[/color] dcl)))
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] len [color=MAROON]""[/color] wid [color=MAROON]""[/color])
           ([color=BLUE]while[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] dcf '(0 1)))
               ([color=BLUE]cond[/color]
                   (   ([color=BLUE]new_dialog[/color] [color=MAROON]"dims"[/color] dch)
                       ([color=BLUE]set_tile[/color]    [color=MAROON]"ed1"[/color] len)
                       ([color=BLUE]set_tile[/color]    [color=MAROON]"ed2"[/color] wid)
                       ([color=BLUE]action_tile[/color] [color=MAROON]"ed1"[/color]  [color=MAROON]"(setq len $value)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"ed2"[/color]  [color=MAROON]"(setq wid $value)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"me1"[/color]  [color=MAROON]"(done_dialog 2)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"me2"[/color]  [color=MAROON]"(done_dialog 3)"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"help"[/color] [color=MAROON]"(set_tile \"error\" \"Enter a length & width above.\")"[/color])
                       ([color=BLUE]action_tile[/color] [color=MAROON]"accept"[/color]
                           ([color=BLUE]vl-prin1-to-string[/color]
                              '([color=BLUE]cond[/color]
                                   (   ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]distof[/color] len) ([color=BLUE]<[/color] 0.0 ([color=BLUE]distof[/color] len))))
                                       ([color=BLUE]set_tile[/color] [color=MAROON]"error"[/color] [color=MAROON]"Please enter a positive numerical length."[/color])
                                   )
                                   (   ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]distof[/color] wid) ([color=BLUE]<[/color] 0.0 ([color=BLUE]distof[/color] wid))))
                                       ([color=BLUE]set_tile[/color] [color=MAROON]"error"[/color] [color=MAROON]"Please enter a positive numerical width."[/color])
                                   )
                                   (   ([color=BLUE]done_dialog[/color] 1))
                               )
                           )
                       )
                       ([color=BLUE]setq[/color] dcf ([color=BLUE]start_dialog[/color]))
                   )
                   (   ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to display dialog"[/color])
                       ([color=BLUE]setq[/color] dcf 0)
                   )
               )
               ([color=BLUE]cond[/color]
                   (   ([color=BLUE]=[/color] 2 dcf)
                       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify a length: "[/color]))
                           ([color=BLUE]setq[/color] len ([color=BLUE]rtos[/color] tmp))
                       )
                   )
                   (   ([color=BLUE]=[/color] 3 dcf)
                       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify a width: "[/color]))
                           ([color=BLUE]setq[/color] wid ([color=BLUE]rtos[/color] tmp))
                       )
                   )
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 dcf)
               ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nUser entered dimensions: "[/color] len [color=MAROON]" x "[/color] wid))
               ([color=BLUE]princ[/color] [color=MAROON]"\n*Cancel*"[/color])
           )
       )
       ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to write & load DCL file."[/color])
   )
   (*error* [color=BLUE]nil[/color])
   ([color=BLUE]princ[/color])
)

 

Lee always rocks :thumbsup:

Link to comment
Share on other sites

Hi ,Lee , Grrr

 

I want make Dcl to lisp like this:

 

"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;"
                   "}"

 

 

(defun c:test (/ dfile tfile odf otf st)
(if
	(and 
		(setq dfile 
			(getfiled "Specify Dcl file :"
				(getvar 'DWGPREFIX)
				"dcl"
				16
			)
		)
		(setq tfile 
			(getfiled "Save to lsp file :"
				(strcat (vl-filename-directory dfile) "\\")
				"lsp"
				1
			)
		)
	)
	(progn
		(setq 
			odf (open dfile "r")
			otf (open tfile "w")
		)
		(while (setq st (read-line odf))
			(write-line (strcat (chr 34) st (chr 34)) otf)
		)
		(mapcar 'close (list odf otf))
	)
)
(princ)
)

 

How to add Bslash ?

" : edit { key = \"ed1\"; label = \"Length:\"; }"

Edited by AIberto
Link to comment
Share on other sites

Alberto, heres my version for this.

I think that you need to be registered there. Also in the comments you can see that marko_ribar has written his own one.

 

Grrr , Thank you, cool. :thumbsup:

Link to comment
Share on other sites

Grrr , Thank you, cool. :thumbsup:

 

Thanks! I was inspired by the Lee's way on writing his String-DCL codes:

 

(strcat
"dia : dialog"
"{"
"    label = \"Example\";"
"	children_alignment = centered;"
"    spacer;"
"    : edit_box { edit_width=40; }"
"    spacer;"
"    : button"
"    {"
"        label = \"• Custom OK Button •\";"
"        fixed_width = true;"
"        height = 3.0;"
"        key = \"accept\";"
"        is_default = true;"
"    }"
"    spacer;"
"}"
)

And was suprised when he told that he does them by hand, so I worked on that lisp to short some editing time and avoid possible conversion mistakes (because I also was used to rewrite DCL codes by hand like this).

Link to comment
Share on other sites

How to add Bslash ?

" : edit { key = \"ed1\"; label = \"Length:\"; }"

 

Hi,

 

Open your *.dcl file in Vslide then from the menu [search] -> Replace then in the first row add the string quote ( " ) then in the next row add ( \" ) then replace all.

 

And one string quote at the beginning and at the end of the whole codes.

Link to comment
Share on other sites

And was suprised when he told that he does them by hand...

 

Using the formatting utilities offered by the VLIDE, no manual typing involved (Select text > Ctrl+E > Prefix/Append | Find/Replace)

Link to comment
Share on other sites

Using the formatting utilities offered by the VLIDE, no manual typing involved (Select text > Ctrl+E > Prefix/Append | Find/Replace)

 

Sorry for misunderstanding, just tested it and yeah its fairly quick way! :thumbsup:

But I'm a NP++ guy and I use VLIDE only for debugging (not used to write codes from scratch there).

Link to comment
Share on other sites

Sorry for misunderstanding, just tested it and yeah its fairly quick way! :thumbsup:

 

No problem - certainly quicker in my opinion than having to save the DCL code to file and then run another program to select the saved DCL file and output another file...

 

But I'm a NP++ guy and I use VLIDE only for debugging (not used to write codes from scratch there).

 

NP++ is even easier: everything can be done through Search > Replace... (Ctrl+H)

 

Set the Search Mode to Regular Expressions and then:

[font=Courier New]Find    Replace
"       \\"
^       "
$       "[/font]

And done!

Link to comment
Share on other sites

No problem - certainly quicker in my opinion than having to save the DCL code to file and then run another program to select the saved DCL file and output another file...

 

 

 

NP++ is even easier: everything can be done through Search > Replace... (Ctrl+H)

 

Set the Search Mode to Regular Expressions and then:

[font=Courier New]Find    Replace
"       \\"
^       "
$       "[/font]

And done!

 

Wow, you are true hacker! :lol:

I didn't knew about ^ and $ - that can perfix/suffix every line, Thanks alot! :thumbsup:

Link to comment
Share on other sites

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...