LISP to move blocks closer to each other

LISP to move blocks closer to each other

kevin8UQA6
Explorer Explorer
333 Views
3 Replies
Message 1 of 4

LISP to move blocks closer to each other

kevin8UQA6
Explorer
Explorer

I have a lisp routine that takes the first 2 blocks in a selection set and moves them 2 inches closer together. Sometimes the code works perfectly fine, other times it won't work at all even if I am dealing with the same set of blocks selected where it worked before. All my blocks are at least 24 inches apart, and I always select 2 or more blocks, so I don't think i need to worry about those issues. Here is my code:

 

 

 

(defun c:HDM ()
	(setq HDS (ssget '((0 . "INSERT"))))
	(setq HDDa (ssname HDS 0))
	(setq HDDb (ssname HDS 1))	
	(setq HDa (entget (ssname HDS 0)))
	(setq HDb (entget (ssname HDS 1)))
    (setq insA(cdr (assoc 10 HDa)))
	(setq insB(cdr (assoc 10 HDb)))
	(setq angA (angle insA insB) )
	(setq angB (angle insB insA) )
	(setq pt1 (polar insA angA 2))
	(setq pt2 (polar insB angB 2))
	(command "._move" HDDa "" insA pt1)
	(command "._move" HDDb "" insB pt2)
	(princ)
)

 

Any thoughts on where I may have gone wrong?

0 Likes
Accepted solutions (1)
334 Views
3 Replies
Replies (3)
Message 2 of 4

pendean
Community Legend
Community Legend
Can you share a DWG file with blocks where this LISP failed in?
0 Likes
Message 3 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

Most likely running OSNAP modes.

 

(defun c:HDM ()
  (setq HDS (ssget '((0 . "INSERT"))))
  (setq HDDa (ssname HDS 0))
  (setq HDDb (ssname HDS 1))
  (setq HDa (entget (ssname HDS 0)))
  (setq HDb (entget (ssname HDS 1)))
  (setq insA(cdr (assoc 10 HDa)))
  (setq insB(cdr (assoc 10 HDb)))
  (setq angA (angle insA insB) )
  (setq angB (angle insB insA) )
  (setq pt1 (polar insA angA 2))
  (setq pt2 (polar insB angB 2))
  (command "._move" HDDa "" "_non" insA "_non" pt1)
  (command "._move" HDDb "" "_non" insB "_non" pt2)
  (princ)
  )

 

Other possible issues - UCS, variables not localized.

0 Likes
Message 4 of 4

kevin8UQA6
Explorer
Explorer

The OSNAP setting were throwing it off. Everything works perfectly as intended.

0 Likes