Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
New Member
eug3n91
Posts: 1
Registered: ‎05-27-2012
Message 1 of 6 (687 Views)

How to properly link to DCL?

687 Views, 5 Replies
05-27-2012 02:04 PM

Hi...I'm a total beginner with AutoLISP and I have to get an my first project done. The problem I'm having is that even if I try using the most basic code, taken from this tutorial:

 

http://www.afralisp.net/dialog-control-language/tutorials/dialog-boxes-and-autolisp-part-1.php

 

I still get an error as if the dcl file didn't exist. Both the lisp and the DCL files are both set in the same folder, together, no sub-folders or anything like that.

 

Please take a look and tell me what I'm doing wrong...I'm...really stumped and can't figure it out.

 

Here's my code:

 

- DCL:

samp1 : dialog {
    label = "Structural Holes";

    ok_cancel;
}

 

- LISP

 

(defun C:samp1()
  (setq dcl_id (load_dialog "C:\Users\Eugen Iancu\Desktop\learnLisp\samp1.DCL"))
  (if (not (new_dialog "C:\Users\Eugen Iancu\Desktop\learnLisp\samp1.DCL" dcl_id))

    (COMMAND "ZOOM") ;;THIS IS WERE MY FUNCTION GETS STUCK. I ADDED THIS SO I COULD CLEARLY SEE           WHAT GOES WRONG
    )

  (action_tile
       "cancel"
       "(done_dialog)(setq userclick nil)"
       )
  (action_tile
    "accept"
    "(done_dialog)(setq userclick T))"
    )

  (start_dialog)
 
  (princ)

 )

(princ)

Distinguished Mentor
_Tharwat
Posts: 636
Registered: ‎07-02-2010
Message 2 of 6 (672 Views)

Re: How to properly link to DCL?

05-27-2012 09:43 PM in reply to: eug3n91

First save the DCL codes to your Autocad Support folder e.g.

 

C:\Program Files\AutoCAD 20**\Support

 

and after that load the lisp file to your current opened drawing and run the code .

 

Good luck .

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Valued Mentor
Ian_Bryant
Posts: 362
Registered: ‎06-02-2005
Message 3 of 6 (618 Views)

Re: How to properly link to DCL?

05-31-2012 03:45 AM in reply to: eug3n91

"\" is treated as an escape character, when feeding a string to a lisp function.
You need to use "\\" in file path strings etc.
Replace
(setq dcl_id (load_dialog "C:\Users\Eugen Iancu\Desktop\learnLisp\samp1.DCL"))
with
(setq dcl_id (load_dialog "C:\\Users\\Eugen Iancu\\Desktop\\learnLisp\\samp1.DCL"))

 

The first argument of the new_dialog function is the name of a dialog defined in the DCL file, not the DCL file name itself.
Replace
(if (not (new_dialog "C:\Users\Eugen Iancu\Desktop\learnLisp\samp1.DCL" dcl_id))
with
(if (not (new_dialog "samp1" dcl_id))

 

Ian

*Expert Elite*
scot-65
Posts: 2,204
Registered: ‎12-11-2003
Message 4 of 6 (595 Views)

Re: How to properly link to DCL?

05-31-2012 03:41 PM in reply to: eug3n91

Whenever I write code that includes a dialog box, I first create a folder,

then add a "test.DWG", and of course place the LSP and DCL files in there

for a total of three files in this folder.

 

By opening this test.DWG file, you automatically have a "current directory" path

to where you do not need to declare a "Hard-Path" for the DCL file, as the DCL

is located in the current directory.

 

Whenever you make changes to the LSP file, you have to reload it:

(load "samp1"). Again, the current directory makes it easy to (re)load.

 

Do yourself a favor and always include (unload_dialog dcl_id) in your LSP file

just after the (start_dialog) so that too can be reloaded (more of a memory

manager than a reload).

 

Another trick I use is to temporarily cancel out the first and last lines, which saves

me a step to start the program without having to enter the command.

When the program is finished to my satisfaction, the semi-colons are removed.

 

;(defun c:TEST ()

 

:smileywink:

 

Good Luck!

Scot-65
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
*Expert Elite*
pbejse
Posts: 2,502
Registered: ‎11-24-2009
Message 5 of 6 (580 Views)

Re: How to properly link to DCL?

05-31-2012 11:00 PM in reply to: eug3n91

Another option is to incorporate the DCL onto your lisp rouitne

 

(Defun c:showLayerDemo  (/ CDiaStr a laylst)
(setq laylst nil)     
(defun CDiaStr  (/ fnSTR ListBoxDia)
            (setq StrDiaFnme (vl-filename-mktemp "tmp.DCL"))
            (setq fnSTR (open StrDiaFnme "a"))
            (write-line
                  "dcl_settings : default_dcl_settings { audit_level = 3; }
  ShowLayers : dialog
  { label = \"\"; key= \"Taytol\";
  : list_box { key = \"StrListS\"; multiple_select =
  true; width = 20; height = 20; } spacer ;
  ok_cancel;
  }"              fnSTR)
            (close fnSTR)
            T
            )
(defun ListBoxDia (DiaName DiaKey Title Lst)
     (setq StrDIA (load_dialog StrDiaFnme))
    (if (not (new_dialog DiaName StrDIA))
          (exit)
          )
    (start_list DiaKey)
    (mapcar 'add_list Lst)
    (end_list)
    (set_tile "Taytol" Title)
    (action_tile
          DiaKey
          (vl-prin1-to-string
                (quote (set (setq dd (read DiaKey))
                            (get_tile $key)))))
    (action_tile "accept" "(done_dialog 1)")
    (action_tile "cancel" "(done_dialog 0)")
    (start_dialog)
    (unload_dialog StrDIA)
    )

           
 (while (setq a (tblnext "LAYER" (null a)))
             (setq laylst (cons (cdr (assoc 2 a)) laylst)))
       (CDiaStr)
       (ListBoxDia
             "ShowLayers"
             "StrListS"
             "Select String to Follow"
             (acad_strlsort laylst))
       (vl-file-delete StrDiaFnme)
      
(princ)
      )

 

HTH

 

Mentor
diagodose2009
Posts: 263
Registered: ‎12-04-2009
Message 6 of 6 (553 Views)

DCL to LISP Generator..

06-01-2012 11:11 PM in reply to: pbejse

Embedding  the file.DCL into LISP source automatically...

[code]

t025 (strcat t025  "\noptionh :dialog {\n label = \"Style H Option\";\n:row {\n : boxed_column { \n label = \"Style H Options\";\n : boxed_radio_row {\n key = \"Holes\";\n label = \"How Many Holes Per Side?\";\n : radio_button {key = \"Two\"; ");;
t025 (strcat t025  "label = \"2 Holes Per Side\";}\n : radio_button {key = \"Three\"; label = \"3 Holes Per Side\";}\n }\n : boxed_radio_row {\n key = \"Inline\";\n label = \"Are Holes Inline?\";\n : radio_button {key = \"Y\"; label = \"Yes\";}\n : ");;
t025 (strcat t025  "radio_button {key = \"N\"; label = \"No\";}\n }\n : boxed_radio_row {\n key = \"Chamfer\";\n label = \"Is Inside Hole Chamfered?\";\n : radio_button {key = \"Yes\"; label = \"Yes\";}\n : radio_button {key = \"No\"; label = \"No\";}\n");;
t025 (strcat t025  " }\n : boxed_radio_row {\n key = \"InsOut\";\n label = \"Is Distance from Pole Shaft to Inside or Outside Hole?\";\n : radio_button {key = \"Inside\"; label = \"Inside Hole\";}\n : radio_button {key = \"Outside\"; label = \"Outside Hole\";}\n");;
t025 (strcat t025  " }\n }\n\n : boxed_column { \n label = \"Vang Dimensions and Table Information\";\n : boxed_radio_column {\n key = \"option\";\n label = \"Select Option\" ;\n : radio_button {key = \"1\"; label = \"Double Sided - Flats 1 && 7\" ");;
t025 (strcat t025  ";}\n : radio_button {key = \"2\"; label = \"Double Sided - Flats 4 && 10\" ;}\n : radio_button {key = \"3\"; label = \"Double Sided - Positive Angle\" ;}\n : radio_button {key = \"4\"; label = \"Double Sided - Negative Angle\";}\n");;
t025 (strcat t025  " : radio_button {key = \"5\"; label = \"Single Sided - Flat 1\" ;}\n : radio_button {key = \"6\"; label = \"Single Sided - Flat 4\" ;}\n : radio_button {key = \"7\"; label = \"Single Sided - Flat 7\" ;}\n : radio_button ");;
t025 (strcat t025  "{key = \"8\"; label = \"Single Sided - Flat 10\" ;}\n : radio_button {key = \"9\"; label = \"Single Sided - Positive Angle - Opposite Side\" ;}\n : radio_button {key = \"10\"; label = \"Single Sided - Positive Angle - Near Side\" ");;
t025 (strcat t025  ";}\n : radio_button {key = \"11\"; label = \"Single Sided - Negative Angle - Opposite Side\" ;}\n : radio_button {key = \"12\"; label = \"Single Sided - Negative Angle - Near Side\" ;}\n }\n }\n\n \n : boxed_column { \n key = ");;
t025 (strcat t025  "\"dimensions\";\n label = \"Dimensions of Vang\";\n : edit_box {\n label = \"Width of Vang (Include Inch Mark):\";\n edit_limit = 10;\n edit_width = 10;\n fixed_height = true;\n is_enabled = true;\n key = \"width\";\n }\n : edit_box ");;
t025 (strcat t025  "{\n label = \"Hole to Shaft Dimension (Include Inch Mark):\";\n edit_limit = 10;\n edit_width = 10;\n fixed_height = true;\n is_enabled = true;\n key = \"hole2shaft\";\n }\n : edit_box {\n label = \"Weld Size:\";\n edit_limit = ");;
t025 (strcat t025  "4;\n edit_width = 4;\n fixed_height = true;\n is_enabled = true;\n key = \"weldsz\";\n }\n : edit_box {\n label = \"Hole Diameter (Include Inch Mark):\";\n edit_limit = 10;\n edit_width = 10;\n fixed_height = true;\n is_enabled = ");;
t025 (strcat t025  "true;\n key = \"holedia\";\n }\n : edit_box {\n label = \"Radius (Include Inch Mark):\";\n edit_limit = 10;\n edit_width = 10;\n fixed_height = true;\n is_enabled = true;\n key = \"rad\";\n }\n : edit_box {\n label = \"Vertical Hole Spacing (Include Inch Mark):\";\n");;
t025 (strcat t025  " edit_limit = 10;\n edit_width = 10;\n fixed_height = true;\n is_enabled = true;\n key = \"VERT_HSPACING\";\n }\n : edit_box {\n label = \"Horizontal Hole Spacing (Include Inch mark):\";\n edit_limit ");;
t025 (strcat t025  "= 10;\n edit_width = 10;\n fixed_height = true;\n is_enabled = true;\n key = \"HORZ_HSPACING\";\n }\n }\n\n : boxed_radio_column { \n key = \"table\";\n label = \"Number of Lines in Table\" ;\n : radio_button {key = \"N1\"; ");;
t025 (strcat t025  "label = \"1 Line in Table\" ;}\n : radio_button {key = \"N2\"; label = \"2 Lines in Table\" ;}\n : radio_button {key = \"N3\"; label = \"3 Lines in Table\" ;}\n : radio_button {key = \"N4\"; label = \"4 Lines in Table\" ;}\n : radio_button ");;
t025 (strcat t025  "{key = \"N5\"; label = \"5 Lines in Table\" ;}\n }\n }\n\n}\n\n:row {alignment=centered; fixed_width=true;\n ok_cancel;\n}\n}\n\n"))
;(str_princ (list ))

[/code]

 

HERE is Original DCL :mantongue: :smileywink::smileyembarrassed:

[code]

optionh :dialog {
   label = "Style H Option";


:row {

  : boxed_column {         //COLUMN 1
  label = "Style H Options";
  : boxed_radio_row {
    key = "Holes";
    label = "How Many Holes Per Side?";
    : radio_button {key = "Two"; label = "2 Holes Per Side";}
    : radio_button {key = "Three"; label = "3 Holes Per Side";}
  }
  : boxed_radio_row {
    key = "Inline";
    label = "Are Holes Inline?";
    : radio_button {key = "Y"; label = "Yes";}
    : radio_button {key = "N"; label = "No";}
  }
  : boxed_radio_row {
    key = "Chamfer";
    label = "Is Inside Hole Chamfered?";
    : radio_button {key = "Yes"; label = "Yes";}
    : radio_button {key = "No"; label = "No";}
  }
  : boxed_radio_row {
    key = "InsOut";
    label = "Is Distance from Pole Shaft to Inside or Outside Hole?";
    : radio_button {key = "Inside"; label = "Inside Hole";}
    : radio_button {key = "Outside"; label = "Outside Hole";}
  }
 }//COLUMN 1


  : boxed_column {          //COLUMN 2
  label = "Vang Dimensions and Table Information";
  : boxed_radio_column {
    key = "option";
    label = "Select Option" ;
    : radio_button {key = "1"; label = "Double Sided - Flats 1 && 7" ;}
    : radio_button {key = "2"; label = "Double Sided - Flats 4 && 10" ;}
    : radio_button {key = "3"; label = "Double Sided - Positive Angle" ;}
    : radio_button {key = "4"; label = "Double Sided - Negative Angle";}
    : radio_button {key = "5"; label = "Single Sided - Flat 1" ;}
    : radio_button {key = "6"; label = "Single Sided - Flat 4" ;}
    : radio_button {key = "7"; label = "Single Sided - Flat 7" ;}
    : radio_button {key = "8"; label = "Single Sided - Flat 10" ;}
    : radio_button {key = "9"; label = "Single Sided - Positive Angle - Opposite Side" ;}
    : radio_button {key = "10"; label = "Single Sided - Positive Angle - Near Side" ;}
    : radio_button {key = "11"; label = "Single Sided - Negative Angle - Opposite Side" ;}
    : radio_button {key = "12"; label = "Single Sided - Negative Angle - Near Side" ;}
  }
 }//COLUMN 2

 
  : boxed_column {                   //COLUMN 3
    key = "dimensions";
    label = "Dimensions of Vang";
    : edit_box {
      label = "Width of Vang (Include Inch Mark):";
      edit_limit = 10;
      edit_width = 10;
      fixed_height = true;
      is_enabled = true;
      key = "width";
      }
    : edit_box {
      label = "Hole to Shaft Dimension (Include Inch Mark):";
      edit_limit = 10;
      edit_width = 10;
      fixed_height = true;
      is_enabled = true;
      key = "hole2shaft";
      }
    : edit_box {
      label = "Weld Size:";
      edit_limit = 4;
      edit_width = 4;
      fixed_height = true;
      is_enabled = true;
      key = "weldsz";
      }
    : edit_box {
      label = "Hole Diameter (Include Inch Mark):";
      edit_limit = 10;
      edit_width = 10;
      fixed_height = true;
      is_enabled = true;
      key = "holedia";
      }
    : edit_box {
      label = "Radius (Include Inch Mark):";
      edit_limit = 10;
      edit_width = 10;
      fixed_height = true;
      is_enabled = true;
      key = "rad";
      }
    : edit_box {
      label = "Vertical Hole Spacing (Include Inch Mark):";
      edit_limit = 10;
      edit_width = 10;
      fixed_height = true;
      is_enabled = true;
      key = "VERT_HSPACING";
      }
    : edit_box {
      label = "Horizontal Hole Spacing (Include Inch mark):";
      edit_limit = 10;
      edit_width = 10;
      fixed_height = true;
      is_enabled = true;
      key = "HORZ_HSPACING";
      }
     }//COLUMN 3


   : boxed_radio_column {                   //COLUMN 4
     key = "table";
     label = "Number of Lines in Table" ;
     : radio_button {key = "N1"; label = "1 Line in Table" ;}
     : radio_button {key = "N2"; label = "2 Lines in Table" ;}
     : radio_button {key = "N3"; label = "3 Lines in Table" ;}
     : radio_button {key = "N4"; label = "4 Lines in Table" ;}
     : radio_button {key = "N5"; label = "5 Lines in Table" ;}
     }
   }//COLUMN 4


}//ROW


:row {alignment=centered; fixed_width=true;
     ok_cancel;
}


}//DIALOG


[/code]

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!