ILoveMadoka Posted February 28 Posted February 28 I found an autolisp program here that does autonumbering of blocks which works perfectly for my application. I really do like the way it works! It requires a user select blocks one at a time (ENTSEL). I'd like to be able to create a selection set (SSGET) and have it perform the exact same function. Here is the code: (defun c:ASQ () :Attribute SeQuential numbering (princ "\nStarting Number: ") (setq startnum (getint)) (setq num startnum) (princ "\nPick Block to sequentially number: ") (while (setq a (entsel)) (setq b (car a)) (setq c (entget b)) (setq d (entnext b)) (setq e (entget d)) (setq f (assoc 0 e)) (setq g (assoc 2 e)) (setq h (assoc 1 e)) (setq num$ (itoa num)) (setq hh (cons 1 num$)) (setq e (subst hh h e)) (entmod e) (entupd d) (setq num (1+ num)) (princ "\nNext block: ") ) (princ) ) I believe I have to incorporate something along the lines of this snippet but do not know how to actually marry the two together (if (setq ss (ssget '((0 . "INSERT")))) (progn (repeat (setq i (sslength ss)) (setq name (cdr (assoc 2 (entget (ssname ss (setq i (1- i))))))) (if (null (member name lst)) (setq lst (cons name lst)) ) ) (foreach n lst (setq ent (cdr (assoc -2 (tblsearch "BLOCK" n)))) (while ent (setq elst (entget ent)) (do stuff here...) (setq ent (entnext ent)) Help please? Quote
pkenewell Posted February 28 Posted February 28 @ILoveMadoka The problem I see with this approach is you will not have any control on the order that SSGET selects the objects (unless you still pick them one at a time), and you might not get the sequential order you want. You would need some type of code to sort the selected entities by some other criteria, such as location. 1 Quote
Steven P Posted February 28 Posted February 28 Yes, I'd go with that too - even though it is quicker and there are some very good LISPs out there I tend to pick each individually and number that way Quote
Steven P Posted February 28 Posted February 28 (edited) Untested though you could try this (defun c:ASQ ( / a b c d e f g h num$ num startnum MySS acount) :Attribute SeQuential numbering (princ "\nStarting Number: ") (setq startnum (getint)) (setq num startnum) (princ "\nPick Block to sequentially number: ") (setq MySS (ssget '((0 . "INSERT"))) ) ; selection set (setq acount 0) (while (< acount (sslength MySS)) (setq a (ssname MySS acount)) ;; (while ;; (setq a (entsel)) ;; (setq b (car a)) (setq b a) (setq c (entget b)) (setq d (entnext b)) (setq e (entget d)) (setq f (assoc 0 e)) (setq g (assoc 2 e)) (setq h (assoc 1 e)) (setq num$ (itoa num)) (setq hh (cons 1 num$)) (setq e (subst hh h e)) (entmod e) (entupd d) (setq num (1+ num)) (princ "\nNext block: ") ;; ) ; end while (setq acount (+ acount 1)) ) ; end while (princ) ) Edited March 4 by Steven P Quote
ILoveMadoka Posted February 28 Author Posted February 28 Thanks much.. Will have to wait for tomorrow to test... Being able to pick several at a time in order is still quicker... Quote
BIGAL Posted February 28 Posted February 28 (edited) You could change the code to 2 functions a pick pick or select multi, take the Edit part out make it a defun, then just call that function for each pick or call it inside a loop for a selection. For me (princ "\nStarting Number: ") (setq startnum (getint)) (setq startnum (getint "\nPlease enter starting numer ")) Edited February 28 by BIGAL Quote
Jonathan Handojo Posted February 29 Posted February 29 (edited) FYI @pkenewell, there's one particular program that I use in my workplace on a daily basis using ssget in which order matters a lot. This is also for the same reason... numbering purposes, and page order when plotting multiple templates. The way I taught my colleagues on how to use this is not to use the window selection method, but rather to click one at a time as well, mimicking entsel. I tested the selection order of ssget using Fence as well, and so far I haven't found any flaws with the sequencing of ssget. Edited February 29 by Jonathan Handojo Quote
BIGAL Posted February 29 Posted February 29 There was a post about using handle ID and that it increases in value so I have not used it but would be interesting to try, need to convert hex to a number. A list sorted ((num Entity name: 2f9f3670>)...... I tried this as a test seemed to work. ; reorder a selection set using Handle for order ; by AlanH 29 Feb ;; Base to Decimal - Lee Mac ;; Converts an number in an arbitrary base to decimal. ;; n - [str] string representing number to convert ;; b - [int] base of input string ;; Returns: [int] Decimal representation of supplied number (defun LM:base->dec ( n b / l ) (if (= 1 (setq l (strlen n))) (- (ascii n) (if (< (ascii n) 65) 48 55)) (+ (* b (LM:base->dec (substr n 1 (1- l)) b)) (LM:base->dec (substr n l) b)) ) ) (defun LWPoly (lst cls) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls)) (mapcar (function (lambda (p) (cons 10 p))) lst))) ) (defun c:wow ( / ) (prompt "pick objects ") (setq ss (ssget)) (setq lst '()) (repeat (setq x (sslength ss)) (setq ent (entget (ssname ss (setq x (1- x))))) (setq id (cdr (assoc 5 ent))) (setq enty (cdr (assoc -1 ent))) (setq num (LM:base->dec id 16)) (setq lst (cons (list num enty) lst)) (princ) ) (setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y))))) (setq lst2 '()) (foreach val lst (setq ent (cadr val)) (setq lst2 (cons (cdr (assoc 10 (entget ent))) lst2)) ) (lwpoly lst2 1) (princ) ) (c:wow) 1 Quote
ILoveMadoka Posted February 29 Author Posted February 29 (edited) Thank you for the code sir.. (Steven P) There is a missing closing paren. Does it go here? (setq acount 0 even when I added it, the code was not working for me. It did not make one change for the blocks I selected. FYI, nothing magic about my block. Its a simple block with a piece of text inside that is not part of the block. imagine a circle that is a block then putting a stand alone piece of text inside the circle. Edited February 29 by ILoveMadoka Quote
ILoveMadoka Posted February 29 Author Posted February 29 BigAl, this is what I got when I tried your code Sir.. if I windowed everything I get this Quote
Steven P Posted February 29 Posted February 29 2 hours ago, ILoveMadoka said: Thank you for the code sir.. (Steven P) There is a missing closing paren. Does it go here? (setq acount 0 even when I added it, the code was not working for me. It did not make one change for the blocks I selected. FYI, nothing magic about my block. Its a simple block with a piece of text inside that is not part of the block. imagine a circle that is a block then putting a stand alone piece of text inside the circle. I've edited the code above and a small other change that might make a difference Quote
BIGAL Posted February 29 Posted February 29 (edited) My code was just to prove the theory about getting objects in creation order thats all. Not an answer to your question. Ok simple fix to problem convert the text to an attribute, it does not make sense to change the hard coded text in a block, that is what attributes are for. So bedit your block and repost a new dwg. The answer will come back so fast. May even add the sort by creation order. Edited February 29 by BIGAL 1 Quote
BIGAL Posted March 1 Posted March 1 (edited) Here is your code with a block made with 1 attribute, I inserted once and copied randomly. So add a Attribute. It will work for any block changing 1st attribute. ; reorder a block selection set using Handle for order ; by AlanH 29 Feb ;; Base to Decimal - Lee Mac ;; Converts an number in an arbitrary base to decimal. ;; n - [str] string representing number to convert ;; b - [int] base of input string ;; Returns: [int] Decimal representation of supplied number (defun LM:base->dec ( n b / l ) (if (= 1 (setq l (strlen n))) (- (ascii n) (if (< (ascii n) 65) 48 55)) (+ (* b (LM:base->dec (substr n 1 (1- l)) b)) (LM:base->dec (substr n l) b)) ) ) (defun c:wow ( / ) (prompt "pick objects ") (setq ss (ssget '((0 . "Insert")))) (setq lst '()) (repeat (setq x (sslength ss)) (setq ent (entget (ssname ss (setq x (1- x))))) (setq id (cdr (assoc 5 ent))) (setq enty (cdr (assoc -1 ent))) (setq num (LM:base->dec id 16)) (setq lst (cons (list num enty) lst)) ) (setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y))))) (setq x 1) (foreach blk lst (setq ent (cadr blk)) (setq atts (vlax-invoke (vlax-ename->vla-object ent) 'Getattributes)) (setq att1 (nth 0 atts)) (vlax-put att1 'Textstring (rtos x 2 0)) (setq x (1+ x)) ) (princ) ) Edited March 1 by BIGAL Quote
ILoveMadoka Posted March 4 Author Posted March 4 BigAl.. Sorry I didn't understand your original post... Your new code works perfectly. <Very cool> Very useful. Has tremendous application in so many situations.. Numbers in creation order correct? If I knew more I could take your code and make a new proggie from it that takes into consideration both the pick order and asks for a starting number. Here is a real life application I never know which "chair" will be numbered 1 and which direction they will want the numbers to go.... (It's not always the same ) The original comments about pick order comes into play... I won't ask for more because you did so much <Thank you!> Between your code and the original "one at a time" I can make do... I will use your code and the new block for layouts in the future... Thank you both so very much Quote
ILoveMadoka Posted March 4 Author Posted March 4 (edited) Steven P, I could not get yours to work <for me> unfortunately. Seems like it got stuck in a loop. (princ "\nNext block: ") My test was this and a crossing gave me this.. <I had to cancel to get out of the loop> I do appreciate it! And the help elsewhere!! Edited March 4 by ILoveMadoka 1 Quote
ronjonp Posted March 4 Posted March 4 @ILoveMadoka You might take a look at THIS too. It will let you increment your blocks by simply dragging the cursor over them. 1 Quote
BIGAL Posted March 5 Posted March 5 Like the ronjonp idea if you select a row at a time hopefully there is a pattern, I have not looked at what an array does wether its rows or columns 1st. Like your image 3 rows of seats. Try selecting the 3 row seats 1 row at a time can add a "F" option so drag lines over. Would like to know what happens. Quote
ILoveMadoka Posted March 5 Author Posted March 5 On 2/29/2024 at 9:00 AM, Steven P said: I've edited the code above and a small other change that might make a difference Winner!! That was my original design intent. Thank you so very much!! = In addition, I now have different options for a working solution. I appreciate you guys and your assistance. Thank you ALL so very much! 1 Quote
ILoveMadoka Posted March 5 Author Posted March 5 12 hours ago, ronjonp said: @ILoveMadoka You might take a look at THIS too. It will let you increment your blocks by simply dragging the cursor over them. Witchcraft!! That is SO cool!! Thank you Sir 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.