Riccardo_Ferrari Posted July 5, 2020 Posted July 5, 2020 I have tried the program Count.lsp link http://www.lee-mac.com/blockcounter.html (by Lee Mac) I have few AutoLisp knowledge and I tried to modify your soft for my own only use as follow, but I fault: I have a lot of blocks (many, last time I had 3.000 block) each of them contains with mtext (very simple mtext, it could be a text, ma became as mtext) on three different layer (example I’m seeing now : 968, pf, 2.337, two are numeric, one alphabetic) and a point, the coordinates of the point are also the insertion of the block. I attach the example. I need to make a table with, on each line, the three text and the coordinates of the point. Is it possible? Begging your pardon for my English Riccardo Ferrari Point-Block.Dwg Quote
BIGAL Posted July 6, 2020 Posted July 6, 2020 It would be way easy if the text was attributes need to pull apart each entity of the block and check is *text, if so retrieve value, insertion point is easy. Need to think about it. Sort on pt number ? Quote
Riccardo_Ferrari Posted July 6, 2020 Author Posted July 6, 2020 (edited) 4 hours ago, BIGAL said: It would be way easy if the text was attributes need to pull apart each entity of the block and check is *text, if so retrieve value, insertion point is easy. Need to think about it. Thank you for the answer, but the text isn’t attributed. In others cases I found data (text or numerical or any) checking then dxf database (or as it is called) of the entity. The long list with (<number> . <something>) I always found what I was looking for. Not in this case. Sorting isn't importan now. I'll sort the tab after Thanks Edited July 6, 2020 by Riccardo_Ferrari Quote
BIGAL Posted July 7, 2020 Posted July 7, 2020 (edited) Try this, but note its hard coded to match your block type and you only provided 1 block sample rather than a few also the blocks are tiny messing with the table not sure about that. I tested on copies of the 1 block. There appears also to be a NULL string in block. https://www.cadtutor.net/forum/topic/70795-block-table/ ; make a table of text entities inside a block not attributes. ; By AlanH info@alanh.com.au ; July 2020 ; ah:maketable is a library function and can be used in other code. (defun AH:blktxtents ( / obj x yz k lst2 lst ) (vl-load-com) ;(setq numrows 3) ;(setq numcolumns 6) ;(setq rowheight 0.5) ;(setq colwidth 0.5) (defun AH:maketable ( numrows numcolumns rowheight colwidth / pt1 ) (setq curspace (vla-get-modelspace doc)) (setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table: "))) (setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth)) (vla-settext objtable 0 0 "Heading 1") (vla-settext objtable 1 0 "No") (vla-settext objtable 1 1 "X") (vla-settext objtable 1 2 "Y") (vla-settext objtable 1 3 "Z") (vla-settext objtable 1 4 "Elev") (vla-settext objtable 1 5 "Desc") ) (defun AH:addlinet (lst / rowcnt rowhgt) (setq rowcnt (vla-get-rows objtable)) (setq rowhgt (vla-getRowHeight objtable 2)) (vla-InsertRows objTable rowcnt rowhgt 1) (vla-settext objtable (- rowcnt 1) 0 (nth 4 lst)) (vla-settext objtable (- rowcnt 1) 1 (rtos (nth 0 lst)2 3)) (vla-settext objtable (- rowcnt 1) 2 (rtos (nth 1 lst) 2 3)) (vla-settext objtable (- rowcnt 1) 3 (rtos (nth 2 lst)2 3)) (vla-settext objtable (- rowcnt 1) 4 (nth 6 lst)) (vla-settext objtable (- rowcnt 1) 5 (nth 5 lst)) ) ;; starts here (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq blks (vla-get-blocks doc )) (setq blk (entget (car (entsel "Pick block for layer")))) (ah:maketable 3 6 5 50) (setq objtable (vlax-ename->vla-object (entlast))) (vla-put-RegenerateTableSuppressed objtable :vlax-true) (setq lay (cdr (assoc 8 blk))) (setq ss (ssget (list (cons 0 "INSERT")(cons 8 lay)))) (repeat (setq k (sslength ss)) (setq lst '()) (setq obj (vlax-ename->vla-object (ssname ss (setq k (- k 1))))) (setq ins (vlax-get Obj 'insertionPoint)) (setq lst1 (list (car ins) (cadr ins) (caddr ins))) (setq bname (vla-get-name obj)) (setq lst2'()) (vlax-for block blks (if (= (vla-get-name block) bname) (vlax-for ent block (if (or (= (vla-get-objectname ent) "AcDbMText")(= (vla-get-objectname ent) "AcDbText")) (setq lst2 (cons (vla-get-textstring ent) lst2)) ) ) ) ) (if (/= lst2 nil) (AH:addlinet (append lst1 lst2)) (princ "\nWrong type of block") ) ) (vla-RecomputeTableBlock objtable :vlax-true) (princ) ) (AH:blktxtents) Edited July 9, 2020 by BIGAL 1 Quote
Riccardo_Ferrari Posted July 8, 2020 Author Posted July 8, 2020 On 7/7/2020 at 2:02 AM, BIGAL said: Try this, but note its hard coded to match your block type and you only provided 1 block sample rather than a few also the blocks are tiny messing with the table not sure about that. I tested on copies of the 1 block. There appears also to be a NULL string in block. BIGAL, thank you for the code. It works fine, it is almost the code I was looking for. I would never have been able to write it myself. I would need a text file, but I am able to write it by modifying your code which write the table inside the dwg. I have two question: First: The data are rightly written in the table approximated to the third digit. I had taken a look at the code and the internal data have only five digits instead of the eight usually used by AutoCAD (defun AH:addlinet (lst / rowcnt rowhgt) [from your code] Numbers in the list “lst” have only five digits (after point, obviously) Second: The lisp crash with the message error: ActiveX Server returned an error: Parameter not optional The presence of a block on the same layer, but different from the standard one, causes the crash. You can simply avoid its selection, but it is often in the middle of many others. It happens because some users explode the block, releasing an additional block (the red cross) which is on the same layer I attach a dwg with this second question Thanks again for your excellent work Riccardo Bug-En.Dwg Quote
BIGAL Posted July 9, 2020 Posted July 9, 2020 The number of digits displayed is based on the UNITS setting Acad works at like a 14 digit precision wont go into it explaining. The RTOS function real to string, has 2 Engineering with 3 decimal places 2 0 would give 123, 2 3 123.456 Will have a look at dwg the issue is may need to look at block and see if has text. Fixed added a check has a text. See code above. Added Vl-load-com also For me would replace all blocks for 1 with attributes. Then delete all redundant blocks. . It may be possible will find some other hiccup but post if so. Quote
Riccardo_Ferrari Posted July 18, 2020 Author Posted July 18, 2020 On 7/9/2020 at 9:22 AM, BIGAL said: The number of digits displayed is based on the UNITS setting Acad works at like a 14 digit ... BIGAL, thank you. I saw your answer about digits and I understood. Thanks for the code, too. I got another kind of block, with attributes (i think so) is it possible have the same table? A dwg attached with 5 samples. Riccardo Blocks.Dwg Quote
BIGAL Posted July 19, 2020 Posted July 19, 2020 (edited) Their blocks with attributes so much easier there are many variations of attribute to table out there. Just google. Or try EATTEXT you will need to make a new dxe when asked and untick options on the chooses. Edited July 19, 2020 by BIGAL 1 Quote
Riccardo_Ferrari Posted July 26, 2020 Author Posted July 26, 2020 On 7/19/2020 at 3:06 AM, BIGAL said: Their blocks with attributes so much easier there are many variations of attribute to table out there. Just google. Yes, I googled and found some ideas. So I wrote a lisp. It seems to be working. Thank you for your suggestion. I attach the lisp if you want to take a look. Thanks again. Riccardo PT-ATTR.LSP Quote
BIGAL Posted July 27, 2020 Posted July 27, 2020 Just me I use VL now a little easier, so you can use (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname SS (setq x (- x 1))))) (if (= (vla-get-hasattributes obj) :vlax-true) ; checks does block have attributes so can skip a block if no attributes. (foreach att (vlax-invoke obj 'getattributes) (princ (vla-get-textstring att)) ; do your thing here ) ) ) Quote
Riccardo_Ferrari Posted August 6, 2020 Author Posted August 6, 2020 On 7/27/2020 at 2:02 AM, BIGAL said: Just me I use VL now a little easier, so you can use [snip] Thanks a lot, I'll try it. I know little Lisp, even less VL. For example, what is the difference between VL, VLA, VLX. Anyway, besides the easier code (maybe) Is the execution of the programs faster? Riccardo Quote
BIGAL Posted August 6, 2020 Posted August 6, 2020 I am no expert on speed command is slowest, it depends on what your trying to do did something with 700 objects took a couple of minutes did it another way took 2 seconds. 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.