Good Morning,
I’m new to autoLISP and trying to modify some code I found to do something a little different.
I’m looking to prompt the user to select a polyline and then a collection of line segments and count the intersections between them as a start. After some modification I can no longer load it — loading results in a syntax error.
Does anyone have any thoughts on this? See code below:
——————————————————————————-
(defun c:EONEinterscount ( / c i l s x ent sel2 ) ;;define function
(if
(setq ent (car (entsel))) ;;selects Zone polyline
(setq sel2 (ssget ‘((0 . «LINE»)(8 . «LPSLAT»)))) ;;selects lateral lines
(setq s (ssadd ent sel2)) ;;adds zone and laterals to same selection set
(if
(cdr
(repeat (setq i (sslength s))
(setq i (1- i)
l (cons (vlax-ename->vla-object (ssname s i)) l)
)
)
)
(progn
(setq c 0)
(while (setq x (car l))
(foreach y (setq l (cdr l))
(setq c (+ c (/ (length (vlax-invoke x ‘intersectwith y acextendnone)) 3)))
)
)
(princ (strcat «\n» (itoa c) » intersection» (if (= 1 c) «» «s») » between » (itoa (sslength s)) » objects.»))
)
(princ «\nPlease select more than one object.»)
)
)
(princ) ;;clean exit
)
(vl-load-com) (princ)
27 minutes ago, tombu said:
Second always save a link to where you got the code, if you ever have an issue with it that should be the best place to get support from whoever the code belongs to.
ChatGPT is computer generated code, so no source location to post… and I bet if you asked the computer why it isn’t working it will just go «?»
If you were to go through the code and do 2 things, first off mark the end of each if, progn, repeat for example
....
(if (= count 2)
(progn
.... do somew stuff
) ; end progn
(progn
... do some other stuff
) ; end progm
) ; end if
This can help a lot. Syntax error might be that an if statement has more then 2 parts after it (which is a kind of hint) and might be missing a (progn …. ) part
Second is to comment out all the lines with a ; leaving in something like the last (princ) — lisp doesn’t like empty routines…. and remove the commented out parts section by section till you find where the problem is.
So for example I did this and got to the first half up to ‘ (setq ss (ssget «_X» ‘((0 . «WIPEOUT»))))’ is good, problem is after then, also noting the end points of the if statements, ‘(if (cdr (assoc 330 ent))’ has too many parts, might be missing a progn somewhere?
It might be quite satisfying working out the issue from a couple of hints?
Using the Check Command to Look for Syntax Errors
Using the Check Command to Look for Syntax Errors
Debugging Programs
Finding the Location of the Syntax Error in Your
Program
If you double-click on the
error message in the Build Output window, VLISP activates the editor
window, places the cursor at the beginning of the statement that
caused the error, and highlights the entire expression, as follows:
This error results from the last princ statement following
the if. The if statement only allows
two arguments: the statement to execute if the expression is true,
and the statement to execute if the expression is false. The last princ statement, which
is used in this program to cause a quiet exit, belongs after the
close parenthesis that currently follows it. (See Exiting Quietly for
an explanation of a quiet exit.) If you move the statement to the
correct location and run Check again, the code should pass as error-free.
Topic: ? syntax error in AutoLisp? error: bad argument type: numberp: nil (Read 3906 times)
0 Members and 1 Guest are viewing this topic.
+X^N
Hello ,
I am learning AutoLisp ;
get error: bad argument type: numberp: nil
.
Am seeking to make new UCS at an angle .
here is the code :
; Define local FUNCTIONs
(dfnc dist_half(/ x_refl y_refl) ;; UCS distance X to Point
(/ (sqrt(+ (expt x_refl 2.0) (expt y_refl 2.0))) 2.0) ;; SquareRoot of X^2 + Y^2 = Hypotenuse
)
(dfnc c:distz-hgt(/ fo_hgt_z reflhgtz) ;; UCS distance Y to Point
(- fo_hgt_z reflhgtz)
)
;; TESTing 20160911
; Create UCS "ReflNN_1" tipped towards Point
(setq point2 '(dist_half(20.8125 20.8125) distz-hgt(0.625) 0) );; use FUNCTION of distance : from UCS 'horizonatally' to the
(command "_.ucs" "_3p" (0 0 0) point2 (0 0 1)) ;; UCS Origin , Positive X Axis , Positive Y Orientation _ the Refel Center , Tip the UCS towards THE Point , UCS Positive Z direction unit ; still need to 'flip '
(command "_.ucs" "_na" "_s" "Refl25_1_TEST")
;; end_TESTing 20160911
any help is _pre_appreciated
« Last Edit: September 11, 2016, 06:45:23 PM by +X^N »
Logged
At first glance it looks like;
(0 0 0) is not a list you need to make it ‘(0 0 0) same with the list after point2.
Logged
+X^N
Calculating the numbers by hand and using in the setq works :
-
;; TESTing 20160911
-
; Create UCS ‘tipped’ towards Point «ReflNN_1»
-
(setq point1 ‘(0 0 0) point2 ‘(—14.716659883445020351592573286307 62.375 0) point3 ‘(0 0 1)) ;; from UCS ‘horizonatally’ to the
-
(command «_.ucs» «_3p» point1 point2 point3) ;; UCS Origin , Positive X Axis , Positive Y Orientation _ the Refel , Tip the UCS towards THE Point , UCS Positive Z direction unit
-
(command «_.ucs» «_na» «_s» «Refl25_1_TEST»)
-
;; end_TESTing 20160911
However , would like to have calculation in the setq _ as in the first post .
« Last Edit: September 13, 2016, 01:10:14 AM by +X^N »
Logged
Just guessing, but according to your later numerical interpretation, maybe it should look like this :
; Define local FUNCTIONs
(defun dist_half ( x_refl y_refl ) ;; UCS distance X to Point
(/ (sqrt (+ (expt x_refl 2.0) (expt y_refl 2.0))) -2.0) ;; SquareRoot of X^2 + Y^2 = Hypotenuse
)
(defun distz-hgt ( fo_hgt_z reflhgtz ) ;; UCS distance Y to Point
(- fo_hgt_z reflhgtz)
)
;; TESTing 20160911
; Create UCS "ReflNN_1" tipped towards Point
(setq point2 (list (dist_half 20.8125 20.8125) (distz-hgt 63.0 0.625) 0.0));; use FUNCTION of distance : from UCS 'horizonatally' to the
(command "_.ucs" "_3p" "_non" '(0.0 0.0 0.0) "_non" point2 "_non" '(0.0 0.0 1.0)) ;; UCS Origin , Positive X Axis , Positive Y Orientation _ the Refel Center , Tip the UCS towards THE Point , UCS Positive Z direction unit ; still need to 'flip '
(command "_.ucs" "_na" "_s" "Refl25_1_TEST")
;; end_TESTing 20160911
And I would set point2 variable at the end to nil or localize point2 variable inside main function that haven’t yet been defined…
HTH, M.R.
Logged
+X^N
Just guessing, but according to your later numerical interpretation, maybe it should look like this :
; Define local FUNCTIONs
(defun dist_half ( x_refl y_refl ) ;; UCS distance X to Point
(/ (sqrt (+ (expt x_refl 2.0) (expt y_refl 2.0))) —2.0) ;; SquareRoot of X^2 + Y^2 = Hypotenuse
)
(defun distz—hgt ( fo_hgt_z reflhgtz ) ;; UCS distance Y to Point
(— fo_hgt_z reflhgtz)
)
;; TESTing 20160911
; Create UCS «ReflNN_1» tipped towards Point
(setq point2 (list (dist_half 20.8125 20.8125) (distz—hgt 63.0 0.625) 0.0));; use FUNCTION of distance : from UCS ‘horizonatally’ to the
(command «_.ucs» «_3p» «_non» ‘(0.0 0.0 0.0) «_non» point2 «_non» ‘(0.0 0.0 1.0)) ;; UCS Origin , Positive X Axis , Positive Y Orientation _ the Refel Center , Tip the UCS towards THE Point , UCS Positive Z direction unit ; still need to ‘flip ‘
(command «_.ucs» «_na» «_s» «Refl25_1_TEST»)
;; end_TESTing 20160911
And I would set point2 variable at the end to nil or localize point2 variable inside main function that haven’t yet been defined…
HTH, M.R.
Thank you _ am just learning — it (mostly) was the need for list (which allows evaluative statements ) ,
rather than ‘ (which seems to act as a literal ) .
.
My trig was incorrect ;
I need to halve the angle not a horiz. dist . (I still need the horiz dist though) .
will start seperate thread .
« Last Edit: September 13, 2016, 01:10:53 AM by +X^N »
Logged
+X^N
Interesting did a quick copy and paste to see what was happening.
Command: (setq point2 ‘((/ (sqrt(+ (expt 20.8125 2.0) (expt 20.8125 2.0))) 2.0) (- 63.0 0.625) 0))
((/ (SQRT (+ (EXPT 20.8125 2.0) (EXPT 20.8125 2.0))) 2.0) (- 63.0 0.625) 0)Command: !point2
((/ (SQRT (+ (EXPT 20.8125 2.0) (EXPT 20.8125 2.0))) 2.0) (- 63.0 0.625) 0)
I gather that the ‘ acts like the AutoLISP function quote
in that it acts as a literal , or prvents the statement following evaluation ;
this is sometimes what we need .
Otherwise use the
-
(setq point2 (list (/ (sqrt(+ (expt 20.8125 2.0) (expt 20.8125 2.0))) 2.0) (— 63.0 0.625) 0))
(see below)
Just got back from Lee Mac’s amazing site, and the explanation for use of the apostrophe and the quote function is described in depth.
http://www.lee-mac.com/quote.html
Thanks again, Lee Mac!
Learning is fun ctional .
« Last Edit: September 13, 2016, 01:12:07 AM by +X^N »
Logged
попытка выполнить RESET не из
цикла прерывания.
Value of LISPSUBR is too small
Значение LISPSUBR слишком мало
попытка загрузить скомпилированную функцию
, длина которой больше, чем определено в LISPSUBR.
8.3. Сообщения об ошибках компилятора.
ACOMP.INI not found
Не найден ACOMP.INI
не найден файл инициализации компилятора ACOMP.INI.
Это может произойти из-за неверной установки переменой COMPINIT.
Bad ACOMP.INI
Плохой файл ACOMP.INI
попытка
загрузить файл инициализации компилятора не удалоась из-за неверного формата
файла.
Bad LAMBDA
Плохая lambda
выражение lambda или обращение к defun имеет
неверный формат.
Bad varable
Плохая переменная
недопустимая переменная встречена в списке параметров
функций lambda или defun.
Binary output file open
failure:<filename>
Неудачное открытие выходного двоичного файла :<имя файла>
при попытке открыть результирующий файл
<имя файла> произошла ошибка.
Cannot get CAR of <expression>
Нельзя получить CAR<выражения>
Cannot get CDR of <expression>
Нельзя получить CDR <выражения>
попытка получить CAR или CDR <выражения>, не являющегося списком.
Сircular definition for <function>
“Порочный
круг” для
<функции>
встретилось недопустимое рекурсивное
определение. Например , функция состоит только из обращения к самой себе.
Declared special:<variables list>
Объявлены специальными:( <список переменных>)
информационное сообщение, указывающее, что
компилятор распознал ссылки на перечисленные переменые как неместные и объявил
их неместными.
Duplicate variable <var> in LAMBDA
list
Повторная переменная <имя> в списке параметров lambda
переменная <имя>встретилась дважды в списке параметров функции или
lambda (необходимо помнить, что
использование одних и тех же имен до и после наклонной черты в списке
параметров также недопустимо).
Error in file:<filename>
Ошибка в файле:<имя
файла>
встретилась ошибка при обработке файла <имя файла> . Причинами могут быть неправильное размещение скобок,
недопустимые символы и т.п.
Idential names for input and binary files
Идентичные имена для входного и результирующего файлов
имена в обращении к компилятору для входного и
выходного файлов идентичны.Для предотвращения порчи входногофайла
компиляции прекращается.
Improrer call to APPLY
Неправильное обращение к APPLY
количество параметров в обращении к функции APPLY не равно 2.
Improrer use of LAMBDA in <function>
Неправильное использование LAMBDA в <функции>
встетилось либо обращение к lambda без параметров , либо выражение lambda в <функции>
находиться в неправильной позиции.
Invalid function <expression>
Недопустимое <выражение> функции
неверное <выражение> на
месте, где должно быть имя функции или выражения lambda.
Mismatchof arguments
Несоответствие параметров
количество
параметров не соответствует заданному в обращении к функции с фиксированным
количеством параметров.
Outfile specified more then once
Выходной файл определен больше, чем однажды
признак
выходного файла –о в обращении к компилятору определен более одного раза.
Suntax error in file: <filename>
Синтаксическая ошибка в файле: <имя файла>
встречена синтаксическая ошибка при
обработке файла <имя файла>.
Suntax error in function: < function
>
Синтаксическая ошибка в <функции>
встретилась синтаксическая ошибка при
обработке <функции>.
Too many args in call from <functions1> to <functions2>
Слишком много параметров в обращении из <функции 1> к <функции 2>
в обращении к <функции 2> из <функции
1> более 32 параметров.
Too many args in definition of < function >
Слишком много параметров в определении <функции>
в определении <функции> более 32
параметров
Too many errors – compilation aborted
Слишком много ошибок – Компиляция прекращена
при
компиляции заданного файла более 5 ошибок.