Jump to content

Recommended Posts

Posted

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

Posted

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

 

  • Like 1
Posted
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.

Posted

FYI

If their is more then one block they are all on top of each other at (0.5 0 0)

Posted

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

Posted

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

  • Like 3
Posted
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.!

  • Like 1
Posted (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 by mhupp
  • Like 1
Posted

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.

 

Posted

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

 

  • Like 1
Posted (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 by ronjonp
  • Like 1

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