+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Super Member
    Computer Details
    woodman78's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell GX280
    Discipline
    Transport
    woodman78's Discipline Details
    Occupation
    Road Design Engineer
    Discipline
    Transport
    Details
    I work in a local authority design office with a staff of 13. We carry out road schemes ranging from overlays up to 2 km long new schemes.
    Using
    Civil 3D 2011
    Join Date
    Jul 2009
    Location
    Ireland
    Posts
    675

    Default Dialog problem with Toggle

    Registered forum members do not see this ad.

    I am trying to write a lisp with a dialog to create a new layer. The layer dialog box is slow in my machine and I hate having to wait for it to load. I want to create a dialog box instead of using the command line. Mainly just for the challenge. But I have been reading about how to code a toggle and I can't seem to get it to work.

    This is what I have so far. Everything works fine except the toggle.
    Code:
    layermakerccc: dialog { label = "Layer Creator";
      : edit_box { label = "Enter layer name :"; key = "name"; alignment = centered; edit_limit = 45; edit_width = 50; }
      : toggle {key = "tg1"; value = 1; label = "Set colour to be BYLAYER";}
      ok_only;
    }
    Code:
    (defun c:layermakerccc ( / *error* elast id lst name old vars answer1 )
    
      (defun *error* ( msg )
        (if (< 0 id) (unload_dialog id))
        (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
            (princ (strcat "\n** Error: " msg " **")))
        (princ)
      )
      (cond
        ( (or
            (<= (setq id (load_dialog "layermakerccc.dcl")) 0)
            (not (new_dialog "layermakerccc" id))
          )
          (princ "\n--> Error Loading Dialog.")
        )
        (t
          (setq *name1* (set_tile "name" (cond (*name1*) ("Default"))))
          (action_tile "name" "(setq *name1* $value)")
          (action_tile "tg1" "(setq answer1 $value)")
         
          (if
            (and
              (= 1 (start_dialog))
              (setq lst (acad_colordlg 1 nil))
            )
            (progn
              (setq name *name1*)
    
              (if (null (tblsearch "LAYER" name))
                (entmake
                  (list
                    (cons 0 "LAYER")
                    (cons 100 "AcDbSymbolTableRecord")
                    (cons 100 "AcDbLayerTableRecord")
                    (cons 2 name)
          (cons 62 lst)
                    (cons 70 0)
                  )
                )
              )
              (setvar 'CLAYER name)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (if (answer1 = 1)
    (progn
        (setvar "cecolor" "Bylayer")  
    ))
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    )
    )
    )
      )
      (if (< 0 id) (unload_dialog id))
      (mapcar 'setvar vars old)
      (princ)
    )
    Can someone point me in the right direction?

    Thanks.

  2. #2
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,634

    Default

    The $value returned by a dialog action is always a string. So your check of (which should have read (= answer1 1)) won't ever happen. It should rather be:
    (= answer1 "1")

    Or preferably: (eq answer1 "1")

    Or alternatively: (= (read answer1) 1)
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  3. #3
    Super Member
    Computer Details
    woodman78's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell GX280
    Discipline
    Transport
    woodman78's Discipline Details
    Occupation
    Road Design Engineer
    Discipline
    Transport
    Details
    I work in a local authority design office with a staff of 13. We carry out road schemes ranging from overlays up to 2 km long new schemes.
    Using
    Civil 3D 2011
    Join Date
    Jul 2009
    Location
    Ireland
    Posts
    675

    Default

    I tried that irneb but no joy. I don't get an error but it doesn't change the colour to bylayer either.

  4. #4
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,634

    Default

    Sorry then I'm not seeing a problem with your code. Could you perhaps attach the DCL file? Maybe there's some "error" in that? That is if by the ByLayer check you want the colour to be set to ByLayer after the command completes.

    Or do you mean you want the colour dialog not to display? In that case you'd need to modify the if condition regarding the acad_colordlg line. E.g. change the (setq lst (acad_colordlg 1 nil)) line to something like this:
    Code:
    (cond
      ((eq answer1 "1") 256)
      ((acad_colordlg 1 nil))
    )
    Edit: sorry scratch that - I'm being stupid! How would you set a layer's colour to bylayer? Not to mention, you've already given the DCL
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  5. #5
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,634

    Default

    Ok, just went through the whole thing. You're not initializing the answer1 variable. The action only happens when the user clicks on the toggle, so the default checked value is never shown. You have two options, either check for (not (eq answer1 "0")) or initialize it to "1" prior to starting the dialog. Here's some mods of your code, maked in green.
    Code:
    (defun c:layermakerccc (/ *error* elast id lst name old vars answer1 load-layermakerccc)
      (defun load-layermakerccc (/ fn f)
        (setq fn (strcat (getvar "TEMPPREFIX") "layermakerccc.dcl")
              f  (open fn "w")
        )
        (princ "layermakerccc: dialog { label = \"Layer Creator\";\n\r" f)
        (princ
          "  : edit_box { label = \"Enter layer name :\"; key = \"name\"; alignment = centered; edit_limit = 45; edit_width = 50; }\n\r"
          f
        )
        (princ "  : toggle {key = \"tg1\"; value = 1; label = \"Set colour to be BYLAYER\";}\n\r" f)
        (princ "  ok_only;\n\r" f)
        (princ "}\n\r" f)
        (close f)
        (load_dialog fn)
      )
    
      (defun *error* (msg)
        (if (< 0 id)
          (unload_dialog id)
        )
        (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
            (princ (strcat "\n** Error: " msg " **"))
        )
        (princ)
      )
      (cond
        ((or
           (<= (setq id (load-layermakerccc)) 0)
           (not (new_dialog "layermakerccc" id))
         )
         (princ "\n--> Error Loading Dialog.")
        )
        (t
         (setq *name1* (set_tile "name"
                                 (cond (*name1*)
                                       ("Default")
                                 )
                       )
         )
         (action_tile "name" "(setq *name1* $value)")
         (action_tile "tg1" "(setq answer1 $value)")
         (setq answer1 "1")
    
         (if
           (and
             (= 1 (start_dialog))
             (setq lst (acad_colordlg 1 nil))
           )
            (progn
              (setq name *name1*)
    
              (if (null (tblsearch "LAYER" name))
                (entmake
                  (list
                    (cons 0 "LAYER")
                    (cons 100 "AcDbSymbolTableRecord")
                    (cons 100 "AcDbLayerTableRecord")
                    (cons 2 name)
                    (cons 62 lst)
                    (cons 70 0)
                  )
                )
              )
              (setvar 'CLAYER name)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
              (if (eq answer1 "1")
                (setvar "cecolor" "Bylayer")
              )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            )
         )
        )
      )
      (if (< 0 id)
        (unload_dialog id)
      )
      (mapcar 'setvar vars old)
      (princ)
    )
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  6. #6
    Super Member
    Computer Details
    woodman78's Computer Details
    Operating System:
    Win XP
    Computer:
    Dell GX280
    Discipline
    Transport
    woodman78's Discipline Details
    Occupation
    Road Design Engineer
    Discipline
    Transport
    Details
    I work in a local authority design office with a staff of 13. We carry out road schemes ranging from overlays up to 2 km long new schemes.
    Using
    Civil 3D 2011
    Join Date
    Jul 2009
    Location
    Ireland
    Posts
    675

    Default

    Thanks irneb. That worked great. Have you combined the dcl file into the code?

  7. #7
    Super Member irneb's Avatar
    Computer Details
    irneb's Computer Details
    Operating System:
    Win7 Pro 64bit
    Computer:
    Antec One Hundred
    Motherboard:
    ASUS P8P67-Pro P67
    CPU:
    Intel i7 2600 @ 3.4GHz
    RAM:
    16GB-1600MHz
    Graphics:
    GeForce GT 430 (1GB)
    Primary Storage:
    Seagate1TB SATA2 - 7200rpm
    Monitor:
    Samsung 2333TN 23" 1920 x 1080 Full HD LCD Monitor2GW
    Discipline
    Architectural
    irneb's Discipline Details
    Occupation
    Architectural Technician and Programmer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Sep 2010
    Location
    Jo'burg SA
    Posts
    1,634

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by woodman78 View Post
    Thanks irneb. That worked great. Have you combined the dcl file into the code?
    Glad it worked for you.

    Yes, I tend to now combine the DCL into the LSP. Makes it easier to post code on these forums, and you don't need to have either of the files in support folders anymore - makes it a bit simpler to have it work nearly anywhere. I've used a little lisp routine of mine to combine the DCL into a defun of its own:
    Code:
    ;;; Convert a DCL file to LSP for inclusion into one file
    (defun c:DCL2LSP (/ dclFName dcl lspFName lsp str n)
      ;; Get the DCL file's name
      (setq dclFName (findfile (getfiled "Select DCL to convert to LSP" "" "dcl" (+ 4 8))))
    
      ;; 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))
        ;; 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
    
      (write-line "  (close f)" lsp)
      (write-line "  (load_dialog fn)" lsp)
      (write-line ") ;_ end of defun" lsp)
      (close lsp)
      (close dcl)
    ) ;_ end of defun
    It creates a LSP file with a prefix of "load_dialog_" and then the original DCL's filename. Open and copy-n-paste to where you want it. Then replace the load_dialog calls to the new defun without any arguments.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

Similar Threads

  1. Plot Dialog Box and - Taking Forever...Also problem with plotting multiple copies
    By D3YMO in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 10th Aug 2011, 02:55 pm
  2. Render Enviroment Dialog Box Problem
    By RODDY1 in forum AutoCAD 3D Modelling & Rendering
    Replies: 5
    Last Post: 29th May 2009, 04:39 pm
  3. Short Menu and Open file dialog problem
    By shaqstudio in forum AutoCAD General
    Replies: 2
    Last Post: 7th Apr 2009, 06:07 am
  4. F3 osnap toggle problem
    By lindsayb in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 4
    Last Post: 3rd May 2008, 01:58 am
  5. ddedit dialog box problem
    By monty0414 in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 1st May 2006, 06:53 pm

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