Jump to content

Number Array Difficulties - Probably Just a Simple Mistake...


Lee Mac

Recommended Posts

Hi Guys,

 

I have just been creating a LISP to produce a number array, but can't get it to work.

 

I would appreciate it if someone could point out the mistake in my program :)

 

(defun c:numarray (/ snum enum incr txpt cnt ldir lspc)
   (while
       (and
           (setq snum (getreal "\nSpecify Starting Number: "))
           (setq enum (getreal "\nSpecify Ending Number: "))
           (setq incr (getreal "\nSpecify Increment Size [> 0.01]: "))
           (setq txpt (getpoint "\nSelect First Text Base Point: "))
       ) ; end and
       (setq cnt snum)
       (initget 1 "Up" "Down" "Left" "Right")
       (setq ldir (getkword "\nSpecify List Direction (Up/Down/Left/Right): "))
       (setq lspc (getreal (strcat "Specify List Spacing [>"
                       (rtos (* 2.5 (getvar "DIMSCALE")) 2 2)
                       "]: "
                   ) ; end strcat
              ) ; end getreal
       ) ; end setq    
       (while
           (<= cnt enum)
           (entmake    (list    '(0 . "TEXT")
                       '(8 . "TEXT")
                       (cons 10 txpt)
                       (cons 40 (* 2.5 (getvar "DIMSCALE")))
                       (cons 1 (rtos cnt 2 2))
                       (cons 50 0.0)
                       '(7 . "STANDARD")
                       '(71 . 0)
                       '(72 . 1)
                       '(73 . 2)
                       (cons 11 txpt)
                   ) ; end list
           ) ; end entmake
           (setq cnt (+ cnt incr))
           (cond
               ((= ldir "Up")
               (setq txpt (list (car txpt)(+ (cadr txpt) lspc)(caddr txpt)))
               ) ; end cond 1
               ((= ldir "Down")
               (setq txpt (list (car txpt)(- (cadr txpt) lspc)(caddr txpt)))
               ) ; end cond 2
               ((= ldir "Right")
               (setq txpt (list (+ (car txpt) lspc)(cadr txpt)(caddr txpt)))
               ) ; end cond 3
               ((= ldir "Left")
               (setq txpt (list (- (car txpt) lspc)(cadr txpt)(caddr txpt)))
               ) ; end cond 4
           ) ; end cond
       ) ; end while
   ) ; end while
   (prompt "\nFunction Complete.")
   (princ)
) ; end program

 

Thanks in advance for any help given :)

Link to comment
Share on other sites

Hi Guys,

 

Once again, thanks for your help with my LISP program :D

Now that I have finished it, I thought I might upload it so that if it is of any use to anyone to help speed up their work, they are free to use it or modify it to better suit their needs. :)

 

So here it is:

 

(defun c:numarray (/ pref ptxt snum enum incr txpt cnt ldir lspc)
   (initget "Yes No")
   (setq pref (getkword "\nPrefix Text? [Yes/No]: "))
   (if (= pref "Yes")
       (setq ptxt (getstring t "\nSpecify Prefix: "))
   ) ; end if
   (while
       (and
           (setq snum (getreal "\nSpecify Starting Number: "))
           (setq enum (getreal "\nSpecify Ending Number: "))
           (setq incr (getreal "\nSpecify Increment Size [> 0.01]: "))
           (setq txpt (getpoint "\nSelect First Text Base Point: "))
       ) ; end and
       (setq cnt snum)
       (initget 1 "Up Down Left Right")
       (setq ldir (getkword "\nSpecify List Direction (Up/Down/Left/Right): "))
       (setq lspc (getreal (strcat "\nSpecify List Spacing [> "
                       (rtos (getvar "TEXTSIZE") 2 2)
                       "]: "
                   ) ; end strcat
              ) ; end getreal
       ) ; end setq
       (cond
           ((/= pref "Yes")
           (while
               (<= cnt enum)
               (entmake    (list    '(0 . "TEXT")
                           '(8 . "TEXT")
                           (cons 10 txpt)
                           (cons 40 (getvar "TEXTSIZE"))
                           (cons 1 (rtos cnt 2 2))
                           (cons 50 0.0)
                           '(7 . "STANDARD")
                           '(71 . 0)
                           '(72 . 1)
                           '(73 . 2)
                           (cons 11 txpt)
                       ) ; end list
               ) ; end entmake
               (setq cnt (+ cnt incr))
               (cond
                   ((= ldir "Up")
                   (setq txpt (list (car txpt)(+ (cadr txpt) lspc)(caddr txpt)))
                   ) ; end cond 1
                   ((= ldir "Down")
                   (setq txpt (list (car txpt)(- (cadr txpt) lspc)(caddr txpt)))
                   ) ; end cond 2
                   ((= ldir "Right")
                   (setq txpt (list (+ (car txpt) lspc)(cadr txpt)(caddr txpt)))
                   ) ; end cond 3
                   ((= ldir "Left")
                   (setq txpt (list (- (car txpt) lspc)(cadr txpt)(caddr txpt)))
                   ) ; end cond 4
               ) ; end cond
           ) ; end while
           ) ; end cond 1
           ((= pref "Yes")
           (while
               (<= cnt enum)
               (entmake    (list    '(0 . "TEXT")
                           '(8 . "TEXT")
                           (cons 10 txpt)
                           (cons 40 (getvar "TEXTSIZE"))
                           (cons 1 (strcat ptxt (rtos cnt 2 2)))
                           (cons 50 0.0)
                           '(7 . "STANDARD")
                           '(71 . 0)
                           '(72 . 1)
                           '(73 . 2)
                           (cons 11 txpt)
                       ) ; end list
               ) ; end entmake
               (setq cnt (+ cnt incr))
               (cond
                   ((= ldir "Up")
                   (setq txpt (list (car txpt)(+ (cadr txpt) lspc)(caddr txpt)))
                   ) ; end cond 1
                   ((= ldir "Down")
                   (setq txpt (list (car txpt)(- (cadr txpt) lspc)(caddr txpt)))
                   ) ; end cond 2
                   ((= ldir "Right")
                   (setq txpt (list (+ (car txpt) lspc)(cadr txpt)(caddr txpt)))
                   ) ; end cond 3
                   ((= ldir "Left")
                   (setq txpt (list (- (car txpt) lspc)(cadr txpt)(caddr txpt)))
                   ) ; end cond 4
               ) ; end cond
           ) ; end while
           ) ; end cond 2
       ) ; end cond
   ) ; end while
   (prompt "\nFunction Complete.")
   (princ)
) ; end program

Hope this helps someone out! :)

Link to comment
Share on other sites

Lee Mac you're learning fast.

 

Food for thought.

(defun c:numarray (/ pref ptxt snum enum incr txpt cnt ldir lspc)
 (initget "Yes No")
 (setq pref (getkword "\nPrefix Text? [Yes/No]: <No>"))
 (if (= pref "Yes")
   (setq ptxt (getstring t "\nSpecify Prefix: "))
   (setq ptxt "")
 )       ; end if
 (while
   (and
     (setq snum (getdist "\nSpecify Starting Number: "))
     (setq enum (getdist "\nSpecify Ending Number: "))
     (setq incr (getdist "\nSpecify Increment Size [> 0.01]: "))
     (setq txtpt (getpoint "\nSelect First Text Base Point: "))
   )     ; end and
    (setq cnt snum)
    (initget 1 "Up Down Left Right")
    (setq ldir (getkword "\nSpecify List Direction (Up/Down/Left/Right): "))
    (setq lspc (getdist (strcat "\nSpecify List Spacing [> "
                                (rtos (getvar "TEXTSIZE") 2 2)
                                "]: "
                        ) ; end strcat
               ) ; end getdist
    )    ; end setq
    (if (member ldir '("Right" "Left"))
      (setq ang 0.)
      (setq ang (/ pi 2.))
    )
    (if (member ldir '("Down" "Left"))
      (setq lspc (- lspc))
    )
       (while
         (<= cnt enum)
          (entmake (list '(0 . "TEXT")
                         '(8 . "TEXT")
                         (cons 10 txtpt)
                         (cons 40 (getvar "TEXTSIZE"))
                         (cons 1 (strcat ptxt (rtos cnt 2 2)))
                         (cons 50 0.0)
                         '(7 . "STANDARD")
                         '(71 . 0)
                         '(72 . 1)
                         '(73 . 2)
                         (cons 11 txtpt)
                   ) ; end list
          ) ; end entmake
          (setq cnt (+ cnt incr))
          (setq txtpt (polar txtpt ang lspc))
       ) ; end while
 )       ; end while
 (prompt "\nFunction Complete.")
 (princ)
)         ; end program

Link to comment
Share on other sites

Thanks Charles,

 

That make the LISP a lot more concise, whilst still achieveing the same result.

 

I couldn't figure out how to incorporate the prefix within the entmake function and still enable the user to decide not to use a prefix, without duplicating the entmake with use of a cond function - but just setting the prefix to "" in the alternative result of the if function accomplishes it nicely.

 

Thanks :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...