A desperate attempt

A desperate attempt

adaptacad
Advocate Advocate
1,030 Views
4 Replies
Message 1 of 5

A desperate attempt

adaptacad
Advocate
Advocate

I have over 1000,000 texts in the layer "apartments" in a drawing.
Is there a way to read the value of the text up to the letter "A"
Insert the block in justification of the texts.
and change the value of the attribute to the correct one.
 
If
the value is less than 6 - Do not insert the block.
6 to 10 -   Value os Atribute 1
11 to 18 - Value os Atribute 2
19 to 26 - Value os Atribute 3
27 to 34 - Value os Atribute 4
35 to 42 - Value os Atribute 5
43 to 50 - Value os Atribute 6
51 to 58 - Value os Atribute 7
59 to 66 - Value os Atribute 8
67 to 74 - Value os Atribute 9
75 to 82 - Value os Atribute 10  [...]
 
I've attached an example of .dwg

0 Likes
Accepted solutions (2)
1,031 Views
4 Replies
Replies (4)
Message 2 of 5

CodeDing
Advisor
Advisor
Accepted solution

@adaptacad ,

 

Try this. Hope it helps.

(defun c:TEST ( / osm cmd ss e eg txt tmp cnt cntGood cntBad num p)
(vl-load-com)
;if no text items, exit routine (if (not (setq ss (ssget "_X" '((0 . "TEXT") (8 . "apartments") (410 . "Model"))))) (progn (prompt "\nNo text objects found on \"apartment\" layer...") (exit)) );if
;prepare for loop (setq osm (getvar 'OSMODE) cmd (getvar 'CMDECHO)) (setvar 'OSMODE (logior 16384 osm)) (setvar 'CMDECHO 0) (setq cnt (sslength ss) cntGood 0 cntBad 0)
;loop through ss (while (>= (setq cnt (1- cnt)) 0) (setq e (ssname ss cnt) eg (entget e) txt (cdr (assoc 1 eg)))
;only continue if we find first letter "A", and initial text is a number (if (and (setq tmp (vl-string-search "A" txt)) (setq txt (substr txt 1 tmp)) (distof txt 2)) (progn (setq num (atoi txt))
;use cond to determine what text will be used in block (cond ((< num 6) (setq num nil)) ((<= 6 num 10) (setq num "1")) (t (setq num (itoa (+ 2 (fix (/ (1- (- num 10)) 8)))))) );cond
;only continue if block is needed and found (if (and num (tblsearch "BLOCK" "highlighter")) (progn (setq p (cdr (assoc 11 eg))) (command "-INSERT" "highlighter" "_scale" 1 p 0) (setpropertyvalue (entlast) "QUANTIDADE" num) (setq cntGood (1+ cntGood)) );progn
;otherwise, it's a bad count ;else (setq cntBad (1+ cntBad)) );if );progn
;otherwise, it's a bad count ;else (setq cntBad (1+ cntBad)) );if
;prep for next iteration (not totally required) (setq txt nil eg nil num nil) );while
;finishing touches/cleanup (setq ss nil) (setvar 'OSMODE osm) (setvar 'CMDECHO cmd) (prompt (strcat "\nCompletion Status:\n" (itoa cntBad) " - Ignored Text Items\n" (itoa cntGood) " - Successful Text Items\n")) (princ) );defun

Best,

~DD

Message 3 of 5

ronjonp
Mentor
Mentor
Accepted solution

Here's another:

(defun c:foo (/ a b d i p s v)
  ;; RJP » 2019-05-30
  (cond	((null (tblobjname "block" "highlighter")) (print "Block 'highlighter' not found!"))
	((setq s (ssget '((0 . "text") (8 . "apartments") (1 . "*Apartments*"))))
	 (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
	 (setq d (vlax-ename->vla-object (cdr (assoc 330 (entget (car s))))))
	 (foreach x s
	   (setq a (cdr (assoc 1 (entget x))))
	   (setq p (cdr (assoc 11 (entget x))))
	   (cond ((> (setq v (atof (substr a 1 (vl-string-search "A" a)))) 6)
		  (if (setq b (vla-insertblock d (vlax-3d-point p) "highlighter" 1. 1. 1. 0.))
		    (vla-put-textstring
		      (car (vlax-invoke b 'getattributes))
		      (itoa (if	(< v 11)
			      1
			      (if (>= (rem (/ v 8.) (fix (/ v 8.))) 0.375)
				(fix (1+ (/ v 8.)))
				(fix (/ v 8.))
			      )
			    )
		      )
		    )
		  )
		 )
	   )
	 )
	)
  )
  (princ)
)
Message 4 of 5

adaptacad
Advocate
Advocate

@ronjonp @CodeDing  Thank you very much. &#x1F60D;

0 Likes
Message 5 of 5

ronjonp
Mentor
Mentor

@adaptacad wrote:

@ronjonp @CodeDing  Thank you very much. &#x1F60D;


You also have a solution HERE too...

0 Likes