definition could not be loaded

definition could not be loaded

qkakkel
Contributor Contributor
5,941 Views
40 Replies
Message 1 of 41

definition could not be loaded

qkakkel
Contributor
Contributor

What goes wrong I try to load a lisp file but I get the message definition could not be loaded.

I am still a newbee with lisp!

 

(defun C:SAMPLE33 ()

(defun saveVars (/ readlist count item)

;;;---Setup a list to hold the selected items
(setq retlist (list))

;;;---Save the list setting
(setq readlist (get_tile "myList1"))

;;;---Setup a variable to run through the list
(setq count 1)

;;;---cycle through the list getting all of the selected items
(while (setq item (read readlist))
(setq retlist2 (append retList2 (list (nth item myList1))))
(while
(and
(/= "" (substr readlist count 1))
(/= "" (substr readList count 1))
)
(setq count (1+ count))
)
(setq readlist (substr readlist count))
)
;;;---Setup a list to hold the selected items
(setq retList2 (list))

;;;---Save the list setting
(setq readlist (get_tile "myList2"))

;;;---Setup a variable to run through the list
(setq count 1)

;;;---cycle through the list getting all of the selected items
(while (setq item (read readList))
(setq retlist2 (append retList2 (list (nth item mylist2))))
(while
(and
(/= " " (substr readlist count 1))
(/= "" (substr readlist count 1))
)
(setq count (1+ count))
)
(setq readlist (substr readlist count))
)
)


(setq myList1 (list "Electrical" "Structual" "Plumbing" "Foundation"))
(setq myList2 (list "Plastic" "Steel" "Aluminium" "Concrete"))

;;;---Load the dcl file from disk into memory
(if (not (setq dcl_id (load_dialog "SAMPLE33.dcl")))
(progn
(alert "The DCL file could not be loaded!")
(exit)
)

;;;---Else, the DCL file was loaded
(progn

 

;;;---Load the dialog definition inside the DCL file
(if (not (new_dialog "SAMPLE33" dcl_id))
(progn
(alert "The SAMPLE33 definition could not be loaded!")
(exit)
)

;;;---Else, the definition was loaded
(progn

(start_list "myList1" 3)
(mapcar 'add_list myList1)
(end_list)

(start_list "myList2" 3)
(mapcar 'add_list myList2)
(end_list)

;;;---if an action event occurs, do this function
(action_tile "accept" "(saveVars)(done_dialog 2)")
(action_tile "cancel" "done_dialog 1)")

;;;---Display the dialog box
(setq ddiag (start_dialog))

;;;---Unload the dialog box
(unload_dialog dcl_id)

;;;---if the user pressed the Cancel button
(if (= ddiag 1)
(princ "\n Sample33 cancelled!")
)

;;;---if the user pressed the Okay button
(if (= ddiag 2)
(progn


;;;---Inform the user of his selection from the first list
(princ (strcat "\n You chose "
(car retList)
"from the
first list box."
)
)

;;;---Inform the user of his selection from the second list
(princ "\n Your choise(s) from the second list box: ")
(foreach a retList2
(princ "\n ")
(princ a)
)
)
)

;;;;---Suppress the last echo for a clean exit
(princ)

)
)
)
)
)

 

0 Likes
Accepted solutions (1)
5,942 Views
40 Replies
Replies (40)
Message 2 of 41

ВeekeeCZ
Consultant
Consultant

You also need to have SAMPLE33.dcl file, both stored at searchable (support) path.

0 Likes
Message 3 of 41

qkakkel
Contributor
Contributor
The are, both stored at searchable (support) path.

That is why I do not understand why the file is not loaded correctly

0 Likes
Message 4 of 41

ВeekeeCZ
Consultant
Consultant

That can't be right, because that's what I get and I don't have dcl file at all.

 

Try copy-paste this line to the command-line

(findfile "SAMPLE33.dcl") 

If you get nil, it could not be found.

0 Likes
Message 5 of 41

Moshe-A
Mentor
Mentor

@qkakkel  hi,

 

this lisp file loads ok (but i can not test without the dcl) you need to check the dcl file for wrong definition this could be the reason it is not load.

 

i made some modification for you, define some variables as locals

on line 105 instead of using (princ "\n") to drop line we use (terpri) this is all this function do 😀

i moved line 113 (princ) quiet exit to line 120

 

;;;---if an action event occurs, do this function
(action_tile "accept" "(saveVars)(done_dialog 2)")
(action_tile "cancel" "done_dialog 1)")

 

the default return value for dcl OK ("accept") button is 1

and for the Cancel ("cancel") button is 0

 

although what you did is not wrong it is better to stick to defaults.

 

Moshe

 

 

 

 

(defun C:SAMPLE33 (/ saveVars ; local function
                     mylist1 mylist2 dcl_id ddiag) ; local variables

 (defun saveVars (/ readlist count item) ; local variables

  ;;;---Setup a list to hold the selected items
  (setq retlist (list))

  ;;;---Save the list setting
  (setq readlist (get_tile "myList1"))

  ;;;---Setup a variable to run through the list
  (setq count 1)

  ;;;---cycle through the list getting all of the selected items
  (while (setq item (read readlist))
   (setq retlist2 (append retList2 (list (nth item myList1))))
    
   (while (and
            (/= "" (substr readlist count 1))
            (/= "" (substr readList count 1))
          )
    (setq count (1+ count))
   ); while
    
   (setq readlist (substr readlist count))
  ); while
   
  ;;;---Setup a list to hold the selected items
  (setq retList2 (list))

  ;;;---Save the list setting
  (setq readlist (get_tile "myList2"))

  ;;;---Setup a variable to run through the list
  (setq count 1)

  ;;;---cycle through the list getting all of the selected items
  (while (setq item (read readList))
    (setq retlist2 (append retList2 (list (nth item mylist2))))
    (while (and
             (/= " " (substr readlist count 1))
             (/= "" (substr readlist count 1))
           )
     (setq count (1+ count))
    ); while
    (setq readlist (substr readlist count))
   ); while
 ); saveVars 


 (setq myList1 (list "Electrical" "Structual" "Plumbing" "Foundation"))
 (setq myList2 (list "Plastic" "Steel" "Aluminium" "Concrete"))

 ;;;---Load the dcl file from disk into memory
 (if (not (setq dcl_id (load_dialog "SAMPLE33.dcl")))
  (progn
   (alert "SAMPLE33.dcl file could not be loaded!")
   (exit)
  )

  ;;;---Else, the DCL file was loaded
  (progn
   ;;;---Load the dialog definition inside the DCL file
   (if (not (new_dialog "SAMPLE33" dcl_id))
    (progn
     (alert "The SAMPLE33.dcl file could not be loaded!")
     (exit)
    )
    ;;;---Else, the definition was loaded
    (progn
     (start_list "myList1" 3)
     (mapcar 'add_list myList1)
     (end_list)

     (start_list "myList2" 3)
     (mapcar 'add_list myList2)
     (end_list)

     ;;;---if an action event occurs, do this function
     (action_tile "accept" "(saveVars)(done_dialog 2)")
     (action_tile "cancel" "done_dialog 1)")

     ;;;---Display the dialog box
     (setq ddiag (start_dialog))

    ;;;---Unload the dialog box
    (unload_dialog dcl_id)

    ;;;---if the user pressed the Cancel button
    (if (= ddiag 1)
     (princ "\n Sample33 cancelled!")
    )

    ;;;---if the user pressed the Okay button
    (if (= ddiag 2)
     (progn
      ;;;---Inform the user of his selection from the first list
      (princ (strcat "\n You chose " (car retList) "from the first list box."))

      ;;;---Inform the user of his selection from the second list
      (princ "\n Your choise(s) from the second list box: ")
      
      (foreach a retList2
       ; (princ "\n ")
       (terpri) 
       (princ a)
      )
     ); progn
    ); if

    ;;;;---Suppress the last echo for a clean exit
   ; (princ)

    ); progn
   ); if
  ); progn
 ); if
  
 (princ) ; clean exit
); C:SAMPLE33

 

 

0 Likes
Message 6 of 41

qkakkel
Contributor
Contributor
SAMPLE33 : dialog {
label = "Sample Dialog Box Routine - Part 3";
: column {
: boxed_row {
: list_box {
label = "Choose Item";
key = "mylist1";
height = 15;
width = 25;
multiple_select = false;
fixed_width_font = true;
value = "";
}
: list_box {
label = "Choose Item";
key = "myList2";
height = 15;
width = 25;
multiple_select = false;
fixed_width_font = true;
value = "";
}
}
: boxed_row {
: button {
key = "accept";
label = "Okay";
is_default = true;
}
: button {
key = "cancel";
label = "cancel";
is_default = false;
is_cancel = true;
}
}
}
}

0 Likes
Message 7 of 41

qkakkel
Contributor
Contributor
Is not working get nil back

0 Likes
Message 8 of 41

ВeekeeCZ
Consultant
Consultant

So instead of just "SAMPLE33.dcl" in your code, replace that with the entire file path - BUT replace all \ with \\

 

0 Likes
Message 9 of 41

Moshe-A
Mentor
Mentor

@qkakkel 

 

the dcl is OK and it's load so i guess the problem at you side, autocad can not find it.

for test, put a copy of it in your document folder and give it a try.

 

Moshe

 

 

SAMPLE33 : dialog {
  label = "Sample Dialog Box Routine - Part 3";
  : column {
    : boxed_row {
      : list_box {
        label = "Choose Item";
        key = "mylist1";
        height = 15;
        width = 25;
        multiple_select = false;
        fixed_width_font = true;
        value = "";
       }
       
       : list_box {
         label = "Choose Item";
         key = "myList2";
         height = 15;
         width = 25;
         multiple_select = false;
         fixed_width_font = true;
         value = "";
       }
    }
    
    : boxed_row {
      : button {
        key = "accept";
        label = "Okay";
        is_default = true;
      }
      
      : button {
        key = "cancel";
        label = "cancel";
        is_default = false;
        is_cancel = true;
      }
    }
  }
}

 

0 Likes
Message 10 of 41

qkakkel
Contributor
Contributor
This is the pdf file that I have used to learn something .
0 Likes
Message 11 of 41

qkakkel
Contributor
Contributor
Ok thanks I wil try that.

By the way this is the pdf file were I was working from.
I think it is a littlebit messy


0 Likes
Message 12 of 41

paullimapa
Mentor
Mentor

try using following changes to lsp & dcl

(defun C:SAMPLE33 (/ saveVars ; local function
                     mylist1 mylist2 dcl_id ddiag) ; local variables

 (defun saveVars (/ readlist count item) ; local variables

  ;;;---Setup a list to hold the selected items
  (setq retlist (list))

  ;;;---Save the list setting
  (setq readlist (get_tile "myList1"))

  ;;;---Setup a variable to run through the list
  (setq count 1)

  ;;;---cycle through the list getting all of the selected items
  (while (setq item (read readlist))
;   (setq retlist2 (append retList2 (list (nth item myList1)))) ; error
   (setq retlist (append retlist (list (nth item myList1))))
    
   (while (and
            (/= " " (substr readlist count 1)) ; add space
            (/= "" (substr readList count 1))
          )
    (setq count (1+ count))
   ); while
    
   (setq readlist (substr readlist count))
  ); while
   
  ;;;---Setup a list to hold the selected items
  (setq retList2 (list))

  ;;;---Save the list setting
  (setq readlist (get_tile "myList2"))

  ;;;---Setup a variable to run through the list
  (setq count 1)

  ;;;---cycle through the list getting all of the selected items
  (while (setq item (read readList))
    (setq retlist2 (append retList2 (list (nth item myList2)))) ; caps
    (while (and
             (/= " " (substr readlist count 1))
             (/= "" (substr readlist count 1))
           )
     (setq count (1+ count))
    ); while
    (setq readlist (substr readlist count))
   ); while
 ); saveVars 


 (setq myList1 (list "Electrical" "Structual" "Plumbing" "Foundation"))
 (setq myList2 (list "Plastic" "Steel" "Aluminium" "Concrete"))

 ;;;---Load the dcl file from disk into memory
 (if (not (setq dcl_id (load_dialog "SAMPLE33.dcl")))
  (progn
   (alert "SAMPLE33.dcl file could not be loaded!")
   (exit)
  )

  ;;;---Else, the DCL file was loaded
  (progn
   ;;;---Load the dialog definition inside the DCL file
   (if (not (new_dialog "SAMPLE33" dcl_id))
    (progn
     (alert "The SAMPLE33.dcl file could not be loaded!")
     (exit)
    )
    ;;;---Else, the definition was loaded
    (progn
     (start_list "myList1" 3) ; dcl list box label changed to match case
     (mapcar 'add_list myList1)
     (end_list)
     (start_list "myList2" 3)
     (mapcar 'add_list myList2)
     (end_list)

     ;;;---if an action event occurs, do this function
     (action_tile "accept" "(saveVars)(done_dialog 2)")
;     (action_tile "cancel" "done_dialog 1)") ; correction here
     (action_tile "cancel" "(done_dialog 1)") 

     ;;;---Display the dialog box
     (setq ddiag (start_dialog))

    ;;;---Unload the dialog box
    (unload_dialog dcl_id)

    ;;;---if the user pressed the Cancel button
    (if (= ddiag 1)
     (princ "\n Sample33 cancelled!")
    )

    ;;;---if the user pressed the Okay button
    (if (= ddiag 2)
     (progn
      ;;;---Inform the user of his selection from the first list
;      (princ (strcat "\n You chose " (car retList) "from the first list box.")) ; need correction
      (princ "\n Your choise(s) from the first list box: ")
; add following foreach code      
      (foreach a retlist
       ; (princ "\n ")
       (terpri) 
       (princ a)
      )

      ;;;---Inform the user of his selection from the second list
      (princ "\n Your choise(s) from the second list box: ")
      
      (foreach a retList2
       ; (princ "\n ")
       (terpri) 
       (princ a)
      )
     ); progn
    ); if

    ;;;;---Suppress the last echo for a clean exit
   ; (princ)

    ); progn
   ); if
  ); progn
 ); if
  
 (princ) ; clean exit
); C:SAMPLE33
SAMPLE33 : dialog {
  label = "Sample Dialog Box Routine - Part 3";
  : column {
    : boxed_row {
      : list_box {
        label = "Choose Item";
        key = "myList1";
        height = 15;
        width = 25;
        multiple_select = false;
        fixed_width_font = true;
        value = "";
       }
       
       : list_box {
         label = "Choose Item";
         key = "myList2";
         height = 15;
         width = 25;
         multiple_select = false;
         fixed_width_font = true;
         value = "";
       }
    }
    
    : boxed_row {
      : button {
        key = "accept";
        label = "Okay";
        is_default = true;
      }
      
      : button {
        key = "cancel";
        label = "cancel";
        is_default = false;
        is_cancel = true;
      }
    }
  }
}

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 13 of 41

3wood
Advisor
Advisor

Can you load other lisp files in the same folder without problem?

If you can load all other lisp files but only not this one, can you try moving it to another folder or renaming the lisp file?

 

0 Likes
Message 14 of 41

paullimapa
Mentor
Mentor

there were errors in the code the way they were typed in both the lsp & dcl files which would stop the loading process

when @qkakkel downloads my corrected versions then should be able to successfully load & run the new sample33 code which actually launches a dialog window with two list boxes for the user to select from

what's still missing is an option to select multiple items from the list boxes instead of just one


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 15 of 41

qkakkel
Contributor
Contributor
Where can I find the correct one?
I already have two differend versions!
0 Likes
Message 16 of 41

qkakkel
Contributor
Contributor
Yes I can load other lisp files without problems.
All of the samples I try to let work are from the internet I download a PDF file with examples
Can you load other lisp files in the same folder without problem? If you can load all other lisp files but only not this one, can you try moving it to another folder or renaming the lisp file?

0 Likes
Message 17 of 41

paullimapa
Mentor
Mentor

In my reply posting under message 12 of 15

Save the code for both Sample33.lsp and Sample33.dcl in one of the folders in AutoCAD support file search path and then at AutoCAD command prompt r:

(load”Sample33”)

Sample33


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 18 of 41

qkakkel
Contributor
Contributor
Thank you for your help.
Sorry but where can I find the message 12 of 15 , do you mean page 12 of 15 from your reply’s ?



0 Likes
Message 19 of 41

paullimapa
Mentor
Mentor

I mean the 12th reply which is my post reply to your OP. Try this link to go there directly 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/definition-could-not-be-loaded/m-p/1...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 20 of 41

qkakkel
Contributor
Contributor
Thanks for your help but I don’t know what is wrong with my pc but still not working!
Copied and paste your files saved them in a new directory , put them in Support File Search Path and in trusted locations .


Command: _appload sample33.lsp successfully loaded.
Command:
Command:
Command: sample33
Unknown command "SAMPLE33". Press F1 for help.
Command: (load"sample33")
nil
0 Likes