help making an lisp to editing a lot of text objets

help making an lisp to editing a lot of text objets

m_skullman
Participant Participant
1,275 Views
8 Replies
Message 1 of 9

help making an lisp to editing a lot of text objets

m_skullman
Participant
Participant

hi everyone 
I work in mapping and we have a lot of houses blocks where the houses are numered from 00 to 99 (barely blocks reaches the 50 houses) but now we have to add numbers before and after to the number of the house

im not good in programing, until now only I've able to write a lsp file who makes new layer and copy the objets than Im onterested on to the new layer, but I can't find a way to make the code to edit all the new text objets and add digits before and after to the text that they content

 

Im interested on objets that are only numbers, because some houses are not registered yet so we use a dot (.) on them 



test 1.pngtest 2.png

0 Likes
Accepted solutions (1)
1,276 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

@m_skullman wrote:

.... now we have to add numbers before and after to the number of the house
.... I've able to write a lsp file who makes new layer and copy the objets ... to the new layer, but ... the code to edit all the new text objets and add digits before and after to the text that they content ....


Something like this, in simplest terms [untested]:

 

(defun C:TEXTADDPRESUF (/ ss n edata txt)

  (if (setq ss (ssget "_X" '((0 . "TEXT") (8 . "YourNewLayerName"))))

    (repeat (setq n (sslength ss)); then

      (setq edata (entget (ssname ss (setq n (1- n))))); get entity data

      (if (wcmatch (setq txt (cdr (assoc 1 edata))) "#,##"); 1- or 2-digit numbers only

      (entmod

        (subst

          (cons 1 (strcat "YourPrefix" txt "YourSuffix")); expanded content

          (assoc 1 edata); in place of original

          (edata)

        ); subst

      ); entmod
    ); repeat

  ); if

  (princ)

); defun

 

That assumes they're all plain  Text, not Mtext, but that can be accommodated if necessary.  And it can be made to ask for the prefix and suffix parts, rather than having them built in, but see whether the above works first.

Kent Cooper, AIA
0 Likes
Message 3 of 9

m_skullman
Participant
Participant

sorry bro, but I get the message "error: malformed list on input" 
I also get the same error mesage when I was trying something else 
btw, can set a dialog box on:

(cons 1 (strcat "YourPrefix" txt "YourSuffix")); expanded content
where "YourPrefix" allow me to imput the number of the block? 
"YourSuffix" is only 000000 (six zeros)

0 Likes
Message 4 of 9

dlanorh
Advisor
Advisor

Try this. There was a missing closing bracket.

 

(defun C:TEXTADDPRESUF (/ ss n edata txt)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (8 . "YourNewLayerName"))))
    (repeat (setq n (sslength ss)); then
      (setq edata (entget (ssname ss (setq n (1- n))))); get entity data
      (if (wcmatch (setq txt (cdr (assoc 1 edata))) "#,##"); 1- or 2-digit numbers only
        (entmod
          (subst
            (cons 1 (strcat "YourPrefix" txt "YourSuffix")); expanded content
            (assoc 1 edata); in place of original
            (edata)
          ); subst
        ); entmod
      ); if
    ); repeat
  ); if
  (princ)
); defun

I am not one of the robots you're looking for

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@dlanorh wrote:

Try this. There was a missing closing bracket.

 ....


Thanks for noticing -- that's what I get for not testing....

Kent Cooper, AIA
0 Likes
Message 6 of 9

m_skullman
Participant
Participant

hi, sorry fo the laste reply but I wasnt on my office so I wasnt able to answer
I've tested the program but it dont do anything.  I added the code that I got until now and works but still without doing anyting, 

this is the code that I got and work

defun C:miprog()  
(command "._layer" "_M" "clave_catastral" "")
(setq TargEnt (car (entsel "\nSelect object on layer to select: ")))
 (setq TargLayer (assoc 8 (entget TargEnt)))
 (sssetfirst nil (ssget "_X" (list TargLayer)))
 (setq curlay (getvar "clayer"))
      (setq ss1 (ssget))
      (command "copy" ss1 "" "0,0" "0,0")
      (command "chprop" "p" "" "layer" curlay "lt" "bylayer" "s" "1.0"
  (princ)
); defun

unti now this creates a new layer and makes a copy from all  the objets in a layer from one that I choose to the new one

 

now, I was working with this code (Is not mine I took it from somewhere) 

(defun C:miprog()  
(command "._layer" "_M" "clave_catastral" "")
(setq TargEnt (car (entsel "\nSelect object on layer to select: ")))
 (setq TargLayer (assoc 8 (entget TargEnt)))
 (sssetfirst nil (ssget "_X" (list TargLayer)))
 (setq curlay (getvar "clayer"))
      (setq ss1 (ssget))
      (command "copy" ss1 "" "0,0" "0,0")
      (command "chprop" "p" "" "layer" curlay "lt" "bylayer" "s" "1.0"
      "")(princ)
   (setq olderr  *error*             
         *error* chgterr
         chm     0)
   (setq p (ssget))                  
   (if p (progn                      
      (while (= 0 (setq osl (strlen (setq os (getstring t "\nOld string: ")))))
            (princ "Null input invalid")
      )
      (setq nsl (strlen (setq ns (getstring t "\nNew string: "))))
      (setq l 0 n (sslength p))
      (while (< l n)                 
         (if (= "TEXT"               
                (cdr (assoc 0 (setq e (entget (ssname p l))))))
            (progn
               (setq chf nil si 1)
               (setq s (cdr (setq as (assoc 1 e))))
               (while (= osl (setq sl (strlen
                             (setq st (substr s si osl)))))
                  (if (= st os)
                      (progn
                        (setq s (strcat (substr s 1 (1- si)) ns
                                        (substr s (+ si osl))))
                        (setq chf t) 
                        (setq si (+ si nsl))
                      )
                      (setq si (1+ si))
                  )
               )
               (if chf (progn        
                  (setq e (subst (cons 1 s) as e))
                  (entmod e)         
                  (setq chm (1+ chm))
               ))
            )
         )
         (setq l (1+ l))
      )
   ))
   (princ "Changed ")                
(princ)
)

this one sent me a dialog box that alow me to insert the text that I want apear in front of all the texts that I just created but the code must beguin with 0, and it dont respect that number, omithtng it, also dont allows me to insert the next 6 zeros after the numbers

as I said Im not good in programing, I just can read the code but Im not able to wirte it or know exactli what it does

0 Likes
Message 7 of 9

m_skullman
Participant
Participant

[sorry for the double post but I wasn't able to edit the previus one]

 

hi, sorry fo the late reply but I wasnt on my office so I wasnt able to test the code before and answer.

I've tested the code but it don't do anything.  I added the code to the one that I got until now but still without doing anyting.

this is the code that I got and work

defun C:miprog()  
(command "._layer" "_M" "clave_catastral" "")
(setq TargEnt (car (entsel "\nSelect object on layer to select: ")))
 (setq TargLayer (assoc 8 (entget TargEnt)))
 (sssetfirst nil (ssget "_X" (list TargLayer)))
 (setq curlay (getvar "clayer"))
      (setq ss1 (ssget))
      (command "copy" ss1 "" "0,0" "0,0")
      (command "chprop" "p" "" "layer" curlay "lt" "bylayer" "s" "1.0"
  (princ)
); defun

unti now this creates a new layer, askes me to choose an objet that I want to copy and  and makes a copy from all  the objets in a the layer from the objet that I choosed to the new one

 

now, I was working with this code (Is not mine I took it from somewhere) 

(defun C:miprog()  
(command "._layer" "_M" "clave_catastral" "")
(setq TargEnt (car (entsel "\nSelect object on layer to select: ")))
 (setq TargLayer (assoc 8 (entget TargEnt)))
 (sssetfirst nil (ssget "_X" (list TargLayer)))
 (setq curlay (getvar "clayer"))
      (setq ss1 (ssget))
      (command "copy" ss1 "" "0,0" "0,0")
      (command "chprop" "p" "" "layer" curlay "lt" "bylayer" "s" "1.0"
      "")(princ)
   (setq olderr  *error*             
         *error* chgterr
         chm     0)
   (setq p (ssget))                  
   (if p (progn                      
      (while (= 0 (setq osl (strlen (setq os (getstring t "\nOld string: ")))))
            (princ "Null input invalid")
      )
      (setq nsl (strlen (setq ns (getstring t "\nNew string: "))))
      (setq l 0 n (sslength p))
      (while (< l n)                 
         (if (= "TEXT"               
                (cdr (assoc 0 (setq e (entget (ssname p l))))))
            (progn
               (setq chf nil si 1)
               (setq s (cdr (setq as (assoc 1 e))))
               (while (= osl (setq sl (strlen
                             (setq st (substr s si osl)))))
                  (if (= st os)
                      (progn
                        (setq s (strcat (substr s 1 (1- si)) ns
                                        (substr s (+ si osl))))
                        (setq chf t) 
                        (setq si (+ si nsl))
                      )
                      (setq si (1+ si))
                  )
               )
               (if chf (progn        
                  (setq e (subst (cons 1 s) as e))
                  (entmod e)         
                  (setq chm (1+ chm))
               ))
            )
         )
         (setq l (1+ l))
      )
   ))
   (princ "Changed ")                
(princ)
)

this one sent me a dialog box that asks me for ol styring and new string, but I dont want replace anything, I need add 6 zero after the numbers and a dialog box that allows me to add 8 numbers before the code
as I said Im not good in programing, I just can read the code but Im not able to wirte it or know exactli what it does

0 Likes
Message 8 of 9

3wood
Advisor
Advisor
Accepted solution

You can also try ALTEXT.

You need add prefix and suffix separately.

 

Add prefix:

altext1.JPG

 

Add suffix:

ALTEXT2.JPG

 

You can even write a formula and use it in ALTEXT to make the whole process automatically, including find  nearby "07-686" as part of prefix.

0 Likes
Message 9 of 9

m_skullman
Participant
Participant

actually I  made all the changes that I need using find comand, (I did manualy  from 01 to 99 adding an "a" before the numbers and 0000000 after to them) then I used another lisp routine to change all "a" letters to the full code houses block one each one

 

@3wood I tried to use your solution but it askes me for a code to use it, so I decided not to use it but looks like was the best solution that anyone could use

 

thanks everyone who helped me

0 Likes