find & replace string in layout names

Discussion in 'AutoCAD' started by martin, Jul 16, 2003.

  1. martin

    martin Guest

    hi,
    I work with a drawings that have certain layout-names, is there a way to
    change a string in those names globally through lisp, for example:
    A01,A02,A03.. to B01,B02,B03...

    martin
     
    martin, Jul 16, 2003
    #1
  2. martin

    SpeedCAD Guest

    Hi...

    I pass a routine to you that allows to change the name you of each LAYOUT, I occupy it for each one, but you can modify it so that he is more automatic...

    CODE:

    (defun c:r-layout (/ lst-layout contar nuevo-nombre)
      (setvar "cmdecho" 0)
      (setq lst-layout (layoutlist))
      (setq contar 0)
      (while (< contar (length lst-layout))
        (setq nuevo-nombre
    (getstring T
    (strcat
    "\nIngrese nuevo nombre para reemplazar Layout <"
    (nth contar lst-layout)
    ">: "
    )
    )
        )
        (command "_.-layout"
    "_r"
    (nth contar lst-layout)
    nuevo-nombre
        )
        (setq contar (1+ contar))
      ) ;_while
      (setvar "cmdecho" 1)
      (prin1)
    ) ;_defun

    Un saludo de SpeedCAD... :)
    CHILE
     
    SpeedCAD, Jul 16, 2003
    #2
  3. martin

    martin Guest

    there seems to be some missing arguments, "error: too few arguments", when
    executing the command...

    martin
     
    martin, Jul 16, 2003
    #3
  4. I modified it a bit. It will not prompt for the new and old strings.

    (defun C:renameLayout (/ layouts)
    (vl-load-com)
    (setq newstr (getstring "\nEnter new string: ")
    oldstr (getstring "\nEnter old string: "))
    (setq layouts (vla-get-layouts
    (vla-get-activedocument
    (vlax-get-acad-object))))
    (vlax-for each layouts
    (cond
    ((/= (vla-get-name each) "Model")
    (vla-put-name each (vl-string-subst newstr oldstr (vla-get-name
    each)))
    )
    )
    )
    (princ)
    )

    --
    Ken Alexander
    Acad2000
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 16, 2003
    #4
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.