Jump to content

Help changing code from ENTSEL to SSGET


ILoveMadoka

Recommended Posts

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?
 

Link to comment
Share on other sites

@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.

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Steven P
Link to comment
Share on other sites

Thanks much..
Will have to wait for tomorrow to test...

Being able to pick several at a time in order is still quicker...

 

Link to comment
Share on other sites

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 by BIGAL
Link to comment
Share on other sites

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 by Jonathan Handojo
Link to comment
Share on other sites

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)

 

 

 

  • Like 1
Link to comment
Share on other sites

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.

 

image.png.c7ab9eaf559d15602767855b2ef94ef0.png

 

Edited by ILoveMadoka
Link to comment
Share on other sites

BigAl,

 

this is what I got when I tried your code Sir..

 

image.png.743f6428e2fd44c765468c762f122076.png

 

if I windowed everything I get this

 

image.png.a78d2e8360c0f159492121b5b417b30a.png

Link to comment
Share on other sites

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.

 

image.png.c7ab9eaf559d15602767855b2ef94ef0.png

 

 

 

I've edited the code above and a small other change that might make a difference

Link to comment
Share on other sites

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 by BIGAL
  • Like 1
Link to comment
Share on other sites

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)
)

 

image.png.ff12d8e1e904dd0489edebc5840e9c21.png

 

 

Edited by BIGAL
Link to comment
Share on other sites

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

image.thumb.png.68bdaa2cad60a3cf5f858ed21bb7af23.png

 

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

 

 


 

 

Link to comment
Share on other sites

Posted (edited)

Steven P,

 

I could not get yours to work <for me> unfortunately.

Seems like it got stuck in a loop.

 

(princ "\nNext block: ")

 

image.png.e18162c13650cdbf7d37c3960d7e9a3e.png

 

My test was this

 

image.thumb.png.f650a59bc395b7d4e39028154a8d2429.png

 

and a crossing gave me this.. <I had to cancel to get out of the loop>

 

image.thumb.png.68638b63dd9886f61f4a06ef43b4e524.png

 

I do appreciate it!


And the help elsewhere!!

 

Edited by ILoveMadoka
  • Like 1
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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!


 

  • Like 1
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...