Lisp wont load into AutoCAD

Lisp wont load into AutoCAD

christian_paulsen98V29
Enthusiast Enthusiast
2,344 Views
15 Replies
Message 1 of 16

Lisp wont load into AutoCAD

christian_paulsen98V29
Enthusiast
Enthusiast

Hi everyone! I just made a similar post for a different lisp routine im working on. The other one error codes when putting in the command, this one errors out when even trying to load the lisp. Can anyone point out where i went wrong? I assume its like an extra bracket or something somewhere.

 

;;DEFINE PLOT FUNCTION

(defun lolplotfun ( / fullfilename)
    (command
      "-PLOT"
      "Yes"                                     ;; Detailed plot configuration? [Yes/No]
      "Model"                                   ;; Enter a layout name or [?]
      "Autodesk PDF.pc3"                        ;; Enter an output device name or [?]
      "ARCH expand D (36.00 x 24.00 Inches)"    ;; Enter paper size or [?]
      "Inches"                                  ;; Enter paper units [Inches/Millimeters]
      "Landscape"                               ;; Enter drawing orientation [Portrait/Landscape]
      "No"                                      ;; Plot upside down? [Yes/No]
      "View"                                    ;; Enter plot area [Display/Extents/Layout/View/Window]
      "MS"                                      ;; Enter view name <>
      "Fit"                                     ;; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit]
      "Center"                                  ;; Enter plot offset (x,y) or [Center]
      "Yes"                                     ;; Plot with plot styles? [Yes/No]
      "24x36.ctb"                               ;; Enter plot style table name or [?]
      "Yes"                                     ;; Plot with lineweights? [Yes/No]
      "As displayed"                            ;; Enter shade plot setting [As displayed/legacy Wireframe/legacy Hidden/Visual styles/Rendered]
      fullfilename                              ;; Enter file name <>
      "Yes"                                     ;; Save changes to page setup [Yes/No]?
      "Yes"                                     ;; Proceed with plot [Yes/No] <Y>:
    )
)

;;DEFINE FOLDER FUNCTION

(defun createlolfolder ( / str_path str_name str_lol_folder )
    (setq str_path (getvar 'DWGPREFIX)
          str_name (vl-string-right-trim ".dwg" (getvar 'DWGNAME))
          str_lol_folder (strcat str_path " - " str_name)
    )
    (if (not (vl-file-directory-p str_cnc_folder))
       (vl-mkdir str_lol_folder)
    )
    str_lol_folder
)

;;MAIN ROUTINE

(defun c:lolplot()	
	file_path (createlolfolder)
	dwg_name (vl-string-right-trim ".dwg" (getvar 'DWGNAME))
	(initget "PLAN ELEC DATA PROP RIG")
	file_name (setq keyword (getkword "[Plan/Elec/Data/Prop/Rig]: <Plan>"))
	(layerstate-restore file_name)
	(lolplotfun (strcat file_path "\\" dwg_name " - " filename)
)
0 Likes
Accepted solutions (1)
2,345 Views
15 Replies
Replies (15)
Message 2 of 16

Kent1Cooper
Consultant
Consultant

And the error is...?

 

It looks like you are trying to set values into variables without (setq) functions to do it with, at lines 43, 44, & 46, and are missing a closing right parenthesis on line 48.

 

And if I'm reading it right, line 3 should have fullfilename as an argument, before the slash.

 

(defun lolplotfun (fullfilename)

 

[No slash is needed if there are no localized variables to list after it.] 

Kent Cooper, AIA
0 Likes
Message 3 of 16

christian_paulsen98V29
Enthusiast
Enthusiast

This is copied straight off the command line.

 

Command: APPLOAD
LOL FULL PLOT LISP.lsp successfully loaded.
Command: ; error: malformed list on input

0 Likes
Message 4 of 16

Kent1Cooper
Consultant
Consultant

@christian_paulsen98V29 wrote:

....: ; error: malformed list on input


That usually means a parentheses problem.  See Message 2 again -- I added to it.

Kent Cooper, AIA
0 Likes
Message 5 of 16

paullimapa
Mentor
Mentor
Accepted solution

As @Kent1Cooper stated you are missing setq statements here:

(defun c:lolplot()	
(setq
	file_path (createlolfolder)
	dwg_name (vl-string-right-trim ".dwg" (getvar 'DWGNAME))
) ; setq
	(initget "PLAN ELEC DATA PROP RIG")
(setq
	file_name (setq keyword (getkword "[Plan/Elec/Data/Prop/Rig]: <Plan>"))
) ; setq
	(layerstate-restore file_name)
	(lolplotfun (strcat file_path "\\" dwg_name " - " filename)
)

 And then your loloplotfun has filename argument so no slash:

(defun lolplotfun ( fullfilename)

 


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

christian_paulsen98V29
Enthusiast
Enthusiast

Could i do the initget before the first setq? Then set the file_name variable using getkword? That way all the variables are being set in one single setq parenthesis? Or does it need to be in its own setq parenthesis?

 

Just trying to keep things as simple as possible. I think this way gets rid of like 3 or 4 lines. Not sure if it actually works though. See example below.

 

(defun c:lolplot()	
(initget "PLAN ELEC DATA PROP RIG")
(setq
	file_name (setq keyword (getkword "[Plan/Elec/Data/Prop/Rig]: <Plan>"))
	file_path (createlolfolder)
	dwg_name (vl-string-right-trim ".dwg" (getvar 'DWGNAME))
) ; setq
	(layerstate-restore file_name)
	(lolplotfun (strcat file_path "\\" dwg_name " - " filename)
)

 

0 Likes
Message 7 of 16

Kent1Cooper
Consultant
Consultant

Also, if you're going to offer a default value that someone can choose with Enter, you need to account for the possibility that they might do that:

    (setq file_name
      (cond
        ((getkword "[Plan/Elec/Data/Prop/Rig]: <Plan>"))
        ("Plan"); on Enter for listed default [returns nil above]
      ); cond
    ); setq

[You never use the 'keyword' variable.]

Kent Cooper, AIA
0 Likes
Message 8 of 16

christian_paulsen98V29
Enthusiast
Enthusiast

Yeah ive got that error before and like i said in the original post i figured it was some kind of extra bracket or a missing bracket. I can just never find out where the extra is or where one is missing. I looked through the code for like 10 minutes and didnt see the mistake.

 

How do you find where the malfunction is? I do all my coding in the notes app and theres no real way to format things or check for errors. I cant find a good code checker tool online. Sometimes i feel bad putting such simple stuff in the forums.

0 Likes
Message 9 of 16

Kent1Cooper
Consultant
Consultant

@christian_paulsen98V29 wrote:

Could i do the initget before the first setq? Then set the file_name variable using getkword? That way all the variables are being set in one single setq parenthesis? ....

....
	(lolplotfun (strcat file_path "\\" dwg_name " - " filename)
....

Yes to the question.  And you're still missing the closing right parenthesis for that line of code.

Kent Cooper, AIA
0 Likes
Message 10 of 16

paullimapa
Mentor
Mentor

use a coder like the one recommended by Autodesk & install the matching bracket extensions to help you locate errors like this.

paullimapa_0-1716575885847.png

 


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

Kent1Cooper
Consultant
Consultant

@christian_paulsen98V29 wrote:

....

How do you find where the malfunction is? I do all my coding in the notes app and theres no real way to format things or check for errors. I cant find a good code checker tool online. Sometimes i feel bad putting such simple stuff in the forums.


I just looked for things to catch my eye.  For a more formal approach, investigate the VLIDE command.  Others are better at it than I, but it's the diagnostic tool for this kind of thing.

Kent Cooper, AIA
0 Likes
Message 12 of 16

paullimapa
Mentor
Mentor

and here's using another vl function so you don't have to repeat the same initget & getkword options:

(defun c:lolplot(/ dwg_name file_name file_path msg)	
 (vl-load-com)
 (initget (setq msg "PLAN ELEC DATA PROP RIG"))
 (setq
  file_name (getkword (strcat "[" (vl-string-translate " " "/" msg)"] <PLAN>:"))
  file_path (createlolfolder)
  dwg_name (vl-string-right-trim ".dwg" (getvar 'DWGNAME))
 ) ; setq
 (if(not file_name)(setq file_name "PLAN"))
 (layerstate-restore file_name)
 (lolplotfun (strcat file_path "\\" dwg_name " - " filename))
) ; defun

 


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

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:
....
 (initget (setq msg "PLAN ELEC DATA PROP RIG"))
 (setq
  file_name (getkword (strcat "[" (vl-string-translate " " "/" msg)"] <PLAN>:"))
....

With two options starting with P, I would do the initial-capitals approach the way all AutoCAD commands with options are built [whether you construct it as above or just spell it all out, which is actually shorter in this case]:

 

....
  (initget "Plan Elec Data PRop Rig")
  (setq
    file_name
      (cond
        ((getkword "[Plan/Elec/Data/PRop/Rig]: <Plan>"))
        ("Plan"); on Enter for listed default [returns nil above]
      ); cond
....

 

That way, if you choose to type an option [rather than accept the default or pick one at the prompt line], you can type just P to get Plan [apparently expected to be the more common option], and PR for PRop, whereas with the all-capitals approach if you type just P it will ask you whether you meant PLAN or PROP.

Kent Cooper, AIA
Message 14 of 16

paullimapa
Mentor
Mentor

and with Dynmode set to 1 or 3 you'll get the popup menu selection when the cursor moves into the drawing area:

paullimapa_0-1716579763867.png

 


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

christian_paulsen98V29
Enthusiast
Enthusiast

Got kinda busy and had some work to do. Just looked at your guys notes, made some changes, simplified a few things. It worked but then i didnt like the way the folders were being named so i tried to change that and now autocad crashes everytime i try to use the command. Any ideas?

Updated code below.

 

;;DEFINE PLOT FUNCTION
(defun plotfunc (fullfilename)
    (command
      "-PLOT"
      "Yes"                                     ;; Detailed plot configuration? [Yes/No]
      "Model"                                   ;; Enter a layout name or [?]
      "Autodesk PDF.pc3"                        ;; Enter an output device name or [?]
      "ARCH expand D (36.00 x 24.00 Inches)"    ;; Enter paper size or [?]
      "Inches"                                  ;; Enter paper units [Inches/Millimeters]
      "Landscape"                               ;; Enter drawing orientation [Portrait/Landscape]
      "No"                                      ;; Plot upside down? [Yes/No]
      "View"                                    ;; Enter plot area [Display/Extents/Layout/View/Window]
      "MS"                                      ;; Enter view name <>
      "Fit"                                     ;; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit]
      "Center"                                  ;; Enter plot offset (x,y) or [Center]
      "Yes"                                     ;; Plot with plot styles? [Yes/No]
      "24x36.ctb"                               ;; Enter plot style table name or [?]
      "Yes"                                     ;; Plot with lineweights? [Yes/No]
      "As displayed"                            ;; Enter shade plot setting [As displayed/legacy Wireframe/legacy Hidden/Visual styles/Rendered]
      fullfilename                              ;; Enter file name <>
      "Yes"                                     ;; Save changes to page setup [Yes/No]?
      "Yes"                                     ;; Proceed with plot [Yes/No] <Y>:
    )
)

;;DEFINE FOLDER FUNCTION
(defun createfolder ( / foldername )
    (setq foldername (strcat (getvar 'DWGPREFIX) "\\PDF"))
    (if (not (vl-file-directory-p foldername))
       (vl-mkdir foldername)
    )
    foldername
)

;;MAIN ROUTINE
(defun c:qplot()	
	(initget "PLAN ELEC DATA LOCA RIG")
	(setq
	state (getkword "[Plan/Elec/Data/Loca/Rig]: <Plan>")
	file_path (createfolder)
	file_name (vl-string-right-trim ".dwg" (getvar 'DWGNAME))
	)
	(layerstate-restore state viewportId 4)
	(command "regen")
	(plotfunc (strcat file_path "\\" file_name " - " state))
)
0 Likes
Message 16 of 16

Took out the "\\" before PDF when creating the folders. Works perfect now! Thank you everyone for your input.

0 Likes