Assistance Needed with AutoCAD Lisp Routine Development for Text String Categorization

Assistance Needed with AutoCAD Lisp Routine Development for Text String Categorization

razzi_302
Explorer Explorer
668 Views
6 Replies
Message 1 of 7

Assistance Needed with AutoCAD Lisp Routine Development for Text String Categorization

razzi_302
Explorer
Explorer

I am looking for a Lisp routine in AutoCAD to automate the categorization of text strings based on specified dimensions. The routines should:
The routine will:

  • ask the user to select single-line text in the drawing (formated as "length x width").
  • Categorize the lengths based on the width.
  • Sum the lengths for each category.
  • Categorize these dimensions into required ranges, similar to a grading system.
  • Prompt the user to specify locations to place the categorized text and the total cumulative distance text in the drawing.

    I tried doing it with assistance from AI. but without any luck. I am attaching the lisp code we have generated through AI which might help you to understand the requirements and the categories. appreciate your efforts in this regard. 
    thank you.
0 Likes
Accepted solutions (1)
669 Views
6 Replies
Replies (6)
Message 2 of 7

pendean
Community Legend
Community Legend

Show us in a DWG file a mock start/finish scenario for where you'd start and what the finished end result will look like please.

Message 3 of 7

razzi_302
Explorer
Explorer

Thank you for your time and reply. I am attaching the drawing for better understanding. 
Currently, I have a total of 18 drawings and each drawing has almost 60 to 100 text strings, which need to be categorized. And in the coming days, I will have more jobs like this.
I hope this drawing will serve you the purpose. let me if you need more information. Thanks a lot for the efforts. 

0 Likes
Message 4 of 7

Kent1Cooper
Consultant
Consultant

What is the (let) function supposed to do?  That's not an AutoLisp function [yet another instance of AI not understanding well enough how AutoLisp works, apparently assuming function names that belong in other programming languages, or something].

Kent Cooper, AIA
0 Likes
Message 5 of 7

Sea-Haven
Mentor
Mentor
Accepted solution

Try this.

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/assistance-needed-with-autocad-lisp-routine-development-for-text/td-p/12873962

; explained drawing
; By AlanH July 2024


(defun c:wow ( / ss lst lst2 x pos len wid str val pt)

(princ "\n\nSelect text ")
(setq ss (ssget '((0 . "TEXT"))))
(setq lst '())
(repeat (setq x (sslength ss))
(setq str (strcase (cdr (assoc 1 (entget (ssname ss (setq x (1- x))))))))
(setq pos (vl-string-position 88 str))
(setq len (atof (substr str 1 (- pos 1))))
(setq wid (atof (substr str (+ pos 3))))
(setq lst (cons (list len wid) lst))
)

(setq lst (vl-sort lst '(lambda (x y) (< (cadr x)(cadr y)))))

; make 22 totals and set to 0.0
(setq x 1)
(repeat 23
(set (read (strcat "tot" (rtos x 2 0))) 0.0)
(setq x (1+ x))
)

(foreach val lst
(setq wid (cadr val))
(cond 
  ((and (>= wid 0.000) (<= wid 0.100))(setq tot1 (+ tot1 (car val))))
  ((and (>= wid 0.101) (<= wid 0.250))(setq tot2 (+ tot2 (car val))))
  ((and (>= wid 0.251) (<= wid 0.350))(setq tot3 (+ tot3 (car val))))
  ((and (>= wid 0.351) (<= wid 0.450))(setq tot4 (+ tot4 (car val))))
  ((and (>= wid 0.451) (<= wid 0.525))(setq tot5 (+ tot5 (car val))))
  ((and (>= wid 0.526) (<= wid 0.600))(setq tot6 (+ tot6 (car val))))
  ((and (>= wid 0.601) (<= wid 0.700))(setq tot7 (+ tot7 (car val))))
  ((and (>= wid 0.701) (<= wid 0.800))(setq tot8 (+ tot8 (car val))))
  ((and (>= wid 0.801) (<= wid 0.900))(setq tot9 (+ tot9 (car val))))
  ((and (>= wid 0.901) (<= wid 1.000))(setq tot10 (+ tot10 (car val))))
  ((and (>= wid 1.001) (<= wid 1.100))(setq tot11 (+ tot11 (car val))))
  ((and (>= wid 1.101) (<= wid 1.200))(setq tot12 (+ tot12 (car val))))
  ((and (>= wid 1.201) (<= wid 1.300))(setq tot13 (+ tot13 (car val))))
  ((and (>= wid 1.301) (<= wid 1.400))(setq tot14 (+ tot14 (car val))))
  ((and (>= wid 1.401) (<= wid 1.500))(setq tot15 (+ tot15 (car val))))
  ((and (>= wid 1.501) (<= wid 1.600))(setq tot16 (+ tot16 (car val))))
  ((and (>= wid 1.601) (<= wid 1.700))(setq tot17 (+ tot17 (car val))))
  ((and (>= wid 1.701) (<= wid 1.800))(setq tot18 (+ tot18 (car val))))
  ((and (>= wid  1.801) (<= wid 1.900))(setq tot19 (+ tot19 (car val))))
  ((and (>= wid  1.901) (<= wid 2.000))(setq tot20 (+ tot20 (car val))))
  ((and (>= wid  2.001) (<= wid 2.200))(setq tot21 (+ tot21 (car val))))
  ((>= wid  2.201)(setq tot22 (+ tot22 (car val))))
)
)

(setq lst2 (list 
"1a- 0.000 - 0.100"
"1b- 0.101 - 0.250"
"2a- 0.251 - 0.350"
"2b- 0.351 - 0.450"
"3a- 0.451 - 0.525"
"3b- 0.526 - 0.600"
"4a- 0.601 - 0.700"
"4b- 0.701 - 0.800"
"5a- 0.801 - 0.900"
"5b- 0.901 - 1.000"
"6a- 1.001 - 1.100"
"6b- 1.101 - 1.200"
"7a- 1.201 - 1.300"
"7b- 1.301 - 1.400"
"8a- 1.401 - 1.500"
"8b- 1.501 - 1.600"
"9a- 1.601 - 1.700"
"9b- 1.701 - 1.800"
"10a- 1.801 - 1.900"
"10b- 1.901 - 2.000"
"11a- 2.001 - 2.200"
"11b- 2.201 & Above"
)
)

(setq str "" x 0)
(setq str (strcat (nth x lst2) " = " (rtos (eval (read (strcat "Tot" (rtos (+ x 1) 2 0)))) 2 2)))

(repeat (- (length lst2) 1)
(setq x (+ x 1))
(setq str (strcat str "\\P" (nth x lst2) " = " (rtos (eval (read (strcat "Tot" (rtos (+ x 1) 2 0)))) 2 2)))
)

(setq x 0)
(repeat 22
(setq tot23 (+ tot23 (eval (read (strcat "Tot" (rtos (+ x 1) 2 0))))))
(setq x (+ x 1))
)

(setq str (strcat str "\\PTotal Cumulative Distance = " (rtos tot23 2 2)))
(setq pt (getpoint "\nPick top left "))

(command "-mtext" pt pt str "")

(princ)
)
(c:wow)

 

I would look at maybe a table the columns will line up better. Yes need the spacing to be added. 

SeaHaven_0-1720078359028.png

 

 

Message 6 of 7

razzi_302
Explorer
Explorer

Thank you so much! I truly appreciate your time, effort, and expertise. Everything is working perfectly, You've saved me a lot of time and effort. I can't express enough how grateful I am for your help.
If it's convenient for you, could we add a prompt at the beginning to input categories for future adjustments—whether it's altering values, adding new ones, or removing existing ones? Otherwise, the routine you've provided works perfectly fine as it is.

0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor

Glad it worked not sure what you mean ? Do you want like 3-5 in 0.05 steps ?

 

In the example there are changes in the step sizes not a consistent value.

0 Likes