Author Topic: edit duplicate text  (Read 3269 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 194
edit duplicate text
« on: March 30, 2009, 08:59:04 PM »
working in other peoples' drawings, some plans have a couple hundred rooms, and a couple hundred room numbers. the program I am working on uses these room numbers, and I need to be able to count on them being unique. they should BE unique, they are room numbers. but I am finding duplication. I guess someone copied and failed to edit.

I intend to ssget "X" and filter for text on a layer. but I found two "111" s. the best thing to do would probably make one of them "111A", but it's possible that there already is a "111A".

I've read several posts here about DELETING duplicates, but not for editing.

maybe a start would be:

(repeat (- (length pp) 1)
(if (member (car pp) (cdr pp))
(setq dup_lst (list (append dup_lst (car pp))) pp (cdr pp))
(setq pp (cdr pp))
)
)

(foreach a dup_lst
(setq it (ssget "_X" '((0 . "TEXT")(1 . a))))))

)

no, that won't quite work. I haven't even made sure there can be no duplicates in my dup_lst, have I?
any real bright ideas?

roy
Never express yourself more clearly than you are able to think.

Spike Wilbury

  • Guest
Re: edit duplicate text
« Reply #1 on: March 30, 2009, 09:48:46 PM »
take a look at this.... (need to practice my lisping skills... to much dust around here)  and see if helps............. :)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: edit duplicate text
« Reply #2 on: March 30, 2009, 09:49:04 PM »
Quick and even dirtier start point:

Code: [Select]
(defun c:TUnique ( / _PicksetToObjects _Main )

    (defun _PicksetToObjects ( ss )
        (if (eq 'pickset (type ss))
            (mapcar
               '(lambda ( x ) (vlax-ename->vla-object (cadr x)))
                (vl-remove-if '(lambda ( x ) (minusp (car x))) (ssnamex ss))
            )
        )
    )

    (defun _Main ( / text temp1 temp2 count index i j )

        (vl-load-com)

        (foreach object
       
            (vl-sort
                (_PicksetToObjects (ssget "x" '((0 . "text"))))
               '(lambda ( a b ) (< (vla-get-objectid a) (vla-get-objectid b)))
            )

            (setq
                text  (vla-get-textstring object)
                temp1 (strcase text)
                temp2 temp1
                count 0
                i     0
                j     (1+ (strlen text))
            )

            (while (member temp2 index)
                (setq temp2 (strcat temp1 "-" (itoa (setq i (1+ i)))))
            )

            (setq index (cons temp2 index))

            (if (/= temp1 temp2)
                (vla-put-textstring object (strcat text (substr temp2 j)))
            )

        )

        (princ)

    )

    (_Main)

)

Not the most efficient or elegant code but I don't care, long day | tired. However I'll endeavor to fix any errors if you finds 'em or revise given more direction.

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Spike Wilbury

  • Guest
Re: edit duplicate text
« Reply #3 on: March 30, 2009, 09:55:39 PM »
that's a good one Michael...

ufffff.... it was hard for me to put together the code I posted here....  :oops:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: edit duplicate text
« Reply #4 on: March 30, 2009, 09:57:59 PM »
that's a good one Michael...

Thanks Luis, we actually did some things similar. :)

ufffff.... it was hard for me to put together the code I posted here....  :oops:

I don't believe you. :P
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Spike Wilbury

  • Guest
Re: edit duplicate text
« Reply #5 on: March 30, 2009, 10:01:37 PM »
I don't believe you. :P

I know.....

 :angel:


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: edit duplicate text
« Reply #6 on: March 30, 2009, 10:02:35 PM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

curmudgeon

  • Newt
  • Posts: 194
Re: edit duplicate text
« Reply #7 on: March 30, 2009, 11:34:48 PM »
thanks guys - I will give it some study.

morning now - I have gone over it, see that it works. I will use it for the purpose and study it more deeply later.
I am close to getting my head around lambda, but I am not there yet.
and anything that begins with "vl-" is something I would not think of first.

"I have great faith in fools. Self confidence, my friends call it."
Poe
« Last Edit: March 31, 2009, 10:47:20 AM by curmudgeon »
Never express yourself more clearly than you are able to think.