The Buzzard Posted September 2, 2010 Posted September 2, 2010 Hello All, I am currently working on a block program for Cable ID Tags. The tags use a sequential number at the end. They start out at 001, 002, 003 & so on. When the program inserts each block the number is to increase by 1. The problem I am having is the leading zero's in the number do not show up after the block is inserted. I thought changing dimzin would work, But it did'nt happen. See image below. Is there a variable for this or do I need to use some sort of special method to achieve this? Any help is much appreciated. Thanks Quote
BlackBox Posted September 2, 2010 Posted September 2, 2010 Have you tried the vl-string-left-trim function? [edit] (vl-string-left-trim "0" "01-N-AV-001") _$ "1-N-AV-001" _$ [/edit] Quote
alanjt Posted September 2, 2010 Posted September 2, 2010 (defun AT:NumFix (s n) ;; Fix number string with leading zeros ;; s - Number string to fix ;; n - Number of characters for final string ;; Alan J. Thompson, 10.29.09 (if (< (strlen s) n) (AT:NumFix (strcat "0" s) n) s ) ) (AT:NumFix "3" 4) -> "0003" 1 Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 Thanks RenderMan, But I am not familar with VL. I was looking more towards a vanilla solution. Below is the function I am currently using. It works with the exception of the leading zeros. (defun COMM_SEQN () (setq ATAG (strcat "01-N-"OUSE"-"SEQN"")) (setq SS (ssget "_l" (list (cons 0 "INSERT")(cons 66 1)))) (if (/= SS nil) (progn (setq INDEX 0) (setq ENAME (ssname SS INDEX)) (setq ELIST (entget ENAME)) (while (/= (cdr (assoc 0 ELIST)) "SEQEND") (setq ELIST (entget ENAME)) (if (= "ID-TAG" (cdr (assoc 2 ELIST))) (progn (entmod (subst (cons 1 ATAG)(assoc 1 ELIST) ELIST)) (entupd ENAME))) (setq ENAME (entnext ENAME))))) (princ)) (princ) Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 Alan, thats interesting. It looks like I need to provide two arguments, a string and a number if I understand it correctly. Quote
BlackBox Posted September 2, 2010 Posted September 2, 2010 My bad, Buzzard. Alan's given you a great alternative! (...another one for the trophy shelf, ehh, Alan!? ) Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 My bad, Buzzard. Alan's given you a great alternative! (...another one for the trophy shelf, ehh, Alan!? ) No problem, I appreciate the help all the same. Quote
alanjt Posted September 2, 2010 Posted September 2, 2010 Alan, thats interesting. It looks like I need to provide two arguments, a string and a number if I understand it correctly. Correct. First is the number string and the second is the desired length of the string eg. (AT:NumFix "1" 3) would yield "001". My bad, Buzzard. Alan's given you a great alternative! (...another one for the trophy shelf, ehh, Alan!? ) Thanks. Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 Correct. First is the number string and the second is the desired length of the stringeg. (AT:NumFix "1" 3) would yield "001". Thanks. Ok, So as the sequence increases, I would need to use a conditional statement. ex: 001-009 & 010-099 as these would change due to fewer leading zeros when they reach these points. Quote
Lee Mac Posted September 2, 2010 Posted September 2, 2010 (edited) Alan, you code inspired me to have some fun with the concept (defun PadLeft&Right ( string char left right ) (defun PadLeft ( string left right ) (cond ( (< 0 left) (PadRight (strcat char string) (1- left) right) ) ( (< 0 right) (PadRight string left right) ) ( string ) ) ) (defun PadRight ( string left right ) (cond ( (< 0 right) (PadLeft (strcat string char) left (1- right)) ) ( (< 0 left) (PadLeft string left right) ) ( string ) ) ) (PadLeft string left right) ) I love the TRACE call: Entering (PADLEFT&RIGHT "1" "0" 8 5) Entering (PADLEFT "1" 8 5) Entering (PADRIGHT "01" 7 5) Entering (PADLEFT "010" 7 4) Entering (PADRIGHT "0010" 6 4) Entering (PADLEFT "00100" 6 3) Entering (PADRIGHT "000100" 5 3) Entering (PADLEFT "0001000" 5 2) Entering (PADRIGHT "00001000" 4 2) Entering (PADLEFT "000010000" 4 1) [10] Entering (PADRIGHT "0000010000" 3 1) [11] Entering (PADLEFT "00000100000" 3 0) [12] Entering (PADRIGHT "000000100000" 2 0) [13] Entering (PADLEFT "000000100000" 2 0) [14] Entering (PADRIGHT "0000000100000" 1 0) [15] Entering (PADLEFT "0000000100000" 1 0) [16] Entering (PADRIGHT "00000000100000" 0 0) [16] Result: "00000000100000" [15] Result: "00000000100000" [14] Result: "00000000100000" [13] Result: "00000000100000" [12] Result: "00000000100000" [11] Result: "00000000100000" [10] Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Result: "00000000100000" Edited September 2, 2010 by Lee Mac Quote
alanjt Posted September 2, 2010 Posted September 2, 2010 Ok, So as the sequence increases, I would need to use a conditional statement. ex: 001-009 & 010-099 as these would change due to fewer leading zeros when the reach these points. It will account for any string (AT:NumFix "123" 3) -> "123" (AT:NumFix "12" 3) -> "012" Quote
BlackBox Posted September 2, 2010 Posted September 2, 2010 If you don't mind, Buzzard... have you ever considered something like this: (defun COMM_SEQM (ouse seqn / ss index elist) (if (setq ss (ssget "_L" '((0 . "INSERT") (66 . 1)))) (progn ;; ...code (entmod (subst (cons 1 (strcat "01-N-" ouse "-" seqn "")) (assoc 1 elist) elist)) ;; ...code )) (princ)) This localizes some of the variables, and I believe the others are arguments (?), also, it removes a couple of steps. Quote
alanjt Posted September 2, 2010 Posted September 2, 2010 Alan, you code inspired me to have some fun with the concept Nice... Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 If you don't mind, Buzzard... have you ever considered something like this: (defun COMM_SEQM (ouse seqn / ss index elist) (if (setq ss (ssget "_L" '((0 . "INSERT") (66 . 1)))) (progn ;; ...code (entmod (subst (cons 1 (strcat "01-N-" ouse "-" seqn "")) (assoc 1 elist) elist)) ;; ...code )) (princ)) This localizes some of the variables, and I believe the others are arguments (?), also, it removes a couple of steps. Thanks, But I do have them them localized. The function that was shown is only a small part of the code. Quote
BlackBox Posted September 2, 2010 Posted September 2, 2010 Thanks, But I do have them them localized. The function that was shown is only a small part of the code. I suspected that, but wanted to be sure, my friend. :wink: Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 (edited) If you are curious to see what I have done. Attached is the code and dcl. Type COMM to start. Select the ID Tag radio button and click enter. Note the program will go into a loop after each insertion. Edited September 2, 2010 by The Buzzard Quote
Lee Mac Posted September 2, 2010 Posted September 2, 2010 Nice... It would help if I counted my zeros Code updated Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 (edited) Ok, I got my leading zeros now. Just a few odd quirky things going on that I will need to fix, But I am closer now than before. Thanks Alan. Edited September 2, 2010 by The Buzzard Quote
alanjt Posted September 2, 2010 Posted September 2, 2010 Ok, I got my leading zeros now. Just a few odd quirky things going on that I will need to fix, But I am closer now than before. Thanks Alan. You're welcome. Quote
The Buzzard Posted September 2, 2010 Author Posted September 2, 2010 To All, Please note, This code is still work in progress and not complete. I plan to reduce the size of the Block Definition & Show Image functions. Also I plan to fix the looping as well. I will repost later at some point when it is completed. 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.