TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Tharwat on July 17, 2010, 09:41:51 AM
-
Suppose that I have a text consist of inch values, so how can I divide the text i.g :
2"x4"
so the following '(cdr (assoc 0 Entity)) would get the whole text, And I want to times the first and the second number with specific number,
(setq a (car(entsel"\n Select a text :")))
(setq b (entget a))
(if (member (cdr (assoc 0 b)) '("TEXT" "MTEXT"))
(progn
(setq c (cdr (assoc 1 b)))
(...............
If I want to times the first number with 3 and the second number with 4 and re-insert them
in a text without the inch quotes, So it should become like this:
6x20
Is there any idea ????
Regards
Tharwat
-
Hi,
something like this ?
(defun foo (str x1 x2)
(strcat
(itoa (* x1 (atoi (substr str 1 (vl-string-search "\"" str)))))
"x"
(itoa (* x2 (atoi (substr str (+ 2 (vl-string-search "x" str))))))
)
)
(foo "2\"x4\"" 3 5) returns "6x20"
-
Thanks gile.
But how these functions would return the outcome since it is not times by any number.
I have no idea how it works vl-string-search "....." "......." ???
Any explanation or another way to add it in my previous codes ?
Thanking you
Tharwat
-
(foo "2\"x4\"" 1 1) returns "2x4"
-
Still not clear at all to me .....
Thanks
-
The foo sub requires 3 arguments:
- str the string to process
- x1 the factor to multiply the first number
- x2 the factor to multiply the second number
for the vl-string-search function look at the Developer's Help it will be explain in a better English than I can do.
-
So could you please add your codes to my previous codes that posted earlier ?????
Many Thanks
Tharwat
-
Hello gile,
The following Lisp would not complete properly, due to something wrong.
(setq ss1 (ssget '((0 . "TEXT,MTEXT"))))
(if ss1
(progn
(setq i 0
total 0
n (sslength ss1))
(while (< i n)
(setq str (cdr (assoc 1 (setq e (entget (ssname ss1 i))))))
(setq i (1+ i))
)))
(defun foo (str x1 x2)
(strcat
(itoa (* x1 (atoi (substr str 1 (vl-string-search "\"" str)))))
"x"
(itoa (* x2 (atoi (substr str (+ 2 (vl-string-search "x" str))))))))
(print foo)
(princ)
Best regards
Tharwat
-
Hi,
foo have to be defined before it's called.
(defun foo (str x1 x2)
(strcat
(itoa (* x1 (atoi (substr str 1 (vl-string-search "\"" str)))))
"x"
(itoa (* x2 (atoi (substr str (+ 2 (vl-string-search "x" str))))))
)
)
(setq ss1 (ssget '((0 . "TEXT,MTEXT"))))
(if ss1
(progn
(setq i 0
total 0
n (sslength ss1)
)
(while (< i n)
(setq e (entget (ssname ss1 i)))
(setq str (cdr (assoc 1 e)))
(setq i (1+ i))
(entmod (subst (cons 1 (foo str 3 5)) (assoc 1 e) e))
)
)
)
(print foo)
(princ)
-
Hi,
foo have to be defined before it's called.
That's great gile, you are amazing.
Thanks for your precious time.
Tharwat