Author Topic: Can't get defun to work....  (Read 2113 times)

0 Members and 1 Guest are viewing this topic.

BudRPerry

  • Guest
Can't get defun to work....
« 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”)
)

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: Can't get defun to work....
« Reply #1 on: January 25, 2016, 11:57:19 AM »
Try this
(setvar 'ctab "BV")
don't double quote ctab.
TheSwamp.org  (serving the CAD community since 2003)

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Can't get defun to work....
« Reply #2 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




David Bethel

  • Swamp Rat
  • Posts: 656
Re: Can't get defun to work....
« Reply #3 on: January 25, 2016, 01:14:58 PM »
I wonder why the forum displays them as more or less standard quotes ?

NotePad ++


HHmmmm 
R12 Dos - A2K

BudRPerry

  • Guest
Re: Can't get defun to work....
« Reply #4 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!

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Can't get defun to work....
« Reply #5 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
The Visual LISP Editor - Part 2
An Introduction to the Visual LISP IDE
Retrieving Information About a Function
A Shortcut to Localising Variables
Debugging Code with the Visual LISP IDE

squirreldip

  • Newt
  • Posts: 114
Re: Can't get defun to work....
« Reply #6 on: January 25, 2016, 02:48:55 PM »
+1

Another good editor is Notepad++ (https://notepad-plus-plus.org/)

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Can't get defun to work....
« Reply #7 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.


ChrisCarlson

  • Guest
Re: Can't get defun to work....
« Reply #8 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.
« Last Edit: January 26, 2016, 11:24:30 AM by ChrisCarlson »

squirreldip

  • Newt
  • Posts: 114
Re: Can't get defun to work....
« Reply #9 on: January 27, 2016, 02:55:12 PM »
Agree...

Notepad++ integrates into your right-click which is handy and it highlights matching parentheses.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Can't get defun to work....
« Reply #10 on: January 27, 2016, 03:06:36 PM »
I got started using VLIDE in 1999 and have never looked back.
For each his own :)

MeasureUp

  • Bull Frog
  • Posts: 462
Re: Can't get defun to work....
« Reply #11 on: January 28, 2016, 01:04:23 AM »
One of the reasons I like NotePad++ is its portable version. I can write codes anywhere.