maahee Posted June 23 Posted June 23 (defun c:Autoalpha (/ pt index alphabet) (setq alphabet '("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" ) ) ; Alphabet string (setq index 0) (while (setq pt (getpoint "\nPick point: ")) (setq letter (nth index alphabet)) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq index (1+ index)) ) ) Modified code after the letter A to Z should follow this format: 1. Use combinations such as AA, AB, AC, ..., AZ, then BA, BB, BC, ..., Bz. 2. Add a numerical prefix or suffix to each letter combination. 3. The numerical prefix or suffix can be either constant or variable. Quote
Tsuky Posted June 23 Posted June 23 Here is an example of a function that might be right for you. Command:BlockTC_POINTAtt2Vtx If this seems correct to you after trying, you can get the function: (defun inc_txt (....)); usage: (inc_txt "arg_string") to insert it after adaptation, in your code ... BlockTC_POINTAtt2Vtx(en).lsp Quote
Saxlle Posted June 23 Posted June 23 3 hours ago, maahee said: 3. The numerical prefix or suffix can be either constant or variable. Can you describe more about this, part when the numerical prefix or suffix are changable? 1 Quote
maahee Posted June 23 Author Posted June 23 50 minutes ago, Saxlle said: Can you describe more about this, part when the numerical prefix or suffix are changable? The numerical prefix or suffix is changeable Quote
Saxlle Posted June 23 Posted June 23 Something like this? (defun c:Autoalpha (/ alphabet index increment index_copy num_pref_suffix answ_1 answ_2 num_pref_suffix const letter) (setq alphabet '("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" ) ) ; Alphabet string (setq index 0 increment 0 index_copy 0 num_pref_suffix 1 ) (initget 1 "Yes No") (setq answ_1 (getkword "\nDo you want to add a prefix or suffix to letters? [Yes/No]")) (if (= answ_1 "Yes") ; 1. progn (progn (initget 1 "Prefix Suffix") (setq answ_2 (getkword "\nDo you want a prefix or suffix? [Prefix/Suffix]")) ;;; (initget 1 "1 2 3 4 5 6 7 8 9 10") ;;; ;;; (setq num_pref_suffix (getkword "\nChoose the numerical prefix or suffix? [1/2/3/4/5/6/7/8/9/10]")) (initget "Constant cHangeable") (setq const (getkword "\nDo you want the numerical prefix or suffix to be Constant or Changeable? [Constant/cHangeable]")) ; main cond start (cond ; 1. cond ((and (= answ_2 "Prefix") (= const "Constant")) (while (setq pt (getpoint "\nPick point: ")) (cond ((< index (length alphabet)) (setq letter (nth index alphabet)) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq index (1+ index)) ) ((>= index (length alphabet)) (if (< increment (length alphabet)) (progn (setq letter (strcat (itoa num_pref_suffix) (nth index_copy alphabet) (nth increment alphabet))) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq increment (1+ increment)) ) (setq index_copy (1+ index_copy) increment 0 ) ) ) ) ) ) ; 1.cond ; 2. cond ((and (= answ_2 "Prefix") (= const "cHangeable")) (while (setq pt (getpoint "\nPick point: ")) (cond ((< index (length alphabet)) (setq letter (nth index alphabet)) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq index (1+ index)) ) ((>= index (length alphabet)) (if (< increment (length alphabet)) (progn (setq letter (strcat (itoa num_pref_suffix) (nth index_copy alphabet) (nth increment alphabet))) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq increment (1+ increment)) ) (setq index_copy (1+ index_copy) increment 0 num_pref_suffix (1+ num_pref_suffix) ) ) ) ) ) ) ; 2. cond ; 3. cond ((and (= answ_2 "Suffix") (= const "Constant")) (while (setq pt (getpoint "\nPick point: ")) (cond ((< index (length alphabet)) (setq letter (nth index alphabet)) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq index (1+ index)) ) ((>= index (length alphabet)) (if (< increment (length alphabet)) (progn (setq letter (strcat (nth index_copy alphabet) (nth increment alphabet) (itoa num_pref_suffix))) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq increment (1+ increment)) ) (setq index_copy (1+ index_copy) increment 0 ) ) ) ) ) ) ; 3. cond ((and (= answ_2 "Suffix") (= const "cHangeable")) (while (setq pt (getpoint "\nPick point: ")) (cond ((< index (length alphabet)) (setq letter (nth index alphabet)) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq index (1+ index)) ) ((>= index (length alphabet)) (if (< increment (length alphabet)) (progn (setq letter (strcat (nth index_copy alphabet) (nth increment alphabet) (itoa num_pref_suffix))) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq increment (1+ increment)) ) (setq index_copy (1+ index_copy) increment 0 num_pref_suffix (1+ num_pref_suffix) ) ) ) ) ) ) ; 4. cond ) ; main cond end ) ; 1. progn ; 2. progn (progn (while (setq pt (getpoint "\nPick point: ")) (cond ((< index (length alphabet)) (setq letter (nth index alphabet)) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq index (1+ index)) ) ((>= index (length alphabet)) (if (< increment (length alphabet)) (progn (setq letter (strcat (nth index_copy alphabet) (nth increment alphabet))) ;; Insert the letter as text (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer 0 (cons 10 pt) ; Insertion point (cons 40 2.0) ; Text height (cons 1 letter) ; Text string (cons 7 "STANDARD") ; Text style ) ) (setq increment (1+ increment)) ) (setq index_copy (1+ index_copy ) increment 0 ) ) ) ) ) ) ; 2. progn ) ; end if (prompt "\nAdding a text values are done!") (princ) ) 1 Quote
BIGAL Posted June 23 Posted June 23 (edited) This will get around any value you want even "ZZ" just note "A" is 1 posted both conversions. ; Alpha2Number - Converts Alpha string into Number ; Function By: Gilles Chanteau from Marseille, France ; Arguments: 1 ; Str$ = String to convert ; Syntax example: (Alpha2Number "ABC") = 731 ;------------------------------------------------------------------------------- (defun Alpha2Number (Str$ / Num#) (if (= 0 (setq Num# (strlen Str$))) 0 (+ (* (- (ascii (strcase (substr Str$ 1 1))) 64) (expt 26 (1- Num#))) (Alpha2Number (substr Str$ 2)) ) ) ) ;------------------------------------------------------------------------------- ; Number2Alpha - Converts Number into Alpha string ; Function By: Gilles Chanteau from Marseille, France ; Arguments: 1 ; Num# = Number to convert ; Syntax example: (Number2Alpha 731) = "ABC" ;------------------------------------------------------------------------------- (defun Number2Alpha (Num# / Val#) (if (< Num# 27) (chr (+ 64 Num#)) (if (= 0 (setq Val# (rem Num# 26))) (strcat (Number2Alpha (1- (/ Num# 26))) "Z") (strcat (Number2Alpha (/ Num# 26)) (chr (+ 64 Val#))) ) ) );defun Number2Alpha Providing you dont exceed "Z" then you can use (chr x) where (chr 65) is "A" 66 is "B" and so on. Edited June 23 by BIGAL 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.