I have a string "3.36+4.67+7.04+9.85-9.14=34.06"
How to use "entsel" in the "4.67" nearby and extract "4.67" out?
Any help would be greatly apprieciated!
|
I have a string "3.36+4.67+7.04+9.85-9.14=34.06"
How to use "entsel" in the "4.67" nearby and extract "4.67" out?
Any help would be greatly apprieciated!
If it is a string, you would use the substr function, not entsel. However, if you need to first select an object that contains that string, you would use the entsel function first.
The entsel function returns a list. The first element of the list is the entity name of the object selected. The second element is the point the user picked. However, if the user misses an object when selecting, the function returns nil. This means you will need to verify the returned value is not nil before you start requesting data out of the returned value.
You can select the first item, which is the entity name, in the list using the car function. Once you have the entity name, you can either go the straight AutoLISP path or move over to the Visual LISP path to get the text string.
If you have a technical question, please find the appropriate forum and ask it there.
You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
jUSt
I want to use "entsel" function (the point-second element of the retunn list)
to pick the part of string,may be the point is at the "9.85" nearby and extract "9.85" out
Are you thinking of the cadr function? That will return the second element in a list. It will not return the second number in a string.
If you have a technical question, please find the appropriate forum and ask it there.
You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
jUSt
Give this a try:
Code:(defun c:FOO (/ BB:Parser ss) (defun BB:Parser (char string / i segments segment) ;; Example: (BB:Parser "-" "dd-mm-yyyy") ;; Returns: ("dd" "mm" "yyyy") (while (setq i (vl-string-search char string)) (setq segments (cons (setq segment (substr string 1 i)) segments)) (setq string (substr string (+ 2 i))) ) (reverse (cons string segments)) ) (if (and (princ "\nSelect text to extract second real number: ") (setq ss (ssget ":S:E" '((0 . "MTEXT,TEXT") (1 . "*#*+*#*=*#*")))) ) (prompt (strcat "\nThe second real number is: " (cadr (BB:Parser "+" (cdr (assoc 1 (entget (ssname ss 0)) ) ) ) ) ) ) ) (princ) )
Last edited by BlackBox; 2014-04-30 at 05:36 PM.
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
Maybe this simple code can help you for a start...
Code:(defun c:pickchar ( / e p el ip txt k char ) (while (not (eq (cdr (assoc 0 (entget (car (setq e (entsel "\nPick char inside text entity")))))) "TEXT"))) (setq p (cadr e)) (setq el (entget (car e))) (setq ip (cdr (assoc 10 el))) (setq txt (cdr (assoc 1 el))) (setq k 0) (while (< (+ (car ip) (car (cadr (textbox (subst (cons 1 (substr txt 1 (setq k (1+ k)))) (assoc 1 el) el))))) (car p))) (setq char (substr txt k 1)) (terpri) (prompt (strcat "\n\"" char "\"")) (princ) )
Nice idea Marko
Here's a quick mod to accommodate the OP's request
How to use "entsel" in the "4.67" nearby and extract "4.67" out?Granting the user select the first number of the target value. i.e 4 of 4.67 and not "6", "7" or even "."Code:(defun c:pickchar ( / e p el ip txt k char ) (while (not (eq (cdr (assoc 0 (entget (car (setq e (entsel "\nPick char inside text entity")))))) "TEXT"))) (setq p (cadr e)) (setq el (entget (car e))) (setq ip (cdr (assoc 10 el))) (setq txt (cdr (assoc 1 el))) (setq k 0) (while (< (+ (car ip) (car (cadr (textbox (subst (cons 1 (substr txt 1 (setq k (1+ k)))) (assoc 1 el) el))))) (car p))) (setq char (substr txt k 1)) (while (and (setq nxt (substr txt (setq k (1+ k)) 1)) (and (/= (ascii nxt) 47)(< 45 (ascii nxt) 58))) (setq char (strcat char nxt))) (terpri) (prompt (strcat "\n\"" char "\"")) (princ) )
Have time to kil....
<Not Thoroughly tested> [i'll come back tomorrow to improve the coding]Code:(defun c:pickchar (/ _allowed _track e p el ip txt k char pr sf) (defun _allowed (n)(and (/= n 47) (< 45 n 58))) (defun _track (str ch sym n / nxt) (while (and (setq n (sym n)) (> n 0) (setq nxt (substr str n 1)) (_allowed (Ascii nxt)) ) (setq ch (if (eq 1+ sym) (strcat ch nxt)(strcat nxt ch))) ) ch ) (while (not (eq (cdr (assoc 0 (entget (car (setq e (entsel "\nPick char inside text entity"))) ) ) ) "TEXT" ) ) ) (setq p (cadr e)) (setq el (entget (car e))) (setq ip (cdr (assoc 10 el))) (setq txt (cdr (assoc 1 el))) (setq k 0) (while (< (+ (car ip) (car (cadr (textbox (subst (cons 1 (substr txt 1 (setq k (1+ k)))) (assoc 1 el) el ) ) ) ) ) (car p) ) ) (setq char (substr txt k 1)) (setq char (if (_allowed (ascii char)) (strcat (if (/= char (setq pr (_track txt char 1- k))) pr char) (if (/= char (setq sf (_track txt char 1+ k))) (substr sf 2) "")) char) ) (terpri) (prompt (strcat "\n\"" char "\"")) (princ) )