Author Topic: Questions about automatic numbering and output  (Read 2760 times)

0 Members and 1 Guest are viewing this topic.

myloveflyer

  • Newt
  • Posts: 152
Questions about automatic numbering and output
« on: June 13, 2015, 05:11:16 AM »
Can according to the linear length automatic numbering, the next thing to do is set the permissible error reduce number type and output the results, DWG file on the right side of the Numbers is done in other programs, the following is written in my program, the right of the program is to allow the error is set to 5 mm.
Can you tell me if there is a program under how to modify to get the results I want?

Code: [Select]
(defun c:test(/ ss num e elist v10 v11 pt1 pt2)
(svos)
(if (= num nil) (setq num 1))
(setvar "osmode" 0)
(if (setq ss (ssget '((0 . "LINE"))))
    (progn
      (repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i))))
(setq eList (entget e))
(setq v10 (cdr (assoc 10 eList)))
(setq v11 (cdr (assoc 11 eList)))
  ;(setq disList (cons (distance v10 v11) disList))
(setq pt1 (polar v10 (angle v10 v11) (/(distance v10 v11) 2.0)))
(setq pt2 (polar pt1 (+ (angle v10 v11) (/ pi 2.0)) 300))
  (command "text" "j" "m" pt2 300 (* (/ (angle v10 v11) pi) 180) (strcat "L-" (itoa num)))
(setq num (+ num 1))
      )
    )
  )
(clos)
(princ)
)

(defun svos ()        
  (setq oldosm (getvar "OSMODE")
oldoth (getvar "ORTHOMODE")    
oldlye (getvar "CLAYER")    
oldclr (getvar "CECOLOR")    
plnwid (getvar "PLINEWID")    
oldltp (getvar "CELTYPE")    
  )
)

(defun clos ()    
  (setvar "OSMODE" oldosm)
  (setvar "ORTHOMODE" oldoth)
  (command "LAYER" "SET" oldlye "")
  (setvar "CECOLOR" oldclr)
  (setvar "PLINEWID" plnwid)
  (setvar "CELTYPE" oldltp)
  (princ)
)
« Last Edit: June 13, 2015, 05:30:47 AM by myloveflyer »
Never give up !

myloveflyer

  • Newt
  • Posts: 152
Re: Questions about automatic numbering and output
« Reply #1 on: June 14, 2015, 09:03:16 PM »
How do I write?
Never give up !

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Questions about automatic numbering and output
« Reply #2 on: June 15, 2015, 09:33:19 AM »
How do I write?
Perhaps this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ makereadable a e ep fuzz hgt i l len p sp ss txt)
  2.   (setq l '(("L-1" "3356")
  3.             ("L-2" "3362")
  4.             ("L-3" "3525")
  5.             ("L-4" "3532")
  6.             ("L-5" "3693")
  7.             ("L-6" "3700")
  8.             ("L-7" "3862")
  9.             ("L-8" "3869")
  10.             ("L-9" "4031")
  11.             ("L-10" "4038")
  12.             ("L-11" "4631")
  13.             ("L-12" "4638")
  14.             ("L-13" "4645")
  15.             ("L-14" "4651")
  16.             ("L-15" "4656")
  17.             ("L-16" "4668")
  18.             ("L-17" "4675")
  19.             ("L-18" "4681")
  20.            )
  21.   )
  22.   ;; Make Angle Readable by: ymg
  23.   (defun makereadable (a)
  24.     (setq a (rem (+ a pi pi) (+ pi pi)))
  25.     (rem (if (< (* pi 0.5) a (* pi 1.5))
  26.            (+ a pi)
  27.            a
  28.          )
  29.          (+ pi pi)
  30.     )
  31.   )
  32.   (setq hgt 300.)
  33.   (setq fuzz 5.)
  34.   (if (setq ss (ssget '((0 . "LINE"))))
  35.     (progn
  36.       (repeat (setq i (sslength ss))
  37.         (setq e (ssname ss (setq i (1- i))))
  38.         (setq sp (cdr (assoc 10 (entget e))))
  39.         (setq ep (cdr (assoc 11 (entget e))))
  40.         (setq a (angle sp ep))
  41.         (setq len (distance sp ep))
  42.         (setq p (polar (polar sp a (* len 0.5)) (+ (makereadable a) (* pi 0.5)) hgt))
  43.         (entmakex
  44.           (list
  45.             '(0 . "TEXT")
  46.             '(100 . "AcDbEntity")
  47.             '(67 . 0)
  48.             '(8 . "TEXT")
  49.             '(100 . "AcDbText")
  50.             (cons 10 p)
  51.             (cons 40 hgt)
  52.             (cons
  53.               1
  54.               (strcat
  55.                 (if
  56.                   (vl-some '(lambda (x) (and (equal len (atof (cadr x)) fuzz) (setq txt (car x))))
  57.                            l
  58.                   )
  59.                    txt
  60.                    "L-?"
  61.                 )
  62.               )
  63.             )
  64.             (cons 50 (makereadable a))
  65.             '(41 . 1.0)
  66.             '(51 . 0.0)
  67.             '(7 . "Standard")
  68.             '(71 . 0)
  69.             '(72 . 1)
  70.             (cons 11 p)
  71.             '(100 . "AcDbText")
  72.             '(73 . 2)
  73.           )
  74.         )
  75.       )
  76.     )
  77.   )
  78.   (princ)
  79. )
« Last Edit: June 15, 2015, 09:40:29 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

myloveflyer

  • Newt
  • Posts: 152
Re: Questions about automatic numbering and output
« Reply #3 on: June 23, 2015, 09:22:27 PM »
How do I write?
Perhaps this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ makereadable a e ep fuzz hgt i l len p sp ss txt)
  2.   (setq l '(("L-1" "3356")
  3.             ("L-2" "3362")
  4.             ("L-3" "3525")
  5.             ("L-4" "3532")
  6.             ("L-5" "3693")
  7.             ("L-6" "3700")
  8.             ("L-7" "3862")
  9.             ("L-8" "3869")
  10.             ("L-9" "4031")
  11.             ("L-10" "4038")
  12.             ("L-11" "4631")
  13.             ("L-12" "4638")
  14.             ("L-13" "4645")
  15.             ("L-14" "4651")
  16.             ("L-15" "4656")
  17.             ("L-16" "4668")
  18.             ("L-17" "4675")
  19.             ("L-18" "4681")
  20.            )
  21.   )
  22.   ;; Make Angle Readable by: ymg
  23.   (defun makereadable (a)
  24.     (setq a (rem (+ a pi pi) (+ pi pi)))
  25.     (rem (if (< (* pi 0.5) a (* pi 1.5))
  26.            (+ a pi)
  27.            a
  28.          )
  29.          (+ pi pi)
  30.     )
  31.   )
  32.   (setq hgt 300.)
  33.   (setq fuzz 5.)
  34.   (if (setq ss (ssget '((0 . "LINE"))))
  35.     (progn
  36.       (repeat (setq i (sslength ss))
  37.         (setq e (ssname ss (setq i (1- i))))
  38.         (setq sp (cdr (assoc 10 (entget e))))
  39.         (setq ep (cdr (assoc 11 (entget e))))
  40.         (setq a (angle sp ep))
  41.         (setq len (distance sp ep))
  42.         (setq p (polar (polar sp a (* len 0.5)) (+ (makereadable a) (* pi 0.5)) hgt))
  43.         (entmakex
  44.           (list
  45.             '(0 . "TEXT")
  46.             '(100 . "AcDbEntity")
  47.             '(67 . 0)
  48.             '(8 . "TEXT")
  49.             '(100 . "AcDbText")
  50.             (cons 10 p)
  51.             (cons 40 hgt)
  52.             (cons
  53.               1
  54.               (strcat
  55.                 (if
  56.                   (vl-some '(lambda (x) (and (equal len (atof (cadr x)) fuzz) (setq txt (car x))))
  57.                            l
  58.                   )
  59.                    txt
  60.                    "L-?"
  61.                 )
  62.               )
  63.             )
  64.             (cons 50 (makereadable a))
  65.             '(41 . 1.0)
  66.             '(51 . 0.0)
  67.             '(7 . "Standard")
  68.             '(71 . 0)
  69.             '(72 . 1)
  70.             (cons 11 p)
  71.             '(100 . "AcDbText")
  72.             '(73 . 2)
  73.           )
  74.         )
  75.       )
  76.     )
  77.   )
  78.   (princ)
  79. )
Thanks,ronmjonp
I'm sorry, may I have a question, the expression of I need to be attached to the graphics according to the length of the straight line number, and the line number, length and quantity output to EXCEL, can merge, and the length of the straight line close to set a straight line length tolerance values
Never give up !

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Questions about automatic numbering and output
« Reply #4 on: June 24, 2015, 12:40:56 PM »
Here you go .. I think this is what you're aiming for. :)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _equal makereadable a el ep f file fuzz hgt i len out p pre sp ss tmp)
  2.   (defun _equal (i l f) (vl-remove-if-not (function (lambda (x) (equal i (car x) f))) l))
  3.   ;; Make Angle Readable by: ymg
  4.   (defun makereadable (a)
  5.     (setq a (rem (+ a pi pi) (+ pi pi)))
  6.     (rem (if (< (* pi 0.5) a (* pi 1.5))
  7.            (+ a pi)
  8.            a
  9.          )
  10.          (+ pi pi)
  11.     )
  12.   )
  13.   (setq hgt 300.)
  14.   (setq fuzz 5.)
  15.   (setq pre "L-")
  16.   (if (setq ss (ssget '((0 . "LINE"))))
  17.     (progn ;; Gather information and store in list 'out'
  18.            (repeat (setq i (sslength ss))
  19.              (setq el (entget (ssname ss (setq i (1- i)))))
  20.              (setq sp (cdr (assoc 10 el)))
  21.              (setq ep (cdr (assoc 11 el)))
  22.              (setq a (angle sp ep))
  23.              (setq len (distance sp ep))
  24.              (setq p (polar (polar sp a (* len 0.5)) (+ (makereadable a) (* pi 0.5)) hgt))
  25.              (setq out (cons (list len p a) out))
  26.            )
  27.            ;; Sort 'out' by shortest length
  28.            (setq out (vl-sort out '(lambda (a b) (< (car a) (car b)))))
  29.            ;; File to write results
  30.            (setq file (open (strcat (getvar 'dwgprefix) "Results.csv") "w"))
  31.            (write-line "Name,Length(mm),NO,Sum(m)" file)
  32.            ;; Place labels in drawing and write to csv file
  33.            (while out
  34.              (setq i (1+ i))
  35.              (setq len (caar out))
  36.              (mapcar (function (lambda (x) (setq out (vl-remove x out))))
  37.                      (setq tmp (_equal len out fuzz))
  38.              )
  39.              (foreach x tmp
  40.                (entmakex (list '(0 . "TEXT")
  41.                                '(100 . "AcDbEntity")
  42.                                '(67 . 0)
  43.                                '(8 . "TEXT")
  44.                                '(100 . "AcDbText")
  45.                                (cons 10 (cadr x))
  46.                                (cons 40 hgt)
  47.                                (cons 1 (strcat pre (itoa i)))
  48.                                (cons 50 (makereadable (caddr x)))
  49.                                '(41 . 1.0)
  50.                                '(51 . 0.0)
  51.                                '(7 . "Standard")
  52.                                '(71 . 0)
  53.                                '(72 . 1)
  54.                                (cons 11 (cadr x))
  55.                                '(100 . "AcDbText")
  56.                                '(73 . 2)
  57.                          )
  58.                )
  59.              )
  60.              (write-line
  61.                (strcat pre
  62.                        (itoa i)
  63.                        ","
  64.                        (vl-princ-to-string (caar tmp))
  65.                        ","
  66.                        (itoa (length tmp))
  67.                        ","
  68.                        (vl-princ-to-string (apply '+ (mapcar 'car tmp)))
  69.                )
  70.                file
  71.              )
  72.            )
  73.            (close file)
  74.            (print (strcat (getvar 'dwgprefix) "Results.csv"))
  75.     )
  76.   )
  77.   (princ)
  78. )
« Last Edit: June 24, 2015, 12:55:23 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

myloveflyer

  • Newt
  • Posts: 152
Re: Questions about automatic numbering and output
« Reply #5 on: June 24, 2015, 11:26:21 PM »
Here you go .. I think this is what you're aiming for. :)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _equal makereadable a el ep f file fuzz hgt i len out p pre sp ss tmp)
  2.   (defun _equal (i l f) (vl-remove-if-not (function (lambda (x) (equal i (car x) f))) l))
  3.   ;; Make Angle Readable by: ymg
  4.   (defun makereadable (a)
  5.     (setq a (rem (+ a pi pi) (+ pi pi)))
  6.     (rem (if (< (* pi 0.5) a (* pi 1.5))
  7.            (+ a pi)
  8.            a
  9.          )
  10.          (+ pi pi)
  11.     )
  12.   )
  13.   (setq hgt 300.)
  14.   (setq fuzz 5.)
  15.   (setq pre "L-")
  16.   (if (setq ss (ssget '((0 . "LINE"))))
  17.     (progn ;; Gather information and store in list 'out'
  18.            (repeat (setq i (sslength ss))
  19.              (setq el (entget (ssname ss (setq i (1- i)))))
  20.              (setq sp (cdr (assoc 10 el)))
  21.              (setq ep (cdr (assoc 11 el)))
  22.              (setq a (angle sp ep))
  23.              (setq len (distance sp ep))
  24.              (setq p (polar (polar sp a (* len 0.5)) (+ (makereadable a) (* pi 0.5)) hgt))
  25.              (setq out (cons (list len p a) out))
  26.            )
  27.            ;; Sort 'out' by shortest length
  28.            (setq out (vl-sort out '(lambda (a b) (< (car a) (car b)))))
  29.            ;; File to write results
  30.            (setq file (open (strcat (getvar 'dwgprefix) "Results.csv") "w"))
  31.            (write-line "Name,Length(mm),NO,Sum(m)" file)
  32.            ;; Place labels in drawing and write to csv file
  33.            (while out
  34.              (setq i (1+ i))
  35.              (setq len (caar out))
  36.              (mapcar (function (lambda (x) (setq out (vl-remove x out))))
  37.                      (setq tmp (_equal len out fuzz))
  38.              )
  39.              (foreach x tmp
  40.                (entmakex (list '(0 . "TEXT")
  41.                                '(100 . "AcDbEntity")
  42.                                '(67 . 0)
  43.                                '(8 . "TEXT")
  44.                                '(100 . "AcDbText")
  45.                                (cons 10 (cadr x))
  46.                                (cons 40 hgt)
  47.                                (cons 1 (strcat pre (itoa i)))
  48.                                (cons 50 (makereadable (caddr x)))
  49.                                '(41 . 1.0)
  50.                                '(51 . 0.0)
  51.                                '(7 . "Standard")
  52.                                '(71 . 0)
  53.                                '(72 . 1)
  54.                                (cons 11 (cadr x))
  55.                                '(100 . "AcDbText")
  56.                                '(73 . 2)
  57.                          )
  58.                )
  59.              )
  60.              (write-line
  61.                (strcat pre
  62.                        (itoa i)
  63.                        ","
  64.                        (vl-princ-to-string (caar tmp))
  65.                        ","
  66.                        (itoa (length tmp))
  67.                        ","
  68.                        (vl-princ-to-string (apply '+ (mapcar 'car tmp)))
  69.                )
  70.                file
  71.              )
  72.            )
  73.            (close file)
  74.            (print (strcat (getvar 'dwgprefix) "Results.csv"))
  75.     )
  76.   )
  77.   (princ)
  78. )
Thank you very much, ronjonp.has been basically can satisfy the need, I put the layer, fonts, and other little detail perfect, then add some other auxiliary program, I think this program is more perfect, thank you again
Never give up !

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Questions about automatic numbering and output
« Reply #6 on: June 25, 2015, 08:29:28 AM »
Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC