View Full Version : Help with routine to sequential number station in Attribute block.
cadd4la
2006-07-07, 01:23 AM
Hi everyone I am in need of some help fixing this code to do what I need it to do.
I am looking for it to Sequential number the station number in the att. block. It will start with A-X or something with a letter and a dash and I need to get i.e. A-1, A-2, A-3, Etc. or B-1, B-2, B-3, Etc.
I have the code able to change A-X to 1 but I don't know how to have the Attribute Sequential number and leave the "A-" the same and only have the number at the end change.
(defun c:IRstep ( / Ask SelSet BlkName AttName AttDxf ) ;; *Counter* = global variable
(if (not *Counter* ) (setq *Counter* 0 ) ( ) ) ; initsilize the global variable
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )) ) (setq *Counter* (1- Ask ) ) ( ) )
(while (setq SelSet (ssget ":S" '((0 . "INSERT" ))) )
(setq BlkName (ssname SelSet 0 ) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "VALVE_NUMBER" )
(progn
(setq *Counter* (1+ *Counter* ))
(setq AttDxf (subst (cons 1 (itoa *Counter* )) (assoc 1 AttDxf ) AttDxf ) )
(entmod AttDxf )
(entupd AttName )
)
( )
)
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" ) (setq AttName nil ) (setq AttName (entnext AttName )) )
)
)
(princ)
)
I have also included the att. block.
I thank you for the help.
Kyle C.
T.Willey
2006-07-07, 01:28 AM
What I would do, is have two variables, and then just string them together when you put them in the attribute.
(setq Prefix (getstring T "\n Enter prefix: "))
(setq Counter (getint "\n Enter starting number: "))
.. pick your block here.. and seach for the attribute
(strcat Prefix (itoa Counter))
(setq Counter (1+ Counter))
Sorry for the really simple, badly coded, example, but it show the basic idea of what I would do.
cadd4la
2006-07-11, 01:58 AM
T.Willey,
I don't understand what you're showing me do.
I added so of your code but still no luck on having the "A-" or any other prefix be fixed.
Thanks for the input.
Kyle C.
(defun c:IRstep ( / Prefix Ask SelSet BlkName AttName AttDxf ) ;; *Counter* = global variable
(setq Prefix (getstring T "n Enter prefix: "))
(if (not *Counter* ) (setq *Counter* 0 ) ( ) ) ; initsilize the global variable
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )) ) (setq *Counter* (1- Ask ) ) ( ) )
(while (setq SelSet (ssget ":S" '((0 . "INSERT" ))) )
(setq BlkName (ssname SelSet 0 ) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "VALVE_NUMBER" )
(progn
(strcat Prefix (itoa Counter))
(setq *Counter* (1+ *Counter* ))
(setq AttDxf (subst (cons 1 (itoa *Counter* )) (assoc 1 AttDxf ) AttDxf ) )
(entmod AttDxf )
(entupd AttName )
)
( )
)
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" ) (setq AttName nil ) (setq AttName (entnext AttName )) )
)
)
(princ)
)
What I would do, is have two variables, and then just string them together when you put them in the attribute.
(setq Prefix (getstring T "n Enter prefix: "))
(setq Counter (getint "n Enter starting number: "))
.. pick your block here.. and seach for the attribute
(strcat Prefix (itoa Counter))
(setq Counter (1+ Counter))
Sorry for the really simple, badly coded, example, but it show the basic idea of what I would do.
T.Willey
2006-07-11, 05:01 PM
You did what I posted, but what I posted wasn't complete, so you code wasn't complete.
Here is what the code should look like.
(defun c:IRstep ( / Prefix Ask SelSet BlkName AttName AttDxf Prefix) ;; *Counter* = global variable
(setq Prefix (getstring T "n Enter prefix: "))
(if (not *Counter* ) (setq *Counter* 0 ) ( ) ) ; initsilize the global variable
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )) ) (setq *Counter* (1- Ask ) ) ( ) )
(while (setq SelSet (ssget ":S" '((0 . "INSERT" ))) )
(setq BlkName (ssname SelSet 0 ) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "VALVE_NUMBER" )
(progn
(setq AttDxf (subst (cons 1 (strcat Prefix (itoa *Counter*))) (assoc 1 AttDxf ) AttDxf ) )
(setq *Counter* (1+ *Counter* ))
(entmod AttDxf )
(entupd AttName )
)
( )
)
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" ) (setq AttName nil ) (setq AttName (entnext AttName )) )
)
)
(princ)
)
cadd4la
2006-07-11, 10:49 PM
T.Willey,
Thanks, the code works but for one problem, for some reason it is subtracting by 1at the start, i.e. if I enter 1 to be the starting number, I will get A-0, A-1, A-2, etc.
I can't figure out what the problem is. the only part that was added to the code I have highlighted in red.
I hope you or somebody can help.
thanks again for you help so far.
Kyle C.
You did what I posted, but what I posted wasn't complete, so you code wasn't complete.
Here is what the code should look like.
(defun c:IRstep ( / Prefix Ask SelSet BlkName AttName AttDxf Prefix) ;; *Counter* = global variable
(setq Prefix (getstring T "n Enter prefix: "))
(if (not *Counter* ) (setq *Counter* 0 ) ( ) ) ; initsilize the global variable
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )) ) (setq *Counter* (1- Ask ) ) ( ) )
(while (setq SelSet (ssget ":S" '((0 . "INSERT" ))) )
(setq BlkName (ssname SelSet 0 ) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "VALVE_NUMBER" )
(progn
(setq AttDxf (subst (cons 1 (strcat Prefix (itoa *Counter*))) (assoc 1 AttDxf ) AttDxf ) )
(setq *Counter* (1+ *Counter* ))
(entmod AttDxf )
(entupd AttName )
)
( )
)
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" ) (setq AttName nil ) (setq AttName (entnext AttName )) )
)
)
(princ)
)
T.Willey
2006-07-11, 11:20 PM
Look at this piece of code
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )) ) (setq *Counter* (1- Ask ) ) ( ) )
Broken down so it's easier to read
(if
(setq Ask
(getint
(strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )
)
)
(setq *Counter* (1- Ask ))
( ) ; not needed.
)
You are saying that if Ask is supplied, then take 1 away from it. So if you enter 1, you are making *Counter* 1 - 1 which = 0.
cadd4la
2006-07-11, 11:45 PM
Tim,
Sorry that didn't help. It is still subtracting by 1at the start, my original code wouldn't do the subtracting by 1at the start.
Also I would like to have a preset setting for the prefix but what I have tried coding is not working (see red highlighting)
(defun c:IRstep ( / Prefix Ask SelSet BlkName AttName AttDxf Prefix) ;; *Counter* = global variable
;;(setq Prefix (getstring T "nEnter prefix or [Enter] to accept <A-> :" ))
(setq Prefix (getstring T "nEnter prefix: "))
(if (not *Counter* ) (setq *Counter* 0 ) ( ) ) ; initsilize the global variable
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )) ) (setq *Counter* (1- Ask ) ) )
(while (setq SelSet (ssget ":S" '((0 . "INSERT" ))) )
(setq BlkName (ssname SelSet 0 ) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "VALVE_NUMBER" )
(progn
(setq AttDxf (subst (cons 1 (strcat Prefix (itoa *Counter*))) (assoc 1 AttDxf ) AttDxf ) );;New part
(setq *Counter* (1+ *Counter* ))
(entmod AttDxf )
(entupd AttName )
)
( )
)
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" ) (setq AttName nil ) (setq AttName (entnext AttName )) )
)
)
(princ)
)
;; (setq AttDxf (subst (cons 1 (itoa *Counter* )) (assoc 1 AttDxf ) AttDxf ) )
Original
(defun c:IRStep1 ( / Ask SelSet BlkName AttName AttDxf ) ;; *Counter* = global variable
(if (not *Counter* ) (setq *Counter* 0 ) ( ) ) ; initsilize the global variable
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa (1+ *Counter* )) "> :" )) ) (setq *Counter* (1- Ask ) ) ( ) )
(while (setq SelSet (ssget ":S" '((0 . "INSERT" ))) )
(setq BlkName (ssname SelSet 0 ) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "VALVE_NUMBER" )
(progn
(setq *Counter* (1+ *Counter* ))
(setq AttDxf (subst (cons 1 (itoa *Counter* )) (assoc 1 AttDxf ) AttDxf ) )
(entmod AttDxf )
(entupd AttName )
)
( )
)
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" ) (setq AttName nil ) (setq AttName (entnext AttName )) )
)
)
(princ)
)
Thanks,
Kyle C.
T.Willey
2006-07-12, 12:37 AM
Here is code that works.
(defun c:IRStep1 ( / Ask SelSet BlkName AttName AttDxf Prefix) ;; *Counter* = global variable
(if (not *Counter* )
(setq *Counter* 1 )
) ; initsilize the global variable
(if (setq Ask (getint (strcat "nEnter start number or [Enter] to accept <" (itoa *Counter*) "> :" )))
(setq *Counter* Ask)
)
(if (= (setq Prefix (getstring T "\n Enter prefix <A->: ")) "")
(setq Prefix "A-")
)
(while (setq SelSet (ssget ":S" '((0 . "INSERT" ))) )
(setq BlkName (ssname SelSet 0 ) )
(setq AttName (entnext BlkName ) )
(while AttName
(setq AttDxf (entget AttName ) )
(if (= (cdr (assoc 2 AttDxf )) "VALVE_NUMBER" )
(progn
(setq AttDxf (subst (cons 1 (strcat Prefix (itoa *Counter* ))) (assoc 1 AttDxf ) AttDxf ) )
(setq *Counter* (1+ *Counter* ))
(entmod AttDxf )
(entupd AttName )
)
)
(if (= (cdr (assoc 0 (entget AttName ))) "SEQEND" )
(setq AttName nil )
(setq AttName (entnext AttName ))
)
)
)
(princ)
)
If you have any questions please feel free to ask. I took your original code, and change it to do what you wanted it to do.
cadd4la
2006-07-12, 01:00 AM
Tim,
It is working 100% the way I need it.
Thank you for all of your help.
Kyle C.
T.Willey
2006-07-12, 01:09 AM
Tim,
It is working 100% the way I need it.
Thank you for all of your help.
Kyle C.
You're welcome. Hope you study to code, so you can understand what the differences are, and why mine works the way you want it to.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.