Need help counting support quantities, can you please help?

Need help counting support quantities, can you please help?

israelU7LZU
Participant Participant
1,347 Views
52 Replies
Message 1 of 53

Need help counting support quantities, can you please help?

israelU7LZU
Participant
Participant

Good day to you Gentlemen,

 

I am not proficient in lisp programing, I don't quite understand the programing language. that's why I come seeking your help on this. 

 

I need to come up with a way to count supports quantities and add them up by height and create some sort of list in numerical order. is there a way to do these things?

 

please let me know what other info is needed to make this happen. 

 

Thank you 

0 Likes
1,348 Views
52 Replies
Replies (52)
Message 21 of 53

israelU7LZU
Participant
Participant

I still need some help. Thank you

0 Likes
Message 22 of 53

Sea-Haven
Mentor
Mentor

@israelU7LZU You copy the code from here, then paste into Notepad, then save say as Supports.lsp, save it to somewhere you can find it easily. For most people that is say c:\mylisps or say C:\Cad-tools\lisp. So save all your downloaded lisps to that directory. I have mine on 😧 drive. Another good idea is to type "Options", choose "Files" then "Support" add the directory you have saved all your lisps in. 

 

To run type Appload then select supports.lsp. I have set it to autorun on load so it should run straight away. You can also drag and drop from Explorer the file onto the Cad screen. If you need to run again type "AHsupports". Do a small pick 1st and check answer for all support sizes and number. Do a few. For the supports on an angle when asked to "Select" text type "WP" this will allow you to select a window on an angle will need 4 picks. The program looks for text on one layer only, so can use window etc when selecting, I did entire dwg when testing.

 

To run other lisp's it may be worth making a new "Menu" so you can choose those lisps and load as required, I have attached something for you about making a POP menu for your Cad. Have a go if get stuck just ask here for help.

0 Likes
Message 23 of 53

israelU7LZU
Participant
Participant

Good day Sea_Haven

 

I saved the lisp as "SPT_Band_Supports.lsp" and also as "Supports.lsp"

 

israelU7LZU_0-1788026142509.png

 

Then I also added the directory on options

 

israelU7LZU_1-1788026439393.png

 

But when I type in "AHsupports" or drag and drop the lisp from explorer into CAD, I get this message...

 

israelU7LZU_2-1788026581225.png

 

what am I doing wrong? 

 

0 Likes
Message 24 of 53

Sea-Haven
Mentor
Mentor

As you have added  the support path you can just use (load "Supports.lsp"). By using a support path there is a auto search through the support paths list looking for a file name. That is why I suggested adding the support path. Once it finds the file it acts on it so having it first in list is a good idea.

 

Ok answer two when using a deep directory it may sound strange but you need to use double backslashes, (load "C:\\Apps\\Pt-cad\\lisp\\Supports.lsp), its to do with the operating system ie windows. Old like me UNIX was opposite direction of slashes. You can also do (load "C:/Apps/Pt-cad/lisp/supports.lsp") this will work, but if you have spaces in directory names, use the "\\"

 

Third option just drag "Supports.lsp" from explorer onto your Cad screen it should just run.

 

The best way is to make a POP menu with the lisp files you want to run. I have purposely stayed away from making a Ribbon menu as you need  to use CUI to make one. A task of its own.

 

Hope that all makes sense. Just get in touch again if having problems.

 

0 Likes
Message 25 of 53

israelU7LZU
Participant
Participant

Sea-Haven

 

I'm good at using CAD just not at programing it, a lot of the terminology you use, I dont understand lol. I try loading the LISP program different ways but I keep running into the the wall. I dont know what else to do 😞

israelU7LZU_0-1788235820453.png

 

0 Likes
Message 26 of 53

Kent1Cooper
Consultant
Consultant

A "syntax error" often means a parentheses problem.  Could something have gone wrong in copying/pasting the code into a file, like not having selected all the way to the last right parenthesis?

When I pasted it into a file, in a Support File Search Path folder so I didn't need to spell out the path, it loaded for me.  [I haven't downloaded the drawing to try the command.]  Post the .lsp file as you saved it, so we can try loading it.

Kent Cooper, AIA
0 Likes
Message 27 of 53

paullimapa
Mentor
Mentor

paullimapa_2-1788234657699.png

dnload attached revised supports.lsp


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 28 of 53

israelU7LZU
Participant
Participant

That actually worked. thank you for that. 

 

once I ran the program, I noticed that it is counting every chair height as a single item. 

 

israelU7LZU_0-1788246497916.png

 

 

but in reality, the number of chairs depends on the number of bundles of cables. 

 

israelU7LZU_1-1788246793909.png

 

Please let me know if this can be done and if I'm been clear with my explanation of the chairs. thank you

 

 

0 Likes
Message 29 of 53

Sea-Haven
Mentor
Mentor

Thank you @paullimapa yes should only have had 2 right closing brackets. Updated above.

 

@israelU7LZU forgot about the multiply totals by the number of bands will fix that, it does mean you will get a table for each group as 2nd go. 3rd go, it is possible to maybe get a master list though. It will mean you have to select a group of text then select the number of bands, this can be done by dragging a line over the bands and they will be auto counted. You will have to repeat for each group. Something like 12 times. Then will get master totals.

 

Watch this space.

 

I think I know how double brackets occurred my fault. I sort the local variables and paste into code that is where extra bracket came from a last minute update.

0 Likes
Message 30 of 53

lauri_barnhart
Autodesk
Autodesk

Hello, @israelU7LZU.

 

Checking to see if you saw Sea-Haven's reply and if it provided the clarity you needed. If it did, please consider clicking on the 'Accept Solution' button. 

 

Best,


Lauri | Community Manager
0 Likes
Message 31 of 53

israelU7LZU
Participant
Participant

i don't mind if I get a total of chairs per size in a single table. as long as I can select specific areas. Thank you

0 Likes
Message 32 of 53

Sea-Haven
Mentor
Mentor

Ok a new version, you need to use WP when selecting text in particular in locations like this. See wiggle in selection.

SeaHaven_0-1788313180865.png

 

0 Likes
Message 33 of 53

israelU7LZU
Participant
Participant

Got it, if I decide to run the program for the whole drawing, then could the quantities be display as total for each height so we don't have to have many small tables?

0 Likes
Message 34 of 53

Sea-Haven
Mentor
Mentor

The problem is you have to associate the cables with text, as I hinted can do all but need still to select the Cables & Mtext repeated times. If that is ok then will do a repeat select. So one big answer.

 

0 Likes
Message 35 of 53

israelU7LZU
Participant
Participant

I think doing multiple selects will work as long as I total is correct. I would really appreciate that

0 Likes
Message 36 of 53

Sea-Haven
Mentor
Mentor

Have some other ideas about how to simplify the selection process of multiple cable groups. but for moment will do a make a big list via multiple selections.

 

Had a couple of days off, still working on it. 5 Sept

0 Likes
Message 37 of 53

Sea-Haven
Mentor
Mentor

@israelU7LZU please try this. limited testing on counts. Note in some areas need care making selection. I have tried to make selection as simple as possible. have another idea but please test this.

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/need-help-counting-support-quantities-can-you-please-help/td-p/14238558
; layer SUPPORT-TEXT-BANDED and plines and TENDON-BANDED-BACKGROUND
; Take text and make them into a table 
; counting the text also
; by Alan H Aug 2026


(vl-load-com)

(defun AH:table_make (numcolumns txtsz / numrows curspc colwidth numcolumnsobjtable rowheight sp doc)
  (setq sp (vlax-3d-point (getpoint "Pick top left")))
  (setq doc(vla-get-activedocument (vlax-get-acad-object) ))
  (if (= (vla-get-activespace doc) 0)
    (setq curspc (vla-get-paperspace doc))
    (setq curspc (vla-get-modelspace doc))
  )
  (setq numrows 2)
  (setq rowheight (* 2.0 txtsz))
  (setq colwidth 100)
  (setq objtable (vla-addtable curspc sp numrows numcolumns rowheight colwidth))
  (vla-settext objtable 0 0 "TABLE title")
  (vla-SetTextHeight Objtable (+ acDataRow acTitleRow acHeaderRow) txtsz)
  (vla-SetText Objtable 0 0 "Chairs")
  (vla-SetText Objtable 1 0 "Size")
  (vla-SetText Objtable 1 1 "Count")
  (setq obj2 (vlax-ename->vla-object (entlast)))
  (vla-Setcolumnwidth obj2 0 (* 6 txtsz))
  (vla-Setcolumnwidth obj2 1 (* 4.5 txtsz))
  (setq obj2 (vlax-ename->vla-object (entlast)))
  (princ)
)

; By Gile
(defun remove_doubles (lst)
  (if lst
    (cons (car lst) (remove_doubles (vl-remove (car lst) lst)))
  )
)

; By Gile
(defun my-count (a L)
    (cond
    ((null L) 0)
    ((equal a (car L)) (+ 1 (my-count a (cdr L))))
  (t (my-count a (cdr L))))
)

(defun splitss ( / x ent textstr)
  (setq count 0)
  (repeat (setq x (sslength ss))
    (setq ent (ssname ss (setq x (1- x))))
    (if (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
      (setq count (1+ count))
     )
  )
  (repeat (setq x (sslength ss))
    (setq ent (ssname ss (setq x (1- x))))
    (if (= (cdr (assoc 0 (entget ent))) "MTEXT")
	(progn
      (setq textstr (getpropertyvalue ent "Text"))
      (repeat count
        (setq lst (cons (list (distof textstr) textstr) lst))
      )
    )
    )
  )
  (princ)
)

(defun plpts ( / pt)
  (setq pt (getpoint "\nStarting point of selection : "))
  (command "_pline" pt)
  (while (= (getvar "cmdactive") 1 )
    (command (getpoint (getvar 'lastpoint)))
  )
)

; Starts here 

; (defun c:AHsupports ( / cnt lst lst2 lst3 obj2 rownum ss trow txtsz val x oldsnap oldlay)
(defun c:AHsupports ( / )
  (setq lst '())
  
  (setq oldsnap (getvar 'osmode))
  (setvar 'osmode 0)
  (setq oldlay (getvar 'clayer))
  (setvar 'clayer "SUPPORT-TEXT-BANDED")
  
  (command "._-layer" "_off" "*" "Y" "")
  (command "._-layer" "_on" "SUPPORT-TEXT-BANDED,TENDON-BANDED-BACKGROUND" "")
  
  (setq txtsz (getreal "\nEnter text size ")) ; try say 25
  (setq lst '())
  (setq cont "Yes")
  
  (while (= cont "Yes")
  (plpts)
  (setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
  (command "erase" "last" "")
  (setq ss (ssget  "WP" pts (list (cons 0 "MTEXT,LWPOLYLINE")(cons 8 "SUPPORT-TEXT-BANDED,TENDON-BANDED-BACKGROUND"))))
  (splitss)
  (initget 1 "Yes No")
  (setq ans (getkword "\nSelect more Yes No "))
  (if (= ans "No" )(setq cont "No"))
  )
  (setq but 1)
  
  (setq lst (vl-sort lst '(lambda (i j) (< (car i)(car j)))))
  (setq lst3 '())
  (setq lst2 (remove_doubles lst))
  (princ lst2)
  (foreach val lst2
    (setq cnt (my-count val lst))
    (setq lst3 (cons (list val cnt) lst3))
  )
  
  (command "._-layer" "_on" "*" "")
  (command "-layer" "M" "Table" "")
  (AH:table_make 2 txtsz)
  
  (setq rownum (vla-get-rows obj2))
  (setq count 0)
  (repeat (setq x (length lst3))
    (vla-InsertRows obj2 rownum (vla-GetRowHeight obj2 (- rownum 1)) 1)
    (setq trow (nth (setq x (1- x)) lst3))
    (vla-SetText Obj2 rownum 0 (cadr (car trow)))
    (vla-SetText Obj2 rownum 1 (rtos (cadr trow) 2 0))
	(setq count (+ count (cadr trow)))
	(setq rownum (1+ rownum))
  )
  (setq rownum (vla-get-rows obj2))
  (vla-InsertRows obj2 rownum (vla-GetRowHeight obj2 (- rownum 1)) 1)
  (vla-SetText Obj2 rownum 0 "Total")
  (vla-SetText Obj2 rownum 1 (rtos count 2 0))
  (vla-SetTextHeight obj2 (+ acDataRow acHeaderRow acTitleRow) txtsz)
  (vla-SetAlignment obj2 acDataRow acMiddleCenter)
  
  (setvar 'osmode oldsnap)

  (alert "To run again type AHsupports")
)
(c:AHsupports)

 

Please look at movie for example of how to select.

0 Likes
Message 38 of 53

israelU7LZU
Participant
Participant

Good day Sea-Haven

 

Thank you for the updated Lisp. I tried it and it seems like it would work if it wasn't because when I go to select the area and create my boundaries, I will not let me choose "C" to close the selection area... what could possible be doing wrong? I tried in different drawings and I get the same result. 

 

israelU7LZU_0-1788795689667.png

 

 

0 Likes
Message 39 of 53

Sea-Haven
Mentor
Mentor

That is odd as I used "C" as last pick prompt. Or just press Enter, will have another look.

 

There may be a better way to select will try again.

0 Likes
Message 40 of 53

israelU7LZU
Participant
Participant

I know it works for you, I just dont know what Im doing wrong. let me try pressing enter instead

 

0 Likes