Lisp Question regarding obtaining parts of a String

Discussion in 'AutoCAD' started by Mr. B, Feb 25, 2006.

  1. Mr. B

    Mr. B Guest

    Sure. Please do that.

    Regards,

    BruceF
     
    Mr. B, Feb 26, 2006
    #21
  2. Mr. B

    Kitty Guest

    Hmmm, now you guys got me puzzled. I remember renaming many many
    xrefed, bound and exploded lsayers back in the day when we were limited
    to (I think 32) characters in a layer name... what was that, R13 and
    R14...
    Don't recall having trouble with dollar signs.
    If I can sneak some time over next few days I'll have a look at it...
    Can't promise I'll have time to get to the bottom of it.
     
    Kitty, Feb 27, 2006
    #22
  3. Mr. B

    Mr. B Guest

    I tried it just now... not an issue. My test strings were like:
    AAA$aaa
    AAA$bbb
    AAA$ccc

    And I got rid of the AAA$ part no problemo...
    This has happened to me. All you can do when you get a duplicate layer name
    is to manually change them if you can't find a string to replace.
    If you have a lot of drawings to do, the easiest thing I could think of is to
    have a Lisp routine to rename the layers for you .

    (Defun C: ChgLyr ( )

    (if (TblSearch "Layer" "CurrName")
    (command "-Rename" Layer" "CurrName" "NewName")
    ) ; if

    (princ)
    ) ; defun


    You have the above table search for Each Layer you want to change. CurrName
    is your Existing Layer name. NewName is your New Layer name.

    Then just run this for each of your drawings and voila'... It is a basic IF
    THEN kind of statement.

    If the Layer does not exist, nothing happens.

    This is a bit harder. But if you have a lot of drawings, I think your up
    front work will help out if they all have similar layers (and especially if
    you know you'll get more drawings from where those ones you have came from).

    Regards,

    BruceF
     
    Mr. B, Feb 27, 2006
    #23
  4. Mr. B

    Mr. B Guest

    I think it is a duplicate layer issue. I don't have any problems with $
    symbols.

    Regards,

    BruceF
     
    Mr. B, Feb 27, 2006
    #24
  5. Mr. B

    Kitty Guest

    Yea, I'm inclined to think in that direction too...
     
    Kitty, Feb 27, 2006
    #25
  6. Mr. B

    Kitty Guest

    Okay, I found the lisp... I still use it ;)
    But for the life of me, I don't remember what was what in it... well,
    in 5 minutes or less. I used to do a lot more lisping few years back,
    i'm starting to forget things :(
    Mind you, this is not for layers, but to search and replace regular
    acad text.

    ;search and replace text - written circa 1998 by CB
    (defun C:EDT (/ adj p l n e os as ns st s nsl osl sl si chf chm)
    (setq p (ssget)) ;Select objects
    (if p (progn ;If any objects selected...
    (setq osl (strlen (setq os (getstring "\nOld string: " t))))
    (setq nsl (strlen (setq ns (getstring "\nNew string: " t))))
    (setq l 0 chm 0 n (sslength p))
    (setq adj
    (cond ((/= osl nsl) (- nsl osl))
    (T nsl)
    )
    )
    (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 adj))
    ))
    (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 chm)
    (princ " text lines.")
    (terpri)
    )
     
    Kitty, Feb 27, 2006
    #26
  7. Mr. B

    Dr Fleau Guest

    Dr Fleau, Feb 27, 2006
    #27
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.