TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: BudRPerry on January 25, 2016, 11:17:40 AM

Title: Can't get defun to work....
Post by: BudRPerry on January 25, 2016, 11:17:40 AM
This is just the very first couple of lines for a routine I'm trying to write.  If I type the second and third line into autocad at the command prompt they run just fine, but as soon as I try to put them into a routine it returns:
; error: bad argument type: (or stringp symbolp): nil
If I can't even get past this part there's no hope for the rest...

Code: [Select]
(defun c:AUTOLAYERFT2 ()
  (setvar “ctab” “BV”)
  (command “_MSpace”)
)
Title: Re: Can't get defun to work....
Post by: Mark on January 25, 2016, 11:57:19 AM
Try this
(setvar 'ctab "BV")
don't double quote ctab.
Title: Re: Can't get defun to work....
Post by: rkmcswain on January 25, 2016, 11:59:52 AM
Do your editing in the VLIDE or Notepad (or some variant of Notepad). IOW, an ASCII file editor.
Your "QUOTE" marks are not ASCII character 34, they are the "curly" quotes, characters 8220 and 8221

Code: [Select]
(defun c:AUTOLAYERFT2 ()
  (setvar "ctab" "BV")
  (command "_MSpace")
)




Here is your code, copy and pasted into the VLIDE



Title: Re: Can't get defun to work....
Post by: David Bethel on January 25, 2016, 01:14:58 PM
I wonder why the forum displays them as more or less standard quotes ?

NotePad ++


HHmmmm 
Title: Re: Can't get defun to work....
Post by: BudRPerry on January 25, 2016, 01:18:25 PM
Wow, that was it!  I had originally typed it all in Word and just copied it to notepad...it kept the original "curly" quotes!  As soon as I retyped the quotes in notepad the routine works!  I was pulling my hair out!

Thank You Very Much for the Replies!
Title: Re: Can't get defun to work....
Post by: Lee Mac on January 25, 2016, 01:19:39 PM
If you are just starting out with AutoLISP, I would strongly suggest writing your code using the Visual LISP IDE (VLIDE) - here are some resources to get you started:

The Visual LISP Editor - Part 1 (http://bit.ly/19BXiVs)
The Visual LISP Editor - Part 2 (http://bit.ly/16nDctv)
An Introduction to the Visual LISP IDE (http://bit.ly/13LA7J9)
Retrieving Information About a Function (http://bit.ly/154UMJh)
A Shortcut to Localising Variables (http://bit.ly/14pdIQh)
Debugging Code with the Visual LISP IDE (http://bit.ly/1ebl2jl)
Title: Re: Can't get defun to work....
Post by: squirreldip on January 25, 2016, 02:48:55 PM
+1

Another good editor is Notepad++ (https://notepad-plus-plus.org/)
Title: Re: Can't get defun to work....
Post by: rkmcswain on January 26, 2016, 07:50:30 AM
I see a lot of people push Notepad ++

Does it integrate into AutoCAD like the VLIDE?
If not, then what is the advantage? (for coding autolisp)

Thanks.

Title: Re: Can't get defun to work....
Post by: ChrisCarlson on January 26, 2016, 07:59:57 AM
It does not incorporate well like VLIDE, however to my knowledge nothing else does either. I use Notepad++ as VLIDE just seems way too clunky.
Title: Re: Can't get defun to work....
Post by: squirreldip on January 27, 2016, 02:55:12 PM
Agree...

Notepad++ integrates into your right-click which is handy and it highlights matching parentheses.
Title: Re: Can't get defun to work....
Post by: rkmcswain on January 27, 2016, 03:06:36 PM
I got started using VLIDE in 1999 and have never looked back.
For each his own :)
Title: Re: Can't get defun to work....
Post by: MeasureUp on January 28, 2016, 01:04:23 AM
One of the reasons I like NotePad++ is its portable version. I can write codes anywhere.