Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"AutoCAD rejected variable" error message

679 views
Skip to first unread message

Jason Piercey

unread,
Mar 1, 2003, 9:53:31 AM3/1/03
to
Are you using any error handlers in your routines? Could be
that a leftover error handlers causing the problem.

--

-Jason
Member of the Autodesk Discussion Forum Moderator Program


"pashley" <paul....@mcd.com> wrote in message
news:f1491...@WebX.maYIadrTaRb...
> I am not aware of that causes this?


Paul Turvill

unread,
Mar 1, 2003, 11:48:06 AM3/1/03
to
What triggers the error is usually an error in the code that attempting to
change the system variable. For example, some sysvars expect strings, others
reals, and yet others integers. Some are confusing to inexperienced
code-cutters, for example, setting CLAYER to Layer 0: most sysvars that
accept 0 as a setting want it as an integer, but CLAYER expects a string --
"0". Others may trigger an error if, for example, an integer value is
specified that lies outside the normal range, like 2 for BLIPMODE, for
example. Visual LISP is a bit less tolerant than previous versions of
AutoLISP, and has more internal error checking, so it finds errors in some
code that slipped by in earlier versions.

You'll need to examine your code for such errors. Often it will be an
improper setting of a symbol that is used in a (setvar ...) function, i.e.,

(setq MyLayer 0)
(setvar "clayer" Mylayer)

will fail, because Mylayer is an integer rather than a string.
___

"pashley" <paul....@mcd.com> wrote in message

news:f149...@WebX.maYIadrTaRb...
> No, I'm not using error handlers - that's an area I've never really
understood. I don't have access to any of my routines right now but, for
example, one just loads a lisp file that does nothing but sets dimension
variables. In that routine, unless I used the command version instead of
setvar, I repeatedly got error meassages. Since AutoCAD sends the error
message, I would think that someone there would know what in there program
triggers sending it.


Chip Harper

unread,
Mar 1, 2003, 12:06:33 PM3/1/03
to
I ran into a similar issue awhile back with my system variable settings
lisp. There was one setting that I could not control with a setvar. Here's
the snip from the end ...

(setvar "XREFCTL" 0)
(setvar "ZOOMFACTOR" 70)
(command "DBLCLKEDIT" "on") ; will not accept
input as setvar

You might be trying to setvar a non-system variable item?

--

Chip Harper

Doug Broad

unread,
Mar 2, 2003, 3:14:17 PM3/2/03
to
Gordon,
See my answer to your other thread.

The main problem between VBA and VLISP is a botched implementation
by AutoDesk. This should never have been a problem. As a workaround
don't ever use setvar in your lisp functions. Use vla-setvariable instead.

BTW,
Your mtext command could simpler. There is no need to
define a text style each time you start your mtext command.
1. Use templates that already contain the styles or
2. Write a function that does it only when the style doesn't already
exist.

For those who use VBA and/or reactors, we may have to re-write
a lot of code to avoid the setvar or redefine the built in function
setvar. This could be done by unprotecting the setvar function
and then rewriting it per Active-X. Don't have time to demonstrate
now but this is something I am thinking about doing for my
own systems.

Good luck.

"Gordon Price" <gordon-price(ditch this)@attbi.com> wrote in message
news:1700ED0829E262A3...@in.WebX.maYIadrTaRb...

>Doug, how do you release an object in VBA, or deal with the mixed methods issue? I have a VBA tool that >manages DimScale &
LTScale as you switch between PS & MS, and a Lsip tool that sets layer & text style, >then does Mtext, then attempts to set
layer & style back, but I get an error on that last bit due to the mixing >methods deal. I prefer VBA for the events and ease
of accessing dictionaries, and Lisp for the mtext because it >is easy to make a command. Trying to do both in one or the
other is less pleasant.

Best,
Gordon


Gordon Price

unread,
Mar 2, 2003, 4:20:53 PM3/2/03
to

"Doug Broad" <dbr...@earthlink.net> wrote in message
news:C8A8133A39224E15...@in.WebX.maYIadrTaRb...

> The main problem between VBA and VLISP is a botched implementation
> by AutoDesk. This should never have been a problem. As a workaround
> don't ever use setvar in your lisp functions. Use vla-setvariable
instead.
And DrawOrder should work across Xrefs, and text should acnkowledge
DimScale, and...
I have decided that the primary indicator of an AutoCAD power user is how
many workarounds they know ;)

> Your mtext command could simpler. There is no need to
> define a text style each time you start your mtext command.
> 1. Use templates that already contain the styles or

We have templates, but I also want to deal with the fact that people will
open drawings that are not to standard (old drawings with old standards,
drawings from elsewhere, drawings started "from scratch", etc). I am dealing
with that as a training issue, but I want to make sure the tools mitigate
whatever possible. I am also using it as a way to promote ADT also (Hey, you
like that, ADT does it with EVERYTHING. You just have to take time to learn
it")

> 2. Write a function that does it only when the style doesn't already
> exist.

My actual code does just that. As I was testing to find where my error was
coming from, I stripped the code down to a minimum that still caused the
problem. Helps me to figure things out, and I find people are more likely to
have an answer here if I post just the minimum code to define the problem.

Given that I am starting all this code from scratch, as the office had
almost nothing automated when I arrived, I think I can just use the VLA
stuff as I go along. Forces me to learn VLisp too.

Thanks,
Gordon


Doug Broad

unread,
Mar 2, 2003, 4:48:14 PM3/2/03
to
Hello All,
For those without the time or inclination to work around Autodesk
created problems, try the attached:

Load the file with acaddoc.lsp or appload. This should eliminate
some of the need to re-write all your functions that use setvar.

Tony T. and all. Please be very critical of the attached file if you
see any major problems. I haven't thoroughly tested it. I appreciate
all comments.

Regards,
Doug

setvar.lsp

John Uhden

unread,
Mar 2, 2003, 9:31:26 PM3/2/03
to
Doug:

A very worthy effort. But if Pragma doesn't exist, then why bother with R14?

How about just ?...
(defun setvar (var val / doc)
(if
(and
(= (type vl-load-com) 'SUBR)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(not
(vl-catch-all-error-p
(vl-catch-all-apply
'vlax-invoke (list doc 'Setvariable var val)
)
)
)
)
val
)
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message

news:9DF13444ECFAF421...@in.WebX.maYIadrTaRb...


--------------------------------------------------------------------------------


;|This file is an attempt to workaround problems
caused by the old version of setvar when used
with reactors active or when vba functions are
used in combination with lisp or in a mixed
VLISP/Legacy LISP environment. Use at your
own risk. May be freely distributed.
Retain authorship notice!
Please post any problems found to
autodesk.autocad.customization or to
dbr...@earthlink.net
D. C. Broad, Jr. 3/2/03
|;

;;Allows setvar and other functions in this file to be re-defined.
(pragma '((unprotect-assign setvar legacyAcad db:Undo-Group db:Undo-End)))


;;Critical Version check - could be improved
;;Vlisp was available as an extra on R14.
(defun legacyAcad () (< (getvar "acadver") "15"))

;;Undo control for acad - Inspired by John Uhden.
;;Replace all instances of undo group and undo end
;;with db:undo-group and db:undo-end
(cond ((legacyAcad)
(defun db:undo-group ()
(command "_.undo" "_end" "_.undo" "_group"))
(defun db:undo-end () (command "_.undo" "_end")))
(t
(vl-load-com)
(defun db:undo-group ()
(vla-endundomark (activedoc))
(vla-startundomark (activedoc)))
(defun db:undo-end () (vla-endundomark (activedoc)))))

;;D.C. Broad, Jr.
;;Workaround for setvar problems.
(cond ((not (legacyAcad))
(defun setvar (var val)
(vla-setvariable
(vla-get-activedocument (vlax-get-acad-object))
var
(cond ((= (type val) 'list)
;;Fragment inspired by Tony T.
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray
'(0 . (1- (length val)))
;;Sys vars are 2 or 3 long
;;Only setvar lists are lists of reals.
vlax-vbdouble)
val)))
(t val))))
))

;;protects the critical symbols defined in this file
(pragma '((protect-assign setvar db:undo-group db:undo-end legacyAcad)))

;;load quietly
(princ)

John Uhden

unread,
Mar 2, 2003, 10:36:36 PM3/2/03
to
You mean it won't load in original 2000 (R15.0)? You mean I have to go
upstairs, crank up the PII-266 and try it out?

Command: (setvar "asdf" "ghjk")
nil

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message

news:A55AC6294963A08F...@in.WebX.maYIadrTaRb...
> Good point John. Hadn't thought to check to see if pragma was
> available in R14. Your version however won't load in R2000 without
> the pragma and (for my taste) you have too much error checking.
> Let's say for instance that you feed this to setvar
> (setvar "asdf" "ghjk")
> What's it going to do? Report the error and halt.
>
> Here's my reply offering:
> ;;-----------------------setvar.lsp for 2000+-----------------------
> (pragma '((unprotect-assign setvar)))
>
> ;;ensure active-x functions
> (vl-load-com)
>
> ;;Redefined setvar for Acad 2000+
> ;;D. C. Broad - Substitute for setvar in Acad 2000+
> ;;with John Uhden's vlax-invoke style
> (defun setvar (var val)
> (vlax-invoke
> (vla-get-activedocument
> (vlax-get-acad-object)) 'setvariable var val)
> val)
>
>
> (pragma '((protect-assign setvar)))
>
> ;-----------------end setvar.lsp for 2000+ ----------------------
>
>
> It could be loaded with
> (or (< (getvar "acadver" "15") (load "setvar"))
>
> There's that undocumented vlax-invoke outdoing the vlax-invoke-method
> and vla-.... again.
>
> Thanks John.
> Regards,
> Doug
>
>
>
> "John Uhden" <juh...@cadlantic.com> wrote in message
news:0F2DD20188D070D3...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Mar 2, 2003, 10:18:47 PM3/2/03
to

;;ensure active-x functions
(vl-load-com)


(pragma '((protect-assign setvar)))

Thanks John.
Regards,
Doug

Doug Broad

unread,
Mar 2, 2003, 10:56:26 PM3/2/03
to
Go upstairs John.
This is what happens in ADT3.3 / Acad 2002 with built in setvar:

Command: (setvar "asdf" "asdf")
LISP ERROR: AutoCAD variable setting rejected: "asdf" "asdf"

That's without VBA, ACAD.LSP, or ACADDOC.lsp or ADT loaded.

I can't test in R15.0 Didn't R15.0 have pragma? R15.06
causes load problems without pragma (if vlide is active). If vlide
has not been activated, then your version will work.

"John Uhden" <juh...@cadlantic.com> wrote in message news:8EB5F39ED80AB316...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Mar 2, 2003, 11:16:26 PM3/2/03
to
I get it. The difference is that I'm writing in TextPad, then Copy/Pasting to
AutoCAD (I use VLIDE only for packaging).
So... don't get so PRAGMAtic. <g>.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message

news:2A691CBEDE631842...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Mar 2, 2003, 11:24:32 PM3/2/03
to
ZZzzzzzz....hmmmm...snort..oh
So I got ya on one huh? At least we've given those with
setvar woes a viable alternative without re-writing all their
old code.
Have a great good night.

"John Uhden" <juh...@cadlantic.com> wrote in message news:1D25923157B9FF97...@in.WebX.maYIadrTaRb...

Luis E.

unread,
Mar 3, 2003, 11:41:04 AM3/3/03
to
As for what I have learned in this long trip creating new intelligent or
smart routines or what ever, I'm still using setvar or mixing autolisp/vlisp
functions.

The only ones I don't use anymore are entmake or command.

Regards,
Luis

btw: I wrote a new command to control the ltscale, psltscale, textstyle,
dimstyle, dimscale, etc, using pure visual lisp/activex and works just fine.


Doug Broad

unread,
Mar 3, 2003, 12:04:28 PM3/3/03
to
Hi Luis,
I don't think the reactors are the problem (as long as they are written
within the reactor guidelines, which emphasize that you should use
activex). The problem comes with all the routines that use the
legacy setvar while reactors (especially command_ended) reactor.

A lot of people (myself included) have a large library of routines
that worked fine in R14 and should have worked fine in R2000
and through no fault of our own, they don't. The bugs surface
slowly and in conditions that could not have been anticipated when
the programs were originally written.

I too have that type of reactor (although reactive text and dimension
styles might be a little too bossy for my style). They work fine
but other programs choke while they are enabled.

Regards,
Doug


"Luis E." <supportATcaddximationDOTcom> wrote in message
news:2E6975309F6346CB...@in.WebX.maYIadrTaRb...

Luis E.

unread,
Mar 3, 2003, 1:03:11 PM3/3/03
to
Doug,

I was not referring to just routines with reactors.

;-)


0 new messages