Code Red > AutoLISP (Vanilla / Visual)
syntax error from simple if statement
vincent.r:
(if (/= (vl-string-search "SV" do2) nil)
(progn
(setq ndo2 (strcat "_" (substr do2 1 2) (substr do2 (strlen do2) 1)))
(setq csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist))
)
(setq ndo2 (strcat "_" (substr do2 1 3) (substr do2 (strlen do2) 1)))
(setq csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist))
)
Why it is giving me "; error: syntax error" ? Its strange for me. Any help will be highly appreciated.
Tharwat:
--- Quote from: vincent.r on August 17, 2019, 02:40:53 AM ---(if (/= (vl-string-search "SV" do2) nil)
(progn
(setq ndo2 (strcat "_" (substr do2 1 2) (substr do2 (strlen do2) 1)))
(setq csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist))
)
(progn
(setq ndo2 (strcat "_" (substr do2 1 3) (substr do2 (strlen do2) 1)))
(setq csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist))
)
)
Why it is giving me "; error: syntax error" ? Its strange for me. Any help will be highly appreciated.
--- End quote ---
Due to extra expressions ...
Dlanor:
You can go with Tharwat (better solution) or eliminate the progn's entirely and run the setq's together
--- Code - Auto/Visual Lisp: ---(if (/= (vl-string-search "SV" do2) nil) (setq ndo2 (strcat "_" (substr do2 1 2) (substr do2 (strlen do2) 1)) csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist) ) (setq ndo2 (strcat "_" (substr do2 1 3) (substr do2 (strlen do2) 1)) csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist) ))
Lee Mac:
Since the only difference between the then and else arguments is the number of characters supplied to the first substr expression, the code could be condensed to:
--- Code - Auto/Visual Lisp: ---(setq csvlist (cons (strcat "[_SVSIM2]_" (substr do2 1 (if (wcmatch do2 "*SV*") 2 3)) (substr do2 (strlen do2))) csvlist))
vincent.r:
Thanks Tharwat and Dlanore for simple solution. Lee you are always explanative. you are rocking as usual.
I stuck in one more place. I am trying to find closest text from a another text's co-ordinate. I want to add just distance to list and not with Ename to compare closest one. Screenshot also attached.
Code -
(while (/= (sslength motorassocvfd) 0)
(setq checkvfd (ssname motorassocvfd 0))
(if (vl-string-search "VFD IP " (cdr (assoc 1 (entget checkvfd))) 0)
(progn
(setq distvfd (distance (car motorcoord) (cdr (assoc 10 (entget checkvfd)))))
(setq checkdvfd (cons distvfd checkvfd))
(setq Enamesvfd (cons checkvfd Enamesvfd))
)
)
(setq motorassocvfd (ssdel checkvfd motorassocvfd))
)
(setq found (vl-position (apply 'min checkdvfd) checkdvfd))
(setq a_vfd (cdr (assoc 1 (entget (nth found ENamesvfd)))))
Navigation
[0] Message Index
[#] Next page
Go to full version