Update Border Information

Discussion in 'AutoCAD' started by montyzoomer, Jan 9, 2005.

  1. montyzoomer

    montyzoomer Guest

    I really need the help of this group. I need to be able to change the part number of over 600 drawings so I am looking for some clues on how to open a drawing and change the text by doing a look up in an XLS file. The XLS side I can handle but I do not know how to open a drawing in VBA or change an entry in the drawing border.

    I hope someone can help me out, it will be most appreciated.

    Thanks

    Monty
     
    montyzoomer, Jan 9, 2005
    #1
  2. montyzoomer

    Walt Engle Guest

    Why not use a lsp routine that looks for certain key words and replaces them? I have one, if you're interested.
     
    Walt Engle, Jan 9, 2005
    #2
  3. montyzoomer

    montyzoomer Guest

    I would appreciate a copy, can you call lsp routine in VBA

    Thanks

    Monty
     
    montyzoomer, Jan 9, 2005
    #3
  4. montyzoomer

    Walt Engle Guest

    Here it is:

    ; CHGTEXT.LSP
    ; CHANGES TEXT GLOBALLY
    ; This program will replace every occurrence of an "old string" with a
    ; "new string".
    (defun chgterr (s)
    (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
    )
    (setq p nil)
    (setq *error* olderr)
    (princ)
    )

    (defun C:CHGTEXT (/ p l n e os as ns st s nsl osl sl si chf chm olderr)
    (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 chm)
    (princ " text lines.")
    (terpri)
    (setq *error* olderr)
    (princ)
    )
     
    Walt Engle, Jan 9, 2005
    #4
  5. Hi Monty,

    You can call lisp from VBA with the SendCommand. However in pre-R2005
    AutoCAD, you can not reliably return to VBA due to the VBA not knowing when
    the Lisp function is complete. I believe this has been fixed in R2005.

    You would be better off doing the whole exercise in VBA. The search and
    replace bits of your code will only be a few lines.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, Jan 9, 2005
    #5
  6. montyzoomer

    montyzoomer Guest

    Laurie

    Thanks for the information, I would prefer to complete the task in VBA but I only have real experience with normal office applications. What I need to understand is the code method for opening a drawing and then how to search for a string and change it.

    If you can guide me on this I would appreciate it.

    Regards

    Monty
     
    montyzoomer, Jan 10, 2005
    #6
  7. montyzoomer

    GaryDF Guest

    You can use objectdbx to open and change the drawings. Let me know if
    this will work for you, and I can post the code.

    Gary


    number of over 600 drawings so I am looking for some clues on how to open a
    drawing and change the text by doing a look up in an XLS file. The XLS side I can
    handle but I do not know how to open a drawing in VBA or change an entry in the
    drawing border.
     
    GaryDF, Jan 10, 2005
    #7
  8. montyzoomer

    montyzoomer Guest

    Gary,

    I am open to give it a go, would it be possible to E mail the code. My address is



    Thanks for your help

    Regards

    Ian
     
    montyzoomer, Jan 10, 2005
    #8
  9. montyzoomer

    GaryDF Guest

    Sent routine.

    Gary
     
    GaryDF, Jan 10, 2005
    #9
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.