JimmyDev Posted July 22, 2022 Posted July 22, 2022 Hello, I would like to move a specific block to specific coordinates. In the example below I can select te block "CART_LV02" and I'm able to move it 0.5 to the right. But how how can I move it for example at coordinates x=200 and y=300? (command "MOVE" (ssget "_X" '((0 . "INSERT") (2 . "CART_LV02"))) "" "" '(0.5 0 0)) Many thanks Quote
mhupp Posted July 22, 2022 Posted July 22, 2022 The move command needs two points to work properly. If you only provide it with one it assumes the 2nd point is 0,0,0 hence why its only moving to the right by 0.5. (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CART_LV02")))) ;this will select all blocks named CART_LV02 in the drawing. (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) ;lists all entity names of selection set (setq pt (cdr (assoc 10 (entget blk)))) ;get insertion point of block (command "_.Move" blk "" pt '(0.5 0 0)) ) 1 Quote
JimmyDev Posted July 22, 2022 Author Posted July 22, 2022 38 minutes ago, mhupp said: The move command needs two points to work properly. If you only provide it with one it assumes the 2nd point is 0,0,0 hence why its only moving to the right by 0.5. (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CART_LV02")))) ;this will select all blocks named CART_LV02 in the drawing. (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) ;lists all entity names of selection set (setq pt (cdr (assoc 10 (entget blk)))) ;get insertion point of block (command "_.Move" blk "" pt '(0.5 0 0)) ) It's exactly what I was look for. Thank you so much. Quote
mhupp Posted July 22, 2022 Posted July 22, 2022 FYI If their is more then one block they are all on top of each other at (0.5 0 0) Quote
JimmyDev Posted July 22, 2022 Author Posted July 22, 2022 Thank you for you response. I have always only one block with the same name in my drawing. I've tested and it works fine for the first 4 blocks (from CATA00000 till CART_LV02), but for the 2 last it doesn't move. Do you know why? The reference point of my CATA00000 block is used for all other blocks. (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CATA00000")))) ;this will select all blocks named CATA00000 in the drawing. (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) ;lists all entity names of selection set (setq pt (cdr (assoc 10 (entget blk)))) ;get insertion point of block (command "_.Move" blk "" pt '(0 0 0)) ) (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CART_LV01")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq pt (cdr (assoc 10 (entget blk)))) (command "_.Move" blk "" pt '(1178 10 0)) ) (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CART_LV03")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq pt (cdr (assoc 10 (entget blk)))) (command "_.Move" blk "" pt '(1178 140 0)) ) (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CART_LV02")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq pt (cdr (assoc 10 (entget blk)))) (command "_.Move" blk "" pt '(1178 152.5 0)) ) (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CATIDENTELEA0")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq pt (cdr (assoc 10 (entget blk)))) (command "_.Move" blk "" pt '(1178 10 0)) ) (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CATREVBELA0")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq pt (cdr (assoc 10 (entget blk)))) (command "_.Move" blk "" pt '(1178 140 0)) ) Quote
marko_ribar Posted July 22, 2022 Posted July 22, 2022 @JimmyDev Do you know that you can shorten repetative syntaxes coded by using (defun myfunc ( arg ) ... ) function and managing repetitions by iteration through (mapcar (function (lambda ( arg ) (myfunc arg))) (list arg1 arg2 ...)) 3 Quote
Kreaten_vhar Posted July 22, 2022 Posted July 22, 2022 3 minutes ago, marko_ribar said: managing repetitions by iteration through (mapcar (function (lambda ( arg ) (myfunc arg))) (list arg1 arg2 ...)) I'm not even sure why this did it for me, but I've been struggling to understand mapcar and lambda expressions and this little example made it (mostly) click! Ty M.R.! 1 Quote
mhupp Posted July 22, 2022 Posted July 22, 2022 (edited) Use @marko_ribar suggestion or you can just combine them easily enough. (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CATA00000,CART_LV##,CATIDENTELEA0,CATREVBELA0")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq pt (cdr (assoc 10 (entget blk)))) (command "_.Move" blk "" pt '(1178 10 0)) ) You can use Wild cards "#" for numbers ;; CART_LV## = BLOCK names CART_LV00 - CART_LV99 "@" for letters ;; CART_LV@ = Block names CART_LVa - CART_LVZ "*" for anything ;; CART_LV* = any block that starts with "CART_LV" *CAT* = any block that containts "CAT" *CART = any block that ends with "CART" if you only want 01-03 just put CATA00000,CART_LV01,CART_LV02,CART_LV03,.... For the last two blocks that didn't move check to see if they are on a locked layer, Then if the name has the correctly spelling. Edited July 22, 2022 by mhupp 1 Quote
JimmyDev Posted July 22, 2022 Author Posted July 22, 2022 Thank you for this exemple. I can try to use it, but the problem is that the insertpoints are always different for each block. That's the raison why I copied the code multiple times. Quote
mhupp Posted July 22, 2022 Posted July 22, 2022 Only really glanced at the code. and saw 1178 multiple times thought they where all going to the same point. You can do it that way Here is another rather then making multiple selections this makes just one of all blocks wanted then uses cond to move them (setq SS (ssget "_X" '((0 . "INSERT") (2 . "CATA00000,CART_LV01,CART_LV02,CART_LV03,CATIDENTELEA0,CATREVBELA0") (410 . "Model")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (setq blkname (cdr (assoc 2 (setq x (entget blk))))) (cond ((eq blkname "CATA00000") (setq pt (cdr (assoc 10 x))) (command "_.Move" blk "" pt '(0 0 0)) ) ((eq blkname "CART_LV01") (setq pt (cdr (assoc 10 x))) (command "_.Move" blk "" pt '(1178 10 0)) ) ((eq blkname "CART_LV02") (setq pt (cdr (assoc 10 x))) (command "_.Move" blk "" pt '(1178 152.5 0)) ) ((eq blkname "CART_LV03") (setq pt (cdr (assoc 10 x))) (command "_.Move" blk "" pt '(1178 140 0)) ) ((eq blkname "CATIDENTELEA0") (setq pt (cdr (assoc 10 x))) (command "_.Move" blk "" pt '(1178 10 0)) ) ((eq blkname "CATREVBELA0") (setq pt (cdr (assoc 10 x))) (command "_.Move" blk "" pt '(1178 140 0)) ) ) ) 1 Quote
ronjonp Posted July 22, 2022 Posted July 22, 2022 (edited) 8 hours ago, JimmyDev said: Hello, I would like to move a specific block to specific coordinates. In the example below I can select te block "CART_LV02" and I'm able to move it 0.5 to the right. But how how can I move it for example at coordinates x=200 and y=300? (command "MOVE" (ssget "_X" '((0 . "INSERT") (2 . "CART_LV02"))) "" "" '(0.5 0 0)) Many thanks You are just scooching the blocks 0.5 to the right? If so you can change the insertion point rather than use the move command like so ( although if they have attributes entmod does some strange stuff ) (if (setq s (ssget "_X" '((0 . "INSERT") (2 . "*")))) (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq pt (mapcar '+ (assoc 10 (entget blk)) '(0 0.5 0 0))) (entmod (append (entget blk) (list pt))) ) ) Edited July 22, 2022 by ronjonp 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.