Author Topic: Cut a text into pieces  (Read 2063 times)

0 Members and 1 Guest are viewing this topic.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Cut a text into pieces
« 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 :
Code: [Select]
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,
Code: [Select]
(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:
Code: [Select]
6x20Is there any idea ????
Regards

Tharwat

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Cut a text into pieces
« Reply #1 on: July 17, 2010, 10:31:48 AM »
Hi,

something like this ?

Code: [Select]
(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"
Speaking English as a French Frog

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Cut a text into pieces
« Reply #2 on: July 17, 2010, 11:16:15 AM »
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

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Cut a text into pieces
« Reply #3 on: July 17, 2010, 11:19:44 AM »
(foo "2\"x4\"" 1 1) returns "2x4"
Speaking English as a French Frog

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Cut a text into pieces
« Reply #4 on: July 17, 2010, 11:53:10 AM »
Still not clear at all to me .....

Thanks

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Cut a text into pieces
« Reply #5 on: July 17, 2010, 12:02:15 PM »
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.
Speaking English as a French Frog

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Cut a text into pieces
« Reply #6 on: July 17, 2010, 12:15:22 PM »
So could you please add your codes to my previous codes that posted earlier   ?????

Many Thanks

Tharwat

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Cut a text into pieces
« Reply #7 on: July 18, 2010, 09:31:58 AM »
Hello gile,
The following Lisp would not complete properly, due to something wrong.
Code: [Select]
(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

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Cut a text into pieces
« Reply #8 on: July 18, 2010, 01:10:48 PM »
Hi,

foo have to be defined before it's called.

Code: [Select]
(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)
Speaking English as a French Frog

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Cut a text into pieces
« Reply #9 on: July 18, 2010, 02:03:32 PM »
Hi,

foo have to be defined before it's called.

That's great gile, you are amazing.

Thanks for your precious time.

Tharwat