TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: zombies640 on September 26, 2016, 11:01:52 AM

Title: Can't locate error
Post by: zombies640 on September 26, 2016, 11:01:52 AM
How this is supposed to work is the user will first select objects, then run the command. The routine will determine if either "DEC" or "CNF" is in the point description. If it is, place a block and some text.

Not sure why this is giving me an error now. It looks like it only errors after the IF statement triggers TRUE:
Code: [Select]
Command: ; error: no function definition: nil
Code: [Select]
(defun c:desc2 (/ ss x northng pnt eastng descr)
   (vl-load-com)
   (if (ssget ":S:E" '((0 . "AECC_COGO_POINT")))
      (progn
         (vlax-for x
            (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
            (setq pnt (vlax-get x 'number)
               eastng (vlax-get x 'easting)
               northng (vlax-get x 'northing)
               descr (vlax-get x 'rawdescription)
            );END setq
            (if
               (or
                  (= 0 (vl-string-search "DEC" descr))
                  (= 0 (vl-string-search "CNF" descr))
               );END or
               (
                  (command "text" "c" (list eastng northng) 0.5 0 descr)
                  (command "-insert" "nf_shrub_conifer" (list eastng northng) "" "" "")                 
               );END if TRUE
            );END if
         );END vlax-for
      );END progn
   );END if
   (princ)
)
Title: Re: Can't locate error
Post by: ribarm on September 26, 2016, 11:22:33 AM
Can't test it as I don't have Civil, but I suppose you forgot to put (progn after (if (condition)...

(defun c:desc2 (/ ss x northng pnt eastng descr)
   (vl-load-com)
   (if (ssget ":S:E" '((0 . "AECC_COGO_POINT")))
      (progn
         (vlax-for x
            (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
            (setq pnt (vlax-get x 'number)
               eastng (vlax-get x 'easting)
               northng (vlax-get x 'northing)
               descr (vlax-get x 'rawdescription)
            );END setq
            (if
               (or
                  (= 0 (vl-string-search "DEC" descr))
                  (= 0 (vl-string-search "CNF" descr))
               );END or
               (progn
                  (command "text" "c" (list eastng northng) 0.5 0 descr)
                  (command "-insert" "nf_shrub_conifer" (list eastng northng) "" "" "")                 
               );END if TRUE
            );END if
         );END vlax-for
      );END progn
   );END if
   (princ)
)
Title: Re: Can't locate error
Post by: zombies640 on September 26, 2016, 11:27:41 AM
Yup, that works. As you were replying, I was trying this instead

Changed:
Code: [Select]
               (
                  (command "text" "c" (list eastng northng) 0.5 0 descr)
                  (command "-insert" "nf_shrub_conifer" (list eastng northng) "" "" "")                 
               );END if TRUE

To:
Code: [Select]
               (command "text" "c" (list eastng northng) 0.5 0 descr
                    "_insert" "nf_shrub_conifer" (list eastng northng) "" "" ""
               );END if true

I like your method better...it's so much celaner. I didn't know you had to use PROGN for separate commands. Now I know! Thanks :)
Title: Re: Can't locate error
Post by: ribarm on September 26, 2016, 12:09:20 PM
You're welcome...

BTW. The code you posted looks like there already was written progn, but someone deliberately or not removed it from apparent place inside it...
Title: Re: Can't locate error
Post by: PKENEWELL on September 27, 2016, 09:38:49 AM
I like your method better...it's so much celaner. I didn't know you had to use PROGN for separate commands. Now I know! Thanks :)

NOTE: The (progn) function is is used to combine multiple programming statements into a single output. The reason you have to use it in the IF statement is because IF can only evaluate 1 output for each If / Then and Else combination.
Title: Re: Can't locate error
Post by: alanjt on September 27, 2016, 10:07:06 AM
These threads should be merged.
https://www.theswamp.org/index.php?topic=52059.0 (https://www.theswamp.org/index.php?topic=52059.0)