Nikon Posted 20 hours ago Posted 20 hours ago (edited) Good afternoon, everyone. I am trying to select a arrayrect and insert a TEXT with the number of array elements into the drawing. But the array is not selected. How do I set the array selection correctly? (defun c:CountElemArrayrect (/ ss n pt) (princ "Select a arrayrect: ") (setq ss (ssget '((0 . "ARRAY"))) n 0) (if ss (progn (setq n (vla-get-Count (vlax-ename->vla-object (ssname ss 0)))) (princ (strcat "The number of elements in the array: " (itoa n))) (princ "Specify the insertion point of the text: ") (setq pt (getpoint)) (if pt (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 1 (itoa n)) (cons 40 25) ; text height (cons 7 (getvar "TEXTSTYLE")) ) ) ) ) ) (princ) ) Β Β Edited 20 hours ago by Nikon Quote
Lee Mac Posted 18 hours ago Posted 18 hours ago If you inspect the DXF data for a rectangular array (e.g. using my Entity List program, for example), you will see that it is in fact a block reference (INSERT). 1 Quote
Lee Mac Posted 18 hours ago Posted 18 hours ago Consider the following function to obtain the data from the array: (defun LM:arraydata ( ent / enx lst rtn ) (if (and (setq enx (entget ent)) (= "INSERT" (cdr (assoc 0 enx))) (setq lst (vl-some (function (lambda ( x ) (if (and (= 330 (car x)) (= "ACDBASSOCDEPENDENCY" (cdr (assoc 0 (entget (cdr x)))))) (cdr (assoc 330 (entget (cdr x)))) ) ) ) (member '(102 . "{ACAD_REACTORS") enx) ) ) (setq lst (entget lst)) (setq lst (cons nil (member (assoc 1 lst) lst))) ) (while lst (setq rtn (cons (cons (cdadr lst) (cdar (cddddr lst))) rtn) lst (cdddr (cddddr lst)) ) ) ) (reverse rtn) ) Call with the array block reference entity, e.g.: (LM:arraydata (car (entsel))) Β 1 1 Quote
Nikon Posted 16 hours ago Author Posted 16 hours ago (edited) The code writes the same amount for arrays with different numbers of elements... (defun c:ArrCountTxt ( / ent arrData count insPt txtHeight) (prompt "Select a arrayrect: ") (setq ent (car (entsel))) (if (and ent (= "INSERT" (cdr (assoc 0 (entget ent))))) (progn (setq arrData (LM:arraydata ent)) ;; count the number of elements (setq count (length arrData)) (princ (strcat "Number of array elements: " (itoa count))) (prompt "Specify the insertion point of the text: ") (setq insPt (getpoint)) (setq txtHeight 20) (entmake (list (cons 0 "TEXT") (cons 8 (cdr (assoc 8 (entget ent)))) ; (cons 10 insPt) (cons 40 txtHeight) (cons 1 (strcat "Quantity: " (itoa count))) (cons 7 "Standard") (cons 50 0.0) ) ) ) ) (princ) ) (defun LM:arraydata ( ent / enx lst rtn ) (if (and (setq enx (entget ent)) (= "INSERT" (cdr (assoc 0 enx))) (setq lst (vl-some (function (lambda ( x ) (if (and (= 330 (car x)) (= "ACDBASSOCDEPENDENCY" (cdr (assoc 0 (entget (cdr x)))))) (cdr (assoc 330 (entget (cdr x)))) ) ) ) (member '(102 . "{ACAD_REACTORS") enx) ) ) (setq lst (entget lst)) (setq lst (cons nil (member (assoc 1 lst) lst))) ) (while lst (setq rtn (cons (cons (cdadr lst) (cdar (cddddr lst))) rtn) lst (cdddr (cddddr lst)) ) ) ) (reverse rtn) ) Β Edited 16 hours ago by Nikon Quote
Lee Mac Posted 15 hours ago Posted 15 hours ago Did you even look at the data that my function returns? Quote
Nikon Posted 15 hours ago Author Posted 15 hours ago (edited) 54 minutes ago, Lee Mac said: Did you even look at the data that my function returns? DXF data Β ( Β Β (-1 . <Object name: 233aa8f9cf0>) Β Β (0 . "INSERT") Β Β (5 . "17957") Β Β (102 . "{ACAD_REACTORS") Β Β (330 . <Object name: 233aa8f9d80>) Β Β (102 . "}") Β Β (330 . <Object name: 23bc15009f0>) Β Β (100 . "AcDbEntity") Β Β (67 . 0) Β Β (410 . "Model") Β Β (8 . "Hatching") Β Β (100 . "AcDbBlockReference") Β Β (2 . "*U268") Β Β (10 77260.1 54657.3 0.0) Β Β (41 . 1.0) Β Β (42 . 1.0) Β Β (43 . 1.0) Β Β (50 . 0.0) Β Β (70 . 0) Β Β (71 . 0) Β Β (44 . 0.0) Β Β (45 . 0.0) Β Β (210 0.0 0.0 1.0) Β ) Β I've looked at the data, but I need professional help... How can I count elements in an array in lisp? Edited 14 hours ago by Nikon Quote
GLAVCVS Posted 13 hours ago Posted 13 hours ago If you post an example drawing, maybe someone else will be encouraged to join the conversation. Quote
Nikon Posted 13 hours ago Author Posted 13 hours ago 18 minutes ago, GLAVCVS said: If you post an example drawing, maybe someone else will be encouraged to join the conversation. Β number of array elements.dwg Quote
GLAVCVS Posted 10 hours ago Posted 10 hours ago (defun c:CountElemArrayrect (/ ss n pt ent le dameFFCC) (defun dameFFCC (ent / items rows cont cols filas) (foreach l (entget (cdr (assoc 330 (entget (cdr (assoc 330 (entget ent))))))) (cond (items (if (= (setq cont (+ (if cont cont 0) (if (= (car l) 90) 1 0))) 3) (setq cols (cdr l) items nil cont nil))) (rows (if (= (setq cont (+ (if cont cont 0) (if (= (car l) 90) 1 0))) 3) (setq filas (cdr l) rows nil cont nil))) ((= (car l) 1) (if (= (cdr l) "Items") (setq items T) (if (= (cdr l) "Rows") (setq rows T)) ) ) ) ) (if (and filas cols) (* filas cols)) ) (princ "Select a arrayrect: ") ;;; (setq ss (ssget '((0 . "ARRAY"))) ;;; n 0) (if (and (setq ent (car (entsel))) (= (cdr (assoc 0 (setq le (entget ent)))) "INSERT") (= "ACDBASSOCDEPENDENCY" (cdr (assoc 0 (entget (cdr (assoc 330 le))))))) (progn (setq n (dameFFCC ent)) ;;; (vla-get-Count ;;; (vlax-ename->vla-object (ssname ss 0)))) (princ (strcat "The number of elements in the array: " (itoa n))) (princ "Specify the insertion point of the text: ") (setq pt (getpoint)) (if pt (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 1 (itoa n)) (cons 40 25) ; text height (cons 7 (getvar "TEXTSTYLE")) ) ) ) ) ) (princ) ) Β 1 Quote
GLAVCVS Posted 10 hours ago Posted 10 hours ago This is the first time Iβve ever done an βautopsyβ on an object like this. Iβve carefully extracted what seemed to me to be the information I was looking for. So I must say: DRIVE CAREFULLY AND RESPECT ALL STOP SIGNS. 1 1 Quote
GLAVCVS Posted 10 hours ago Posted 10 hours ago P.S.: This is just my two cents β though to be honest, itβs probably counterfeit 1 2 Quote
Lee Mac Posted 10 hours ago Posted 10 hours ago (edited) 5 hours ago, Nikon said: I've looked at the data, but I need professional help... How can I count elements in an array in lisp? Β No, I mean the data returned by my (LM:arraydata) function - you just assumed you should use the length of the list, without actually checking what the list contains. Edited 10 hours ago by Lee Mac 1 Quote
Nikon Posted 2 hours ago Author Posted 2 hours ago (edited) 8 hours ago, GLAVCVS said: P.S.: This is just my two cents β though to be honest, itβs probably counterfeit This fake is worth more than two cents.Β Β The code works the way I wanted it to. Thanks!Β Β But I don't understand why I should drive carefully.Β Β Edited 1 hour ago by Nikon 1 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.