How to extract numbers & place them with Block in ascending order

How to extract numbers & place them with Block in ascending order

Anonymous
Not applicable
1,882 Views
11 Replies
Message 1 of 12

How to extract numbers & place them with Block in ascending order

Anonymous
Not applicable

In CAD file (Numbers.dwg) where I have so many Text. Numbers from that Texts I want to be updated in "BOX" symbol on the place of "XXX". & then that "BOX" symbol will place next to one another in ascending order. Numbers.dwg is the file which I have (text in that files get change everytime & it's quantity is also changing). BOX.dwg is the file in which BOX block is there. "Sample Output.dwg" is the file where I have shown the exact requirement.

 

Example - I will click one by one Text which will extract only numbers and arrange them in ascending order. After that I will click any where on drawing then it will place "BOX" symbol that many times next to next & replace the "XXX" text from BOX symbol to the input numbers in ascending order which I have selected.

0 Likes
Accepted solutions (1)
1,883 Views
11 Replies
Replies (11)
Message 2 of 12

Ranjit_Singh
Advisor
Advisor

maybe something like this for example

(defun c:somefunc  (/ curosmode lst pt1 str)
 (setq curosmode (getvar 'osmode))
 (mapcar '(lambda (x)
           (setq str (cdr (assoc 1 (entget x)))
                 lst (cons (atoi (substr str (+ 2 (vl-string-position (ascii "-") str)))) lst)))
         (vl-remove-if-not '(lambda (x) (= (type x) 'ename))
                           (mapcar 'cadr (ssnamex (ssget '((0 . "TEXT") (1 . "*-*")))))))
 (setq pt1 (getpoint "\nSelect Insertion Point :"))
 (setvar 'osmode 16385)
 (mapcar '(lambda (x)
           (command-s "._-insert" "60-398-4" pt1 1 1 180)
           (entmake (list '(0 . "TEXT")
                          '(100 . "AcDbEntity")
                          '(100 . "AcDbText")
                           (cons 10 pt1)
                          '(40 . 0.135448)
                           (cons 1 (itoa x))
                          '(50 . 1.5708)
                           (cons 7 "Standard")))
           (command-s "._move" (entlast) "" "0,0,0" "-0.03,0.887,0")
           (setq pt1 (mapcar '+ pt1 '(0.197 0 0))))
         (vl-sort lst '<))
 (setvar 'osmode curosmode))
0 Likes
Message 3 of 12

Anonymous
Not applicable

Thanks for the help! It works. But (1)final symbol is get scaled to 0.0394 So again I have to change it's scale to 1. Please refer attached file. Final symbol scale is 0.0394 on this drawing. (2)It doesn't take duplicate number. It keeps only one number if any duplication is there. (3)Is it possible that if my numbers are on another file & I want final symbol on onother file.

Please help.

 

0 Likes
Message 4 of 12

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

Thanks for the help! It works. But (1)final symbol is get scaled to 0.0394 So again I have to change it's scale to 1. Please refer attached file. Final symbol scale is 0.0394 on this drawing. (2)It doesn't take duplicate number. It keeps only one number if any duplication is there. (3)Is it possible that if my numbers are on another file & I want final symbol on onother file.

Please help.

 



Hi @Anonymous, I did not understand the part Final symbol scale is 0.0394, explain a bit more. The below code should take care of 2 and 3.

(defun c:somefunc  ( / ans curosmode lst pt1 str)
  (initget "Yes No")
  (setq ans (getkword "\nWill the blocks be inserted in this drawing [Yes / No]: "))
  (cond	((wcmatch (strcase "Yes") (strcase (strcat ans "*")))
	 (setq curosmode (getvar 'osmode))
	 (getlst)
	 (setq pt1 (getpoint "\nSelect Insertion Point :"))
	 (setvar 'osmode 16385)
	 (mapcar '(lambda (x) (somefuncent x)) (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst '<)))
	 (setvar 'osmode curosmode))
	(t
	 (getlst)
	 (vl-bb-set 'ar.dlist (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst '<)))
	 (princ "\nCall \"somefunc2\" in detination file")))
  (princ))

(defun c:somefunc2  (/ curosmode pt1)
  (setq curosmode (getvar 'osmode))
  (setq pt1 (getpoint "\nSelect Insertion Point :"))
  (setvar 'osmode 16385)
  (mapcar '(lambda (x) (somefuncent x)) (vl-bb-ref 'ar.dlist))
  (setvar 'osmode curosmode))

(defun getlst  ()
  (mapcar '(lambda (x)
	     (setq str (cdr (assoc 1 (entget x)))
		   lst (cons (atoi (substr str (+ 2 (vl-string-position (ascii "-") str)))) lst)))
	  (vl-remove-if-not '(lambda (x) (= (type x) 'ename))
			    (mapcar 'cadr (ssnamex (ssget '((0 . "TEXT") (1 . "*-*"))))))))

(defun somefuncent  (x)
  (command-s "._-insert" "60-398-4" pt1 1 1 180)
  (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 pt1) '(40 . 0.135448) (cons 1 (itoa x)) '(50 . 1.5708) (cons 7 "Standard")))
  (command-s "._move" (entlast) "" "0,0,0" "-0.03,0.887,0")
  (setq pt1 (mapcar '+ pt1 '(0.197 0 0))))
0 Likes
Message 5 of 12

Anonymous
Not applicable

Final result which i get from this command is "60-398-4" symbols with the given numbers in sequence. But when i check properties of "60-398-4" symbol which i get in final result, it shows "Scale X, Y & Z as 0.394". Because of that symbols are very small.

0 Likes
Message 6 of 12

Ranjit_Singh
Advisor
Advisor

You may want to do a screencast explaining the problem. I tried above routine for placing blocks in current drawing as well as in a separate drawing. Both show correct scale for blocks. See below

60-398-4.gif

0 Likes
Message 7 of 12

Anonymous
Not applicable

Please refer attach file. In this file scale is 0.394. In my most of the files it shows scale 0.394.
Please help me to correct this.

0 Likes
Message 8 of 12

Ranjit_Singh
Advisor
Advisor
Accepted solution

Hi @Anonymous. I still cannot mimic the problem. Seems like the problem is in your AutoCAD environment. .0394 is essentially 1/25.4 (converting from mm to inch). Make sure your INSUNITS is set correctly. Mine is set to 2 based on my drawing units. It seems like in your case INSUNITS is set to 0 and thereby allowing INSUNITSDEFSOURCE and INSUNITSDEFTARGET to take control. Set INSUNITS to something other than 0 and see if it helps. See AutoCAD help here. (you can also set it by typing units)

Message 9 of 12

Anonymous
Not applicable

Happy New Year!

The provided programme is helping me in my project. In this programme I am selecting the numbers manually one by one. But now In my drawings I want the numbers only which are with prefix "XBA-". So is it possible that it will search the Text with "XBA-" & then take the searched numbers & then it will go ahead with our recent programme. In this way my time to select the numbers will get minimise.Please help.

0 Likes
Message 10 of 12

Anonymous
Not applicable

Please someone help!

0 Likes
Message 11 of 12

Anonymous
Not applicable

Hello Ranjit Sir,

The provided programme is really helping me in my project. In this programme I am selecting the numbers manually one by one. But now In my drawings I want the numbers only which are with prefix "TBA-". So is it possible that it will search the Text with "TBA-" & then take the searched numbers & then it will go ahead with our recent programme. In this way my time to select the numbers manually will get minimise.
I have tried it by replacing (ssget '((0 . "TEXT") (1 . "*-*"))) with (ssget "_X" (list (0 . "TEXT") (1 . "TBA-*") (cons 410 (getvar 'CTAB))))
But not worked. Please refer attached modified program. If possible please help. Thank you!

 

0 Likes
Message 12 of 12

devitg
Advisor
Advisor

@Anonymous , please state or upload the dwg holding 

I want the numbers only which are with prefix "TBA-"

0 Likes