Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error Message "Lisp Prgram" (error: bad function: 0)

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
2521 Views, 7 Replies

Error Message "Lisp Prgram" (error: bad function: 0)

Hey,

Its been a long day,.. the below Lisp Code. produces what I want.. more or less.

First if statement is good
if SETSTD doesn't exist it ask me to Run SETSTD

When I run it.. and SETSTD has been loaded....
I get the following error --->...STDM-50 loaded; error: bad function: 0

@@@@@@

(defun c:M50 ()
(if (= (tblsearch "DIMSTYLE" "STDM") nil)
(PRINC "\n...Please Run SETSTD")
(
(setvar "cmdecho" 0)
(command "filedia" "0")

(command "setvar" "dimscale" 50)
(command "setvar" "dimassoc" 1)
(command "setvar" "dimasz" 5.0)
(command "setvar" "dimcen" 2.2)
(command "setvar" "dimexo" 1.5)
(command "setvar" "dimdli" 9.5)
(command "dim" "dimclrt" "green" "exit")
(command "setvar" "dimexe" 1.5)
(command "setvar" "dimtp" 0.0000)
(command "setvar" "dimtm" 0.0000)
(command "setvar" "dimtxt" 3.0)
(command "setvar" "dimtsz" 0.0000)
(command "setvar" "dimdle" 0.0000)
(command "setvar" "dimtol" 0)
(command "setvar" "dimlim" 0)
(command "setvar" "dimtih" 0)
(command "setvar" "dimtoh" 0)
(command "setvar" "dimse1" 0)
(command "setvar" "dimse2" 0)
(command "setvar" "dimtad" 1)
(command "setvar" "dimtix" 0)
(command "setvar" "dimtofl" 1)
(command "setvar" "dimalt" 0)
(command "setvar" "dimaltf" 0.039370)
(command "setvar" "dimaltd" 4)
(command "setvar" "dimlfac" 1.0)
(command "setvar" "dimclrd" 256)
(command "setvar" "dimclre" 256)
(command "setvar" "dimlwd" -2)
(command "setvar" "dimlwe" -2)
(command "setvar" "dimatfit" 3)
(command "setvar" "dimtmove" 0)
(command "setvar" "dimfrac" 1)
(command "setvar" "dimaltu" 4)
(command "setvar" "dimtfac" 0.6500)
(command "setvar" "dimsho" 1)
(command "setvar" "psltscale" 1)
(command "regenauto" "off")

(command "style" "TITLE50" "ROMANS" 250 0.80 0.00 "n" "n" "n")
(command "style" "MINI50" "ROMANS" 100 0.80 0.00 "n" "n" "n")
(command "style" "STD50" "ROMANS" 150 0.80 0.00 "n" "n" "n")

(command "setvar" "dimgap" 1.5) ;;;dist between txt and dim line
(command "setvar" "dimtxsty" "STD50") ;;;dim txt style
(command "setvar" "dimaunit" 1) ;;;angular unit
(command "setvar" "dimdec" 0) ;;;# of decimal places allows min&sec for angles
(command "setvar" "dimadec" 4)
(command "setvar" "dimunit" 2) ;;;linear units
(command "setvar" "dimzin" 3) ;;;suppress trailing zeros
(command "setvar" "dimrnd" 0.0000)



(if (= (tblsearch "DIMSTYLE" "STDM-50") nil)
(command "dim" "save" "STDM-50" "exit")
(command "dim" "save" "STDM-50" "y" "exit"))

(command "filedia" 1)
(princ"\n...STDM-50 loaded")
(GRAPHSCR)
(princ)
)
)
(princ)
)

@@@@@@
Any help would be helpful
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

Where you have your open parenthesis at the start of the if statement, put a
progn right after it, so it will look like
"(progn " It seemed to work on my computer after I did that.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5254024@discussion.autodesk.com...
Hey,

Its been a long day,.. the below Lisp Code. produces what I want.. more or
less.

First if statement is good
if SETSTD doesn't exist it ask me to Run SETSTD

When I run it.. and SETSTD has been loaded....
I get the following error --->...STDM-50 loaded; error: bad function: 0

@@@@@@

(defun c:M50 ()
(if (= (tblsearch "DIMSTYLE" "STDM") nil)
(PRINC "\n...Please Run SETSTD")
(
(setvar "cmdecho" 0)
(command "filedia" "0")

(command "setvar" "dimscale" 50)
(command "setvar" "dimassoc" 1)
(command "setvar" "dimasz" 5.0)
(command "setvar" "dimcen" 2.2)
(command "setvar" "dimexo" 1.5)
(command "setvar" "dimdli" 9.5)
(command "dim" "dimclrt" "green" "exit")
(command "setvar" "dimexe" 1.5)
(command "setvar" "dimtp" 0.0000)
(command "setvar" "dimtm" 0.0000)
(command "setvar" "dimtxt" 3.0)
(command "setvar" "dimtsz" 0.0000)
(command "setvar" "dimdle" 0.0000)
(command "setvar" "dimtol" 0)
(command "setvar" "dimlim" 0)
(command "setvar" "dimtih" 0)
(command "setvar" "dimtoh" 0)
(command "setvar" "dimse1" 0)
(command "setvar" "dimse2" 0)
(command "setvar" "dimtad" 1)
(command "setvar" "dimtix" 0)
(command "setvar" "dimtofl" 1)
(command "setvar" "dimalt" 0)
(command "setvar" "dimaltf" 0.039370)
(command "setvar" "dimaltd" 4)
(command "setvar" "dimlfac" 1.0)
(command "setvar" "dimclrd" 256)
(command "setvar" "dimclre" 256)
(command "setvar" "dimlwd" -2)
(command "setvar" "dimlwe" -2)
(command "setvar" "dimatfit" 3)
(command "setvar" "dimtmove" 0)
(command "setvar" "dimfrac" 1)
(command "setvar" "dimaltu" 4)
(command "setvar" "dimtfac" 0.6500)
(command "setvar" "dimsho" 1)
(command "setvar" "psltscale" 1)
(command "regenauto" "off")

(command "style" "TITLE50" "ROMANS" 250 0.80 0.00 "n" "n" "n")
(command "style" "MINI50" "ROMANS" 100 0.80 0.00 "n" "n" "n")
(command "style" "STD50" "ROMANS" 150 0.80 0.00 "n" "n" "n")

(command "setvar" "dimgap" 1.5) ;;;dist between txt and dim line
(command "setvar" "dimtxsty" "STD50") ;;;dim txt style
(command "setvar" "dimaunit" 1) ;;;angular unit
(command "setvar" "dimdec" 0) ;;;# of decimal places allows min&sec for
angles
(command "setvar" "dimadec" 4)
(command "setvar" "dimunit" 2) ;;;linear units
(command "setvar" "dimzin" 3) ;;;suppress trailing zeros
(command "setvar" "dimrnd" 0.0000)



(if (= (tblsearch "DIMSTYLE" "STDM-50") nil)
(command "dim" "save" "STDM-50" "exit")
(command "dim" "save" "STDM-50" "y" "exit"))

(command "filedia" 1)
(princ"\n...STDM-50 loaded")
(GRAPHSCR)
(princ)
)
)
(princ)
)

@@@@@@
Any help would be helpful
Message 3 of 8
Anonymous
in reply to: Anonymous

What are you doing this for in multiple drawings? It should be done ONCE
and saved as a template as the basis for new files.

--
George Drayton CD-CAD Ltd New Zealand
"T.Willey" wrote in message
news:5254039@discussion.autodesk.com...
Where you have your open parenthesis at the start of the if statement, put a
progn right after it, so it will look like
"(progn " It seemed to work on my computer after I did that.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5254024@discussion.autodesk.com...
Hey,

Its been a long day,.. the below Lisp Code. produces what I want.. more or
less.

First if statement is good
if SETSTD doesn't exist it ask me to Run SETSTD

When I run it.. and SETSTD has been loaded....
I get the following error --->...STDM-50 loaded; error: bad function: 0

@@@@@@

(defun c:M50 ()
(if (= (tblsearch "DIMSTYLE" "STDM") nil)
(PRINC "\n...Please Run SETSTD")
(
(setvar "cmdecho" 0)
(command "filedia" "0")

(command "setvar" "dimscale" 50)
(command "setvar" "dimassoc" 1)
(command "setvar" "dimasz" 5.0)
(command "setvar" "dimcen" 2.2)
(command "setvar" "dimexo" 1.5)
(command "setvar" "dimdli" 9.5)
(command "dim" "dimclrt" "green" "exit")
(command "setvar" "dimexe" 1.5)
(command "setvar" "dimtp" 0.0000)
(command "setvar" "dimtm" 0.0000)
(command "setvar" "dimtxt" 3.0)
(command "setvar" "dimtsz" 0.0000)
(command "setvar" "dimdle" 0.0000)
(command "setvar" "dimtol" 0)
(command "setvar" "dimlim" 0)
(command "setvar" "dimtih" 0)
(command "setvar" "dimtoh" 0)
(command "setvar" "dimse1" 0)
(command "setvar" "dimse2" 0)
(command "setvar" "dimtad" 1)
(command "setvar" "dimtix" 0)
(command "setvar" "dimtofl" 1)
(command "setvar" "dimalt" 0)
(command "setvar" "dimaltf" 0.039370)
(command "setvar" "dimaltd" 4)
(command "setvar" "dimlfac" 1.0)
(command "setvar" "dimclrd" 256)
(command "setvar" "dimclre" 256)
(command "setvar" "dimlwd" -2)
(command "setvar" "dimlwe" -2)
(command "setvar" "dimatfit" 3)
(command "setvar" "dimtmove" 0)
(command "setvar" "dimfrac" 1)
(command "setvar" "dimaltu" 4)
(command "setvar" "dimtfac" 0.6500)
(command "setvar" "dimsho" 1)
(command "setvar" "psltscale" 1)
(command "regenauto" "off")

(command "style" "TITLE50" "ROMANS" 250 0.80 0.00 "n" "n" "n")
(command "style" "MINI50" "ROMANS" 100 0.80 0.00 "n" "n" "n")
(command "style" "STD50" "ROMANS" 150 0.80 0.00 "n" "n" "n")

(command "setvar" "dimgap" 1.5) ;;;dist between txt and dim line
(command "setvar" "dimtxsty" "STD50") ;;;dim txt style
(command "setvar" "dimaunit" 1) ;;;angular unit
(command "setvar" "dimdec" 0) ;;;# of decimal places allows min&sec for
angles
(command "setvar" "dimadec" 4)
(command "setvar" "dimunit" 2) ;;;linear units
(command "setvar" "dimzin" 3) ;;;suppress trailing zeros
(command "setvar" "dimrnd" 0.0000)



(if (= (tblsearch "DIMSTYLE" "STDM-50") nil)
(command "dim" "save" "STDM-50" "exit")
(command "dim" "save" "STDM-50" "y" "exit"))

(command "filedia" 1)
(princ"\n...STDM-50 loaded")
(GRAPHSCR)
(princ)
)
)
(princ)
)

@@@@@@
Any help would be helpful
Message 4 of 8
Anonymous
in reply to: Anonymous

for those that upper comments have not solved their problem.
look for extra "()" in your code like "((your code block))" and remove it to be like "(your code)"
And "0" is the result of the first line after if that do not relate to the problem
Message 5 of 8
Kent1Cooper
in reply to: Anonymous


chacamasur wrote:
....
I get the following error --->...STDM-50 loaded; error: bad function: 0

....

(if (= (tblsearch "DIMSTYLE" "STDM") nil)
(PRINC "\n...Please Run SETSTD")
(
(setvar "cmdecho" 0)
....


I think you may just need to change that left parenthesis that's on a line by itself to a right parenthesis -- it appears to be the closing parenthesis for the (if) function above it.  Since it's a left [opening] parenthesis instead, it's being taken as the beginning of the 'else' arguement for that (if) function, and what tfollows is setting CMDECHO to 0, which returns 0, and that is where I think the "bad function: 0" message is coming from.

Kent Cooper, AIA
Message 6 of 8
Anonymous
in reply to: Kent1Cooper

Sounds like parentheses problems are a common cause of this error.

 

This was also my issue just now; I just figured out (after staring at the same code for 2 hours) that my issue was I'd defined a function like so:

(defun  boundary_annulus( InnerDiam OuterDiam TempLayerName OutputLayerName )

    (setq layername OutputLayerName )
    (setq templayername TempLayerName )

......

);defun

 

And as soon as I added a space after the function name (before the parenthesis for the arguments), the cryptic & useless error message vanished.  AutoLisp debugging output and error message readability leaves a lot to be desired...

 

Message 7 of 8
john.uhden
in reply to: Anonymous

Good catch.

 

Symbol names can consist of most any characters (except spaces).

 

(defun  boundary_annulus(

is trying to define a function named "boundary_annulus(" with the parenthesis as the last character, thus screwing up everything that follows.

 

Though you can't defun a protected symbol, as in (defun defun ( ...))

But you can (setq define defun).

 

Decades ago we had a competition to write a function to draw a Christmas tree in the the fewest number of characters.  I think I won because mine was the best tree but lost because I had too many characters, even after I (setq s setq a append c cons l list r repeat w while) etc.

John F. Uhden

Message 8 of 8

 

Another thing not allowed in symbol names in AutoLISP is a period.

 

- This has a rather dangerous behaviour, which I consider a bug:

 

_$ (setq aa 'b.c)
B
_$ aa
B

 

_$ (print.qwertyuio 'asdfghjqwertyui.23456789)

ASDFGHJQWERTYUI ASDFGHJQWERTYUI

 

 

So, AutoLISP just stops reading at the period, ignoring the rest, with no warning. This will create very nice aliasing bugs in the program.

 

In other Lisp implementations this is quite acceptable:

 

Common Lisp:

 

CLO 4 > (setq aa 'b.c)
B.C

 

Emacs Lisp:

 

(setq aa 'b.c)
b\.c

 

 

-- 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost