AutoLISP Startup Routine Debugging Help Request

AutoLISP Startup Routine Debugging Help Request

Anonymous
Not applicable
1,526 Views
11 Replies
Message 1 of 12

AutoLISP Startup Routine Debugging Help Request

Anonymous
Not applicable

I am setting up machines in my office with an ACADDOC.LSP AutoLISP Routine to load custom LISP routines to do the following on startup:

 

  1.  Initialize the drawing environment routine:

(command ".setvar" "expert" 1)

(command ".viewres" "y" "5000")

 (command ".color" "BYLAYER")

 (command ".linetype" "set" "BYLAYER")  

 

2.Redefine the Qsave command in “Stealth Mode” to automatically purge all blocks from the drawing every drawing session:

 

(command ".undefine" "QSAVE")

(defun c:qsave ()

 (setvar "cmdecho" 0)

 (command "-purge" "b" "*" "n")

  (command ".qsave")

  (setvar "cmdecho" 1)

  (princ)

 )

 

3.Undefine Qleader command with dialog box message to user to “Use Mleader Command!” to enforce CAD standards:

 

(command ".undefine" "QLEADER")

(defun C:QLEADER ()

  (command ".qleader")

  (alert "Use Mleader Command!")

   (princ)

 )

 

The problem is the custom LISP routines fail to load due code errors I can’t seem to figure out!

I get the following history message after startup:

 

Opening an AutoCAD 2007/LT 2007 format file.

Regenerating model.

 

.setvar expert 1 .viewres y 5000 .-color BYLAYER ; error: misplaced dot on input

 

AutoCAD menu utilities loaded..setvar expert 1 .viewres y 5000 .color BYLAYER .linetype set BYLAYER .undefine

Invalid option keyword.

; error: Function cancelled

*Cancel*

*Cancel*

 

I am new to writing AutoLISP routines. Can anyone please help me debug the above code?

I have attached .LISP files.

All help is greatly appreciated!

 

Corey Barge

0 Likes
Accepted solutions (1)
1,527 Views
11 Replies
Replies (11)
Message 2 of 12

pbejse
Mentor
Mentor

Not sure, but i think you're missing a "" at  (command ".linetype" "set" "BYLAYER" "")

 

Try setvar instead

 

(setvar 'CECOLOR "BYLAYER")
(setvar 'CELTYPE "BYLAYER")
0 Likes
Message 3 of 12

Ranjit_Singh
Advisor
Advisor
Accepted solution

Any command calls cannot be made reliably from acaddoc.lsp unless you use defun-q to define a startup function. As a result you get the error for undefine command. Also it's a good practice to add any AutoCAD environment settings to acad.lsp since you don't need to call the environment settings for every document. Typically acaddoc.lsp makes load calls only and not defines custom functions. If you start defining custom functions in acaddoc then your file we grow tremendously and maybe difficult to manage at some point.

I will add the following in acad.lsp

(setvar 'expert 1)
(setvar 'cecolor "bylayer")
(setvar 'celtype "bylayer")

The acaddoc should now call your lsp file (load "mylisps.lsp") which defines any custom functions. Make sure the mylisps.lsp file is added to a trusted location path. Or alternatively add the file location path to your trusted locations. I made mylisps.lsp with following

(command ".viewres" "y" "5000")
(command "._undefine" "QSAVE") (command "._undefine" "QLEADER") (defun c:qsave () (setvar "cmdecho" 0) (command "-purge" "b" "*" "n") (command "._qsave") (setvar "cmdecho" 1) (princ) ) (defun C:QLEADER () (command "._qleader") (alert "Use Mleader Command!") (princ) )

 Now when you open your AutoCAD application, acad.lsp will set all your environment settings and anytime you open a dwg file acaddoc will make your custom functions available in that document.acaddoc.gif

 

Message 4 of 12

pbejse
Mentor
Mentor

@Ranjit_Singh wrote:

Any command calls cannot be made reliably from acaddoc.lsp unless you .....

 

......will set all your environment settings and anytime you open a dwg file acaddoc will make 

 


Wow, Wish I posted a reply as thorough as you did. 🙂

 

BTW: What program do you use to generate the attached GIF ? That file format is just right to show what one meant without going through a lengthy discussion, normally i posts a video from Autodesk screencast.

 

0 Likes
Message 5 of 12

Ranjit_Singh
Advisor
Advisor

There are many free utilities out there. Just google "screen recording". We decided to invest a little in https://www.flashbackrecorder.com/fbhome/ since we have offshore offices and its a lot faster to explain them with screen recordings. Personal choice as well (I am a man of few words Smiley Wink)

0 Likes
Message 6 of 12

pbejse
Mentor
Mentor

@Ranjit_Singh wrote:

.... We decided to invest a little in https://www.flashbackrecorder.com/fbhome/ since we have offshore offices and its a lot faster to explain them with screen recordings. ...


Thank you, I will look into this.

 

Cheers 

 

pBe

0 Likes
Message 7 of 12

Anonymous
Not applicable

Ranjit.Singh,

Thanks!!! It Works Great just as I wanted!Smiley Very Happy

 

Coreymbarge

 

0 Likes
Message 8 of 12

Ranjit_Singh
Advisor
Advisor

HTH. You will also find this AutoCAD Knowledgebase article very helpful.

0 Likes
Message 9 of 12

Anonymous
Not applicable

How do you add the file location path to your trusted locations? Smiley Embarassed

 

Coreymbarge

0 Likes
Message 10 of 12

Ranjit_Singh
Advisor
Advisor

You can set it in your options dialog box. Type OPTIONS

trusted_locations.png

0 Likes
Message 11 of 12

Anonymous
Not applicable

Never mind. I found it in the "Options" "files tab.Smiley Happy

 

Coreymbarge

0 Likes
Message 12 of 12

Anonymous
Not applicable

Thanks for all the screen shots! They Really help!Smiley Wink

0 Likes