Author Topic: Re-type strings in texts to become in sequence  (Read 8682 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Re-type strings in texts to become in sequence
« on: December 22, 2011, 02:34:38 AM »
Hello everyone .

Is it possible to change two lines of texts to become numbered in sequence ?

Example to become like this ..

1   2   3   4
5   6   7   8

The main challenge is with the sequence and not with replacing the strings .

Many thanks for you all .  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Re-type strings in texts to become in sequence
« Reply #1 on: December 22, 2011, 03:28:54 AM »

Give us some (several) examples of before and after.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Coder

  • Swamp Rat
  • Posts: 827
Re: Re-type strings in texts to become in sequence
« Reply #2 on: December 22, 2011, 05:00:23 AM »
Thank you Kerry .

This is what I am trying to do


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Re-type strings in texts to become in sequence
« Reply #3 on: December 22, 2011, 08:28:44 AM »
Looks to be a sorting challenge but without actual sample data it's a guessing game how to implement a solution.

Show us your data by providing a (setq raw_data ...) sequence.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Re-type strings in texts to become in sequence
« Reply #4 on: December 22, 2011, 09:33:04 AM »
'( (5 6 3) (2 1 4 7) ) -> '( (1 2 3) (4 5 6 7) )

??
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Coder

  • Swamp Rat
  • Posts: 827
Re: Re-type strings in texts to become in sequence
« Reply #5 on: December 22, 2011, 11:30:11 AM »
Thank you all .

I made this routine to change strings in texts but as in my previous shown in my previous image but I do not know how .  :oops:

Code: [Select]
(defun c:test (/ entis numb n ssnm en)
  (setq entis (ssget '((0 . "*TEXT"))))
(if entis
  (progn
    (setq numb 0)
    (setq n 0)
  (while
    (setq ssnm (ssname entis numb))
    (setq en (entget ssnm))
    (entmod (subst (cons 1 (itoa (setq n (1+ n)))); <<- I want numbers to be shown as in the previous image
                   (assoc 1 en) en))
    (setq numb (1+ numb))
    )
    )
  )
)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Re-type strings in texts to become in sequence
« Reply #6 on: December 22, 2011, 11:37:33 AM »
Well, as long as you aren't using AutoCAD 2011 you could use acad_strlsort .. or perhaps vl-sort ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Coder

  • Swamp Rat
  • Posts: 827
Re: Re-type strings in texts to become in sequence
« Reply #7 on: December 22, 2011, 11:52:21 AM »
It does not matter what is the string in selected texts because I am going to change their contents to be in sequence as shown in above image .

Thanks

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Re-type strings in texts to become in sequence
« Reply #8 on: December 22, 2011, 01:02:32 PM »
Well, as long as you aren't using AutoCAD 2011 you could use acad_strlsort .. or perhaps vl-sort ...
What's wrong with acad_strlsort in 2011?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Re-type strings in texts to become in sequence
« Reply #9 on: December 22, 2011, 03:06:01 PM »
Well, as long as you aren't using AutoCAD 2011 you could use acad_strlsort .. or perhaps vl-sort ...
What's wrong with acad_strlsort in 2011?

Unless they have fixed it in a service pack, the first drawing you use acad_strlsort in AC11 it works as expected, when you open a second drawing and use it, an error is generated that says "incorrect number of arguments".

The steps to reproduce are:
Open AutoCAD 2011
Ensure SDI is set to 1
At the command prompt type:
Code - Lisp: [Select]
  1. (acad_strlsort (list "d" "a" "b" "C"))

The return value is ("a" "b" "C" "d")

Now open a second drawing in the same session:

At the command prompt type:
Code - Lisp: [Select]
  1. (acad_strlsort (list "d" "a" "b" "C"))

The return value is: Error: incorrect number of arguments.

This issue has been escalated as a bug at Autodesk so they can resolve it .. hopefully they did .. don't use AC2k11 so I don't know.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

nivuahc

  • Guest
Re: Re-type strings in texts to become in sequence
« Reply #10 on: December 22, 2011, 03:31:50 PM »
Well, as long as you aren't using AutoCAD 2011 you could use acad_strlsort .. or perhaps vl-sort ...
What's wrong with acad_strlsort in 2011?

Unless they have fixed it in a service pack, the first drawing you use acad_strlsort in AC11 it works as expected, when you open a second drawing and use it, an error is generated that says "incorrect number of arguments".

The steps to reproduce are:
Open AutoCAD 2011
Ensure SDI is set to 1
At the command prompt type:
Code - Lisp: [Select]
  1. (acad_strlsort (list "d" "a" "b" "C"))

The return value is ("a" "b" "C" "d")

Now open a second drawing in the same session:

At the command prompt type:
Code - Lisp: [Select]
  1. (acad_strlsort (list "d" "a" "b" "C"))

The return value is: Error: incorrect number of arguments.

This issue has been escalated as a bug at Autodesk so they can resolve it .. hopefully they did .. don't use AC2k11 so I don't know.

Worked just fine for me (MEP 2011)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Re-type strings in texts to become in sequence
« Reply #11 on: December 22, 2011, 03:31:55 PM »
Here is a quick modification of another program I wrote to renumber specific attributes in attributed blocks, modified to instead work for Text/MText:

Code - Auto/Visual Lisp: [Select]
  1. ;; Renumber Text  -  Lee Mac  -  2011  -  www.lee-mac.com
  2. ;; Prompts for a selection of Text / MText objects and renumbers the
  3. ;; contents in the chosen direction, based on the text alignment point.
  4.  
  5. (defun c:rt ( / ent inc lst sel srt )
  6.  
  7.     (defun LM:GroupByFunction ( lst fun / tmp1 tmp2 x1 )
  8.         (if (setq x1 (car lst))
  9.             (progn
  10.                 (foreach x2 (cdr lst)
  11.                     (if (fun x1 x2)
  12.                         (setq tmp1 (cons x2 tmp1))
  13.                         (setq tmp2 (cons x2 tmp2))
  14.                     )
  15.                 )
  16.                 (cons (cons x1 tmp1) (LM:GroupByFunction tmp2 fun))
  17.             )
  18.         )
  19.     )
  20.  
  21.     (defun LM:TextInsertion ( elist )
  22.         (if
  23.             (or
  24.                 (eq "MTEXT" (cdr (assoc 0 elist)))
  25.                 (and
  26.                     (zerop (cdr (assoc 72 elist)))
  27.                     (zerop (cdr (assoc 73 elist)))
  28.                 )
  29.             )
  30.             (cdr (assoc 10 elist))
  31.             (cdr (assoc 11 elist))
  32.         )
  33.     )
  34.  
  35.     (if (setq sel (ssget "_:L" '((0 . "MTEXT,TEXT"))))
  36.         (progn
  37.             (initget "LTR RTL TTB BTT")
  38.             (setq *dir*
  39.                 (cond
  40.                     (   (getkword
  41.                             (strcat "\nDirection? [LTR/RTL/TTB/BTT] <"
  42.                                 (setq *dir* (cond ( *dir* ) ("LTR"))) ">: "
  43.                             )
  44.                         )
  45.                     )
  46.                     (   *dir*   )
  47.                 )
  48.             )
  49.             (repeat (setq inc (sslength sel))
  50.                 (setq ent (entget (ssname sel (setq inc (1- inc))))
  51.                       lst (cons (list (LM:TextInsertion ent) ent) lst)
  52.                 )
  53.             )
  54.             (setq inc 0)
  55.             (foreach row
  56.                 (apply 'vl-sort
  57.                     (cond
  58.                         (   (member *dir* '("LTR" "RTL"))
  59.                             (if (eq "LTR" *dir*)
  60.                                 (setq srt (function (lambda ( a b ) (< (caar a) (caar b)))))
  61.                                 (setq srt (function (lambda ( a b ) (> (caar a) (caar b)))))
  62.                             )
  63.                             (list
  64.                                 (LM:GroupByFunction lst (lambda ( a b ) (equal (cadar a) (cadar b) 0.1)))
  65.                                 (function (lambda ( a b ) (> (cadaar a) (cadaar b))))
  66.                             )
  67.                         )
  68.                         (   (member *dir* '("TTB" "BTT"))
  69.                             (if (eq "TTB" *dir*)
  70.                                 (setq srt (function (lambda ( a b ) (> (cadar a) (cadar b)))))
  71.                                 (setq srt (function (lambda ( a b ) (< (cadar a) (cadar b)))))
  72.                             )
  73.                             (list
  74.                                 (LM:GroupByFunction lst (lambda ( a b ) (equal (caar a) (caar b) 0.1)))
  75.                                 (function (lambda ( a b ) (< (caaar a) (caaar b))))
  76.                             )
  77.                         )
  78.                     )
  79.                 )
  80.                 (foreach item (vl-sort row srt)
  81.                     (entmod
  82.                         (subst
  83.                             (cons  1 (itoa (setq inc (1+ inc))))
  84.                             (assoc 1 (cadr item))
  85.                             (cadr item)
  86.                         )
  87.                     )
  88.                 )
  89.             )
  90.         )
  91.     )
  92.     (princ)
  93. )

Quick Demo:


Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Re-type strings in texts to become in sequence
« Reply #12 on: December 22, 2011, 06:51:54 PM »
Worked just fine for me (MEP 2011)

Like I said, it could have been fixed by now, but Owen Wengard (along with two AutoDesk employees) confirmed the bug.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Coder

  • Swamp Rat
  • Posts: 827
Re: Re-type strings in texts to become in sequence
« Reply #13 on: December 24, 2011, 12:05:44 AM »
Thank you so much Lee , that is fantastic . :-)

You're great .

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Re-type strings in texts to become in sequence
« Reply #14 on: December 24, 2011, 06:31:49 AM »
You're welcome coder, I hope you can learn from the code  :-)