Charpzy Posted September 26, 2023 Posted September 26, 2023 I'm trying to make a script which counts blocks which are named similar, I've created the part which counts the blocks and gets the names etc, im struggling to turn it into a table. I can't find much online which provides info about tables this is my code so far: I'm also trying to style to table so the first two rows are a height of 5, and the rest are 30 as-well as all cells to have a text height of 3 (defun c:SIGN (/ entity-count table insertion-point) (setq ss (ssget '((2 . "MYBLOCKS*")))) (setq entity-count '()) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq modelspace (vla-get-modelspace doc)) (if ss (progn (setq i 0) (repeat (sslength ss) (setq ent (ssname ss i)) (setq i (1+ i)) (setq entity-data (entget ent)) (setq entity-name (cdr (assoc 2 entity-data))) ; Update the count in the list (setq found (assoc entity-name entity-count)) (if found (setq count (+ 1 (cdr found))) (setq count 1) ) (if found (setq entity-count (subst (cons entity-name count) found entity-count)) (setq entity-count (cons (cons entity-name count) entity-count)) ) ) (setq insertion-point (getpoint "\nSpecify insertion point for the table: ")) (setq num-rows (+ 2 (length entity-count))) ; Total rows including header & title (setq table (vla-addtable modelspace insertion-point num-rows 2 30 20)) (vla-settext table 0 0 "Sign Schedule") ;title (vla-settext table 1 0 "Block") ;header (vla-settext table 1 1 "Quantity") ;header (vla-setrowheight table 0 5) (vla-settextheight table 0 3.0) (vla-setrowheight table 1 5) (vla-settextheight table 1 3.0) (vla-update table) ; Fill the table with data (setq row 2) (foreach item entity-count (vla-settextheight table row 3.0) ; Insert the block into the first column cell (setq block-def (vla-item (vla-blocks doc) (car item))) (setq cell (vla-getcell table row 0)) (vla-SetBlockTableRecordId cell (vla-getid block-def)) ; Set the quantity in the second column cell (vla-settext table row 1 (itoa (cdr item))) (setq row (1+ row)) ) ) (prompt "\nNo matching entities found.") ) ) if anyone could help/ give me pointers it would be much appreciated Quote
Steven P Posted September 26, 2023 Posted September 26, 2023 I'm not sure if this will help you? http://www.lee-mac.com/blockcounter.html If not can you post a sample drawing so we can see what you are trying to do? Quote
hosneyalaa Posted September 26, 2023 Posted September 26, 2023 Can you attached example drawing Quote
Charpzy Posted September 26, 2023 Author Posted September 26, 2023 I have managed to make something which lists the signs and the quantities but im wondering if i would be a able to take it a step further style the list/s like: if there is more than 12 individual signs, create a new table to the right of it, im sure i can sort the text part of this and adding in the block to the table, my only issue/worry is trying to style the table to this format and how i would then make it create a new new one if there is more than 12 i have attached the DWG file for reference Example.dwg Quote
BIGAL Posted September 27, 2023 Posted September 27, 2023 (edited) "I can't find much online which provides info about tables" This has been asked so many times and the answer is in the way you Google you need to do like this, "Make table from blocks Autocad lisp" About 187,000 results Ok second answer is "Add block image to Table autocad lisp" 3rd answer is make a table with more columns add the text. Ok now the problem, you need a big look up list as hinted you can have some signs in more than 1 size. Hidden attributes would help you can save the size and type, just set attributes to invisible, but they are there for block counting. A sort of blocks using a list of (name size type.... and so can count the same sign but different sizes. One way around the getting table correct is to do just that and make a custom table in your code checking does it exist. That way all settings are correct. Before everybody jumps in really need you to supply a couple of real block examples, it is very frustrating to have like 5 goes at code because true block names are not there. Really need attributes also or else how know size ? The block names seem odd any reason for that rather than like "STOP" "Warning1" yes I have access to hundreds of signs in some other software. Edited September 27, 2023 by BIGAL 1 Quote
Charpzy Posted September 27, 2023 Author Posted September 27, 2023 Yeah there is a lot online which provide answers, but they are just answers nothing explaining how it works etc, a lot of the 'vla-...' used aren't documented anywhere I could find either so I'm blindly writing code, then any issues I have I'm stuck again I've managed to make something anyhow, but the block names are like that because I'm looking to make a block count on them specific blocks Quote
BIGAL Posted September 28, 2023 Posted September 28, 2023 (edited) If you don't understand the code ask, most people will add explanations line by line. Explaining what is going on. Big list of VLA functions attached then just google what your maybe trying to understand. Sorry no author name in the Autolisp functions. The_Visual_LISP_Developers_Bible.pdf Books such as by Reonaldo Togeros, can get on Kindle as Ebook nice thing is can copy and paste code. List of all vl commands.txt AUTOLISP FUNCTIONS CATOGRIZATION.pdf Edited September 28, 2023 by BIGAL 2 Quote
Recommended Posts
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.