Author Topic: syntax error from simple if statement  (Read 522 times)

0 Members and 1 Guest are viewing this topic.

vincent.r

  • Newt
  • Posts: 47
syntax error from simple if statement
« 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))
      )
      (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

  • Swamp Rat
  • Posts: 518
  • Hypersensitive
Re: syntax error from simple if statement
« Reply #1 on: August 17, 2019, 04:13:32 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.

Due to extra expressions ...

Dlanor

  • Newt
  • Posts: 183
Re: syntax error from simple if statement
« Reply #2 on: August 17, 2019, 04:23:24 AM »
You can go with Tharwat (better solution) or eliminate the progn's entirely and run the setq's together

Code - Auto/Visual Lisp: [Select]
  1. (if (/= (vl-string-search "SV" do2) nil)
  2.   (setq ndo2 (strcat "_" (substr do2 1 2) (substr do2 (strlen do2) 1))
  3.         csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist)
  4.   )
  5.   (setq ndo2 (strcat "_" (substr do2 1 3) (substr do2 (strlen do2) 1))
  6.         csvlist (cons (strcat "[_SVSIM2]" ndo2) csvlist)
  7.   )
  8. )
  9.  

Lee Mac

  • Seagull
  • Posts: 12295
  • London, England
Re: syntax error from simple if statement
« Reply #3 on: August 17, 2019, 06:13:57 AM »
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: [Select]
  1. (setq csvlist (cons (strcat "[_SVSIM2]_" (substr do2 1 (if (wcmatch do2 "*SV*") 2 3)) (substr do2 (strlen do2))) csvlist))

vincent.r

  • Newt
  • Posts: 47
Re: syntax error from simple if statement
« Reply #4 on: August 17, 2019, 10:44:07 AM »
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)))))


Tharwat

  • Swamp Rat
  • Posts: 518
  • Hypersensitive
Re: syntax error from simple if statement
« Reply #5 on: August 17, 2019, 03:22:03 PM »
Hi,
Try it this way and the variable name 'closest' should obtain the shortest distance.

Code - Auto/Visual Lisp: [Select]
  1. (repeat (setq inc (sslength motorassocvfd))
  2.   (setq elst (entget (ssname motorassocvfd (setq inc (1- inc)))))
  3.   (if (vl-string-search "VFD IP " (cdr (assoc 1 elst)))
  4.     (progn
  5.       (setq distvfd (distance (car motorcoord) (cdr (assoc 10 elst))))
  6.       (if closest (if (< distvfd closest) (setq closest distvfd))
  7.         (setq closest distvfd))
  8.       )
  9.     )
  10.   )
  11.  

vincent.r

  • Newt
  • Posts: 47
Re: syntax error from simple if statement
« Reply #6 on: August 19, 2019, 12:07:11 AM »
Thanks Tharwat. Your code is working perfect. You are great Guru.
« Last Edit: August 19, 2019, 01:06:29 AM by vincent.r »

Tharwat

  • Swamp Rat
  • Posts: 518
  • Hypersensitive
Re: syntax error from simple if statement
« Reply #7 on: August 19, 2019, 02:26:42 AM »
You're most welcome.