1-2-3 to A-B-C

Discussion in 'AutoCAD' started by spencer1971, Sep 15, 2004.

  1. spencer1971

    spencer1971 Guest

    I have written this very simple lisp for updating our standard grid block by picking (1st picked attribute changed to 1, second picked changed to 2 and so on...)

    What would be the best way to do this but change grids alphabetically
    (1st picked attribute changed to A, second picked changed to B and so on...)

    (if (= sn 1) (setq sl A)) seems to be in the right direction I think but im having trouble getting it to work,

    Anyones help would be greatly appreciated,



    (defun c:gridnos (/ sn)
    (setq sn (getint "\nStart Number: "))
    (while sn
    (command "attedit" "y" "*" "*" "*" PAUSE "" "v" "r" sn "")
    (setq sn (1+ sn))
    )
    )


    Thanks
     
    spencer1971, Sep 15, 2004
    #1
  2. spencer1971

    Fatty Guest

    Try this:

    (defun alphet (cnt / m)
    (setq alfavitum '("Ð" "B" "C" "D" "E" "F"
    "G" "etc."))
    (setq m (nth (1- cnt) alfavitum))
    )
     
    Fatty, Sep 15, 2004
    #2
  3. spencer1971

    spencer1971 Guest

    Sorry for my ingorance but I can't see what that does. How do I write that into my lisp?
     
    spencer1971, Sep 15, 2004
    #3
  4. Don't have time to work out the details, but the (chr) lisp function will do
    it:

    (setq letter 65)

    makes A the first character (ASCII code for capital A is 65).

    Apply (chr letter) in place of your sn in the attedit part, to make A the
    text content of the attribute. Then increment it upward with

    (setq letter (1+ letter))

    and go to the next one, etc.

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Sep 15, 2004
    #4
  5. spencer1971

    BillZ Guest

    (defun c:gridnos (/ sn)
    (setq sn (getint "\nStart Number: "))
    (setq alp_lst (list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z")
    )
    (while sn
    (setq new_alp (nth (1- sn) alp_lst)
    )
    ;(command "attedit" "y" "*" "*" "*" PAUSE "" "v" "r" new_alp "")
    (princ "\n ")(princ new_alp)
    (setq sn (1+ sn)
    new_alp (nth sn alp_lst)
    )
    (if (> sn 26)(exit))
    )
    )


    Bill
     
    BillZ, Sep 15, 2004
    #5
  6. spencer1971

    spencer1971 Guest

    Bill, I allready got it using juerg's method..

    Thanks anyway, I did adopt the start letter option from yours, this is what I ended up with

    (defun c:gridlet (/ sn letter)
    (setq letter (getint "\nStart Number: A=1 B-2 ETC... "))
    (setq letter (+ 64 letter))
    (while letter
    (setq sn (chr letter))
    (command "attedit" "y" "*" "*" "*" PAUSE "" "v" "r" sn "")
    (setq letter (1+ letter))
    )
    )

    The only problem is that is if you do not select directly on the attribute is stops working as sn becomes nil. I'd like a way to force the lisp to work until esc. is pressed in case the user misses a pick... Any ideas?
     
    spencer1971, Sep 15, 2004
    #6
  7. spencer1971

    BillZ Guest

    I can't test this idea right now but errno = 52 I believe is for "enter".

    (while (and letter (/= (getvar "errno") 52)))

    Let me know if it works.

    Bill
     
    BillZ, Sep 15, 2004
    #7
  8. spencer1971

    Fatty Guest

    I hope you'll understand me
    I had change your function a lot, it works correct,
    but it change visible attributes only

    (defun c:gridnos (/ sn)
    (defun alphet (cnt / m)
    (setq alfavitum (list "A" "B" "C" "D" "E" "F"
    "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q"
    "R" "S" "T" "U" "V" "W" "X" "Y" "Z")
    )
    (setq m (nth (1- cnt) alfavitum))
    ) ;eof alphet

    ;your function:
    (setq sn (getint "\nStart Number: "))
    (while sn
    ; here put minus symbol before attedit
    ; to ignore "Edit Attributes" dialog window
    (command "-attedit" "y" "*" "*" "*" pause "" "v" "r" (alphet sn) "" "")
    (princ "\n ")(princ (alphet sn))
    (setq sn (1+ sn))

    (if (> sn 26)(exit))
    (princ)
    )
    )

    Fatty ;v)
     
    Fatty, Sep 15, 2004
    #8
  9. spencer1971

    spencer1971 Guest

    I tried with it but couldnt' get it going, Ill have another look later when I have more time and let you know
     
    spencer1971, Sep 15, 2004
    #9
  10. spencer1971

    T.Willey Guest

    Try this. The only thing is it only works with one value entered.

    Tim

    (defun c:CntText (/ cnt1)

    (command "_.undo" "_end")
    (command "_.undo" "_group")
    (vl-load-com)
    (setq cnt1 (getstring "\n Enter starting string: "))
    (if cnt1
    (AddString cnt1)
    )
    (command "_.undo" "_end")
    (princ)
    )

    (defun AddString (num1 / ent1 ob1)

    (setvar "errno" 0)
    (while (and (not ent1) (/= (getvar "errno") 52))
    (setq ent1 (nentsel "\n Select text/attribute to change: "))
    (if ent1
    (progn
    (setq ob1 (MakeX (car ent1)))
    (PutX ob1 'Textstring num1)
    (setq num1 (chr (1+ (ascii num1))))
    (setq ent1 nil)
    )
    )
    )
    )

    (defun MakeX (entname)
    (vlax-ename->vla-object entname)
    )

    (defun PutX (object prop val)
    (if (vlax-property-available-p object prop T)
    (vlax-put object prop val)
    )
    )
     
    T.Willey, Sep 15, 2004
    #10
  11. spencer1971

    GaryDF Guest

    Great routine.
    Question, how could you modify the code to also add a zero before digits 1 thur 9
    to the text string value.


    (strcat 0 cnt1)

    Gary
     
    GaryDF, Sep 15, 2004
    #11
  12. spencer1971

    T.Willey Guest

    You can try this.

    Old
    (setq ob1 (MakeX (car ent1)))
    (PutX ob1 'Textstring num1)
    (setq num1 (chr (1+ (ascii num1))))

    New
    (setq ob1 (MakeX (car ent1)))
    (if (> 49 (ascii num1) 57)
    (PutX ob1 'TextString (strcat "0" num1))
    (PutX ob1 'Textstring num1)
    )
    (setq num1 (chr (1+ (ascii num1))))

    Untested, but I think it should work.
    Tim
     
    T.Willey, Sep 15, 2004
    #12
  13. spencer1971

    GaryDF Guest

    hummm............I cant get it to work
    stops after the first pass, without strcat the zero

    (if (> 49 (ascii num1) 57)

    I tried
    (if (and (> 49 (ascii num1))(< (ascii num1) 57))

    Gary
     
    GaryDF, Sep 15, 2004
    #13
  14. spencer1971

    T.Willey Guest

    Gary,
    This should work now.

    Tim

    (defun AddString (num1 / ent1 ob1)

    (setvar "errno" 0)
    (while (and (not ent1) (/= (getvar "errno") 52))
    (setq ent1 (nentsel "\n Select text/attribute to change: "))
    (if ent1
    (progn
    (setq ob1 (MakeX (car ent1)))
    (if (<= 49 (ascii num1) 57)
    (PutX ob1 'TextString (strcat "0" num1))
    (PutX ob1 'Textstring num1)
    )
    (setq num1 (chr (1+ (ascii num1))))
    (setq ent1 nil)
    )
    )
    )
    )
     
    T.Willey, Sep 15, 2004
    #14
  15. spencer1971

    GaryDF Guest

    Thanks..I learned a lot, by studing your code.

    Gary
     
    GaryDF, Sep 15, 2004
    #15
  16. spencer1971

    T.Willey Guest

    Cool glad I could help.

    Tim
     
    T.Willey, Sep 15, 2004
    #16
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.
Similar Threads
There are no similar threads yet.
Loading...