Author Topic: making a small list with autolisp  (Read 1713 times)

0 Members and 1 Guest are viewing this topic.

akkuson

  • Guest
making a small list with autolisp
« on: October 30, 2017, 09:20:35 AM »

hello everyone,

i have a small problem on autolisp. im trying to write one lisp to make list starting from number i to j(user defined).
Numbers are in the list incrementing +1. numbers supposed to be placed in the model area with following conditions;
one column holds max 18 numbers.

first 18 numbers supposed to be placed in first column,
numbers between i+18 and i+35 need to be placed at second column,
numbers between i+36 and i+53 need to be placed at thirth column and it goes until the number reach "j"
 
table location should be determined by user input
distance between columns and rows can be determined by user input or can be predetermined.

here is the sample of what im trying to do.

**********************************************
i       i+18   i+36
i+1   i+19   i+37
i+2   i+20   i+38
i+3   i+21   i+39
i+4   i+22   i+40
i+5   i+23   i+41
i+6   i+24   j
i+7   i+25   
i+8   i+26   
i+9   i+27   
i+10   i+28   
i+11   i+29   
i+12   i+30   
i+13   i+31   
i+14   i+32   
i+15   i+33   
i+16   i+34   
i+17   i+35

*************************************************
i tried couple of different things but the codes became endless loop.
if anyone can help or just give an idea on how to do it i would be glad.
thanks in advance.   

ronjonp

  • Needs a day job
  • Posts: 7529
Re: making a small list with autolisp
« Reply #1 on: October 30, 2017, 09:33:43 AM »
Post your code.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

akkuson

  • Guest
Re: making a small list with autolisp
« Reply #2 on: October 30, 2017, 10:14:16 AM »
here it is,

Code - Auto/Visual Lisp: [Select]
  1. (defun c:weldlist2 ()
  2.   (setq om (getvar "osmode"))
  3.   (setvar "cmdecho" 0)
  4.   (setq T1 "\n text height <"
  5.         T2 "> ?                  "
  6.         T3 2.2
  7.   )
  8.   (terpri)
  9.   (setq TH (getreal (strcat T1 (rtos T3 2 2) T2)))
  10.   (if (= TH nil)
  11.     (setq TH t3)
  12.   )
  13.   (setq h1 (getstring "\n add prefix ?               "))
  14.   (setq n (getint "\n first number of table ?      "))
  15.   (setq wlast (getint "\n last number of table             "))
  16.   (setq p1 (getpoint "\n get point for table "))
  17.   (setq p2 (polar p1 (* PI 1.9055) 5.22))
  18.   (setq p3 (polar p2 (* PI 2) 61.00))
  19.     (while (<= n wlast)
  20.          (setvar "osmode" 0)
  21.          (command "text" "j" "tl" p2 th "0" n "")
  22.          (setvar "osmode" om)
  23.          (terpri)
  24.          (setq n (1+ n))
  25.          (setq p2 (polar p2 (* PI(/ 1.0 2.0)) -3.174))
  26.            
  27.           )
  28.       )  

i defined point p3 but i couldnt manage to use it as i think.



EDIT (John K): Added code tags.
« Last Edit: October 30, 2017, 11:54:19 AM by John Kaul (Se7en) »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: making a small list with autolisp
« Reply #3 on: October 30, 2017, 11:21:46 AM »
Are you wanting to create a TABLE object or just columns of text objects.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: making a small list with autolisp
« Reply #4 on: October 30, 2017, 11:29:28 AM »
I tried to use most of your code, but made a few changes and commented the code a bit.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:weldlist2 (/ ch n p1 pre th wlast x y) ; <- Localize variables
  2.   ;;Not needed
  3. ;;;  (setq   t1 "\n text height <"
  4. ;;;   t2 "> ?                  "
  5. ;;;   t3 2.2
  6. ;;;  )
  7. ;;;  (terpri)
  8. ;;;  (setq th (getreal (strcat t1 (rtos t3 2 2) t2)))
  9. ;;;  (if (= th nil)
  10. ;;;    (setq th t3)
  11. ;;;  )
  12.   ;; Make sure that all the inputs ( and ... ) are entered before proceeding
  13.   (if
  14.     (and
  15.       ;; Default textsize to (getvar 'textsize) if user enters nothing
  16.       (or (setq th (getreal (strcat "\nEnter text height[<" (rtos (getvar 'textsize) 2 1) ">]: ")))
  17.      (setq th (getvar 'textsize))
  18.       )
  19.       ;; Getstring returns "" on enter so no default needed
  20.       (setq pre (getstring "\nPrefix: "))
  21.       ;; Defaults to 1 if use presses enter
  22.       (or (setq n (getint "\nFirst number of table[<1>]: ")) (setq n 1))
  23.       ;; You have to define the column height too... ( default to 18 )
  24.       (or (setq ch (getint "\nColumn height[<18>]: ")) (setq ch 18))
  25.       ;; Defaults to 100 if use presses enter
  26.       (or (setq wlast (getint "\nLast number of table[<100>]: ")) (setq wlast 100))
  27.       ;; If user does not pick a point, the code below will not execute
  28.       (setq p1 (getpoint "\nPick point for table:"))
  29.     )
  30.      (progn ;; Get X value to push over columns
  31.        (setq x (car p1))
  32.        ;; While n is less than the max value
  33.        (while (<= n wlast)
  34.          ;; Reset y value so next column starts at the same height
  35.          (setq y (cadr p1))
  36.          (repeat ch
  37.       (if (<= n wlast)
  38.         (progn (entmake (list   '(0 . "TEXT")
  39.                '(100 . "AcDbEntity")
  40.                '(67 . 0)
  41.                '(8 . "text")
  42.                '(100 . "AcDbText")
  43.                (list 10 x y)
  44.                (cons 40 th)
  45.                (cons 1 (strcat pre (itoa n)))
  46.                '(50 . 0.)
  47.                '(41 . 1.)
  48.                '(51 . 0.)
  49.                '(7 . "Standard")
  50.                '(71 . 0)
  51.                '(72 . 0)
  52.                '(11 0. 0. 0.)
  53.                '(100 . "AcDbText")
  54.                '(73 . 0)
  55.               )
  56.           )
  57.           ;; Removed command call (command "text" "j" "tl" (list x y) th "0" (strcat pre (itoa n)) "")
  58.           ;; Decrement Y
  59.           (setq y (- y th))
  60.           ;; Increment counter
  61.           (setq n (1+ n))
  62.         )
  63.       )
  64.          )
  65.          ;; Increment X value 2X text height to push over next column
  66.          (setq x (+ x (* 2. (getvar 'textsize))))
  67.        )
  68.      )
  69.   )
  70.   (princ)
  71. )
« Last Edit: October 31, 2017, 10:49:01 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

David Bethel

  • Swamp Rat
  • Posts: 656
Re: making a small list with autolisp
« Reply #5 on: October 30, 2017, 04:40:04 PM »
maybe something like this could work

Code - Auto/Visual Lisp: [Select]
  1. (defun c:nlist (/ i j p q z x y x c i l)
  2.   (initget 1)
  3.   (setq i (getint "\nStarting Number 'INT:   "))
  4.  
  5.   (while (or (not j)
  6.              (<= j i))
  7.          (initget 1)
  8.          (setq j (getint "\nEnding Number 'INT:   ")))
  9.  
  10.   (initget 1)
  11.   (setq p (getpoint "\nUpper Left Starting Point:   "))
  12.  
  13.   (initget 6)
  14.   (setq q (getint "\nNumber Of Rows <18>:   "))
  15.   (or q (setq q 18))
  16.  
  17.   (initget 6)
  18.   (setq z (getdist (strcat "\nText Height <" (rtos (getvar "TEXTSIZE") 2 2)">:   ")))
  19.   (or z (setq z (getvar "TEXTSIZE")))
  20.  
  21.   (setq x (car p)
  22.         y (cadr p)
  23.         c 1
  24.         l (strlen (rtos (+ i j) 2 0)))
  25.  
  26.   (repeat (- j i)
  27.     (entmake (list (cons 0 "TEXT")
  28.                    (cons 7 (getvar "TEXTSTYLE"))
  29.                    (cons 1 (rtos i 2 0))
  30.                    (cons 10 (list x (- y z) 0))
  31.                    (cons 11 (list x (- y z) 0))
  32.                    (cons 40 z)
  33.                    ))
  34.     (cond ((zerop (rem c q))
  35.            (setq x (+ x (* z l) 5)
  36.                  y (cadr p)))
  37.            (T
  38.             (setq y (- y (* z 1.5)))))
  39.     (setq i (1+ i)
  40.           c (1+ c)))
  41.   (prin1))

-David
R12 Dos - A2K

akkuson

  • Guest
Re: making a small list with autolisp
« Reply #6 on: October 31, 2017, 07:14:30 AM »
thank you for yours help. 

also i belive that red part should  consist the variable "th" somehow. otherwise there is no point to give text height as variable.
*****************************************************
        (progn (entmake (list   '(0 . "TEXT")
               '(100 . "AcDbEntity")
               '(67 . 0)
               '(8 . "text")
               '(100 . "AcDbText")
               (list 10 x y)
               '(40 . 0.2)
******************************************************
« Last Edit: October 31, 2017, 09:12:29 AM by akkuson »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: making a small list with autolisp
« Reply #7 on: October 31, 2017, 10:36:15 AM »
thank you for yours help. 

also i belive that red part should  consist the variable "th" somehow. otherwise there is no point to give text height as variable.
*****************************************************
        (progn (entmake (list   '(0 . "TEXT")
               '(100 . "AcDbEntity")
               '(67 . 0)
               '(8 . "text")
               '(100 . "AcDbText")
               (list 10 x y)
               '(40 . 0.2)
******************************************************
You are correct :) .. nice catch.
Change to:
Code - Auto/Visual Lisp: [Select]
  1.                (list 10 x y)
  2.                (cons 40 th)
  3.                (cons 1 (strcat pre (itoa n)))
« Last Edit: October 31, 2017, 10:40:13 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC