rog1n Posted September 4, 2020 Posted September 4, 2020 Hello, in my tests I believe the ssget "_X" order the selectionset by the last entity insert on drawing Ex: If I insert a block name "A" 4 times at drawing: 1 - <Entity name: 1b8fdc375c0> 2 - <Entity name: 1b8fdc37650> 3- <Entity name: 1b8fdc376e0> 4- <Entity name: 1b8fdc37770> When I do (setq sel (ssget "_X" (list (cons 0 "INSERT") (cons 2 "A")))) 0-><Entity name: 1b8fdc37770> 1-><Entity name: 1b8fdc376e0> 2-><Entity name: 1b8fdc37650> 3-><Entity name: 1b8fdc375c0> So, is possible update the order of the ssget "_X" in the drawing? like for example I want to move the entity 3 to 1, when I do (setq sel (ssget "_X" (list (cons 0 "INSERT") (cons 2 "A")))): the result will: 0-><Entity name: 1b8fdc37770> 1-><Entity name: 1b8fdc375c0> 2-><Entity name: 1b8fdc376e0> 3-><Entity name: 1b8fdc37650> Quote
BIGAL Posted September 4, 2020 Posted September 4, 2020 (edited) Very doubtful you can though do a sort on say XY position if looking for some sort of pattern. Edited September 4, 2020 by BIGAL Quote
marko_ribar Posted September 5, 2020 Posted September 5, 2020 Maybe perhaps something like this can help... (defun reorderss ( / chkssX ss n m en em i e sss ) (defun chkssX ( ss / i l ) (if ss (repeat (setq i (sslength ss)) (setq l (cons (ssname ss (setq i (1- i))) l)) ) ) l ) (if (setq ss (ssget "_X")) (progn (setq n (getint (strcat "\nSpecify which nth element you want to move to some other position - it must be from 0 to " (itoa (1- (sslength ss))) " : "))) (setq m (getint (strcat "\nSpecify to which position you want to move nth element from 0 to " (itoa (1- (sslength ss))) " : "))) (if (/= n m) (progn (setq en (ssname ss n)) (setq em (ssname ss m)) (setq sss (ssadd)) (setq i -1) (while (< (setq i (1+ i)) (sslength ss)) (setq e (ssname ss i)) (cond ( (= i m) (ssadd en sss) ) ( (= i n) (ssadd em sss) ) ( t (ssadd e sss) ) ) ) ) ) ) ) (if sss (progn (princ "\n") (princ (chkssX sss)) sss ) (progn (princ "\n") (princ (chkssX ss)) ss ) ) ) (defun chkssX ( / ss i l ) (if (setq ss (ssget "_X")) (repeat (setq i (sslength ss)) (setq l (cons (ssname ss (setq i (1- i))) l)) ) ) l ) ;| Command: (chkssx) (<Entity name: 1cbc5778d70> <Entity name: 1cbc5778d60> <Entity name: 1cbc5778d50> <Entity name: 1cbc5778d40>) Command: (setq ss (reorderss)) Specify which nth element you want to move to some other position - it must be from 0 to 3 : 2 Specify to which position you want to move nth element from 0 to 3 : 1 (<Entity name: 1cbc5778d70> <Entity name: 1cbc5778d50> <Entity name: 1cbc5778d60> <Entity name: 1cbc5778d40>)<Selection set: 2c> |; Quote
BIGAL Posted September 5, 2020 Posted September 5, 2020 rog1n please explain more what it is your doing and why change order. Marco nice answer sort of thing you put away for a problem another day. Quote
rog1n Posted September 6, 2020 Author Posted September 6, 2020 (edited) Hi, I trying to make numbering automatic of blocks (like http://www.lee-mac.com/autolabelattributes.html) but if I add a a new block between 3,4 the result will 1,2,3,7,4,5,6, so I want to know if possible update the block orders in my drawing to the numbering count 1,2,3,4,5,6,7 I tried to set a number with xdata to this new block 7 with number 3 for example, them I will have 1,2,3,4,5,6,7 but If I remove the number 1 for exemple the result will have 1,3,2,4,5,6 So I think the only solution is update the order of inserted the blocks on drawing, to be dynamic Edited September 6, 2020 by rog1n Quote
devitg Posted September 6, 2020 Posted September 6, 2020 Maybe if you could show us , such Before.dwg and after.dwg , some better solution could give you . Quote
marko_ribar Posted September 6, 2020 Posted September 6, 2020 (edited) Hi... Me again. I've changed my code a little to suit better your needs... See if it has now some bigger meaning to you... (defun reorderss ( filter / chkss ss n m en i e sss ) (defun chkss ( ss / i l ) (if ss (repeat (setq i (sslength ss)) (setq l (cons (ssname ss (setq i (1- i))) l)) ) ) l ) (if (setq ss (ssget "_X" filter)) (progn (initget 5) (setq n (getint (strcat "\nSpecify which nth element you want to move to some other position - it must be from 0 to " (itoa (1- (sslength ss))) " : "))) (initget 5) (setq m (getint (strcat "\nSpecify to which position you want to move nth element from 0 to " (itoa (1- (sslength ss))) " : "))) (if (/= n m) (progn (setq en (ssname ss n)) (setq sss (ssadd)) (setq i -1) (while (< (setq i (1+ i)) (sslength ss)) (setq e (ssname ss i)) (cond ( (= i m) (ssadd en sss) (ssadd e sss) ) ( (eq e en) nil ) ( t (ssadd e sss) ) ) ) ) ) ) ) (if sss (progn (princ "\n") (princ (chkss sss)) sss ) (progn (princ "\n") (princ (chkss ss)) ss ) ) ) (defun chkssX ( filter / ss i l ) (if (setq ss (ssget "_X" filter)) (repeat (setq i (sslength ss)) (setq l (cons (ssname ss (setq i (1- i))) l)) ) ) l ) ;| Command: (chkssx nil) (<Entity name: 260f38ab5c0> <Entity name: 260f38ab5b0> <Entity name: 260f38ab5a0> <Entity name: 260f38ab590> <Entity name: 260f38ab580> <Entity name: 260f38ab570> <Entity name: 260f38ab560> <Entity name: 260f38ab550> <Entity name: 260f38ab540>) Command: (setq ss (reorderss nil)) Specify which nth element you want to move to some other position - it must be from 0 to 8 : 7 Specify to which position you want to move nth element from 0 to 8 : 2 (<Entity name: 260f38ab5c0> <Entity name: 260f38ab5b0> <Entity name: 260f38ab550> <Entity name: 260f38ab5a0> <Entity name: 260f38ab590> <Entity name: 260f38ab580> <Entity name: 260f38ab570> <Entity name: 260f38ab560> <Entity name: 260f38ab540>)<Selection set: 13> |; Edited September 7, 2020 by marko_ribar Quote
BIGAL Posted September 6, 2020 Posted September 6, 2020 (edited) Sounds like 3 options required. If you want to say manually add a block between 3 & 4 then you could do it by imply a number searching the named blocks, then go through all the others, greater than, renumbering adding 1. Then insert. Adding a new block search blocks find last number +1 and insert. Reorder blocks as per solution by Marko. Thinking more a few options. I am sure some others will come up with a couple more. Edited September 6, 2020 by BIGAL Quote
Roy_043 Posted September 7, 2020 Posted September 7, 2020 The auto label routine referred to relies on the creation order of the block references. The only option I see is to recreate the blocks that should come after the new block. If you copy them in place be sure to pay attention to the selection order! 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.