Move all circles to new center

Move all circles to new center

Anonymous
Not applicable
1,609 Views
7 Replies
Message 1 of 8

Move all circles to new center

Anonymous
Not applicable

I need to move all circles on the page to a new point.

 

My current code is something like this:

(setq newCenter (getpoint "new center:"))
(setq circles (ssget "_X" '((0 . "CIRCLE")))) (setq n (sslength circles)) (setq x 0) (repeat n (setq name (ssname circles x)) (setq circle (entget name)) (setq center (cdr (assoc 10 circle)))
(setq circle (subst '(10 . newCenter) '(10 . center) circle))
(entmod circle)
(setq x (+ 1 x))
)

But, for some reason, it doesn't work. Need help!

 

0 Likes
Accepted solutions (2)
1,610 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

This line has to be like this. '(variable) won't evaluate a variable

 

(setq circle (subst (cons 10 newCenter) (cons 10 center) circle))
Message 3 of 8

hak_vz
Advisor
Advisor
Accepted solution
(setq newCenter (getpoint "new center:"))
(setq circles (ssget "x" '((0 . "CIRCLE"))))
(setq n (sslength circles))
(setq x 0)
(repeat n
  (setq name (ssname circles x))
  (setq circle (entget name))
  (setq center (cdr (assoc 10 circle)))
  (setq circle (subst (cons 10 newCenter) (assoc 10 circle) circle))
  (entmod circle)
  (setq x (+ 1 x))
)   

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 4 of 8

CodeDing
Advisor
Advisor

@Anonymous ,

 

When using variables in list creation, you are not able to use the QUOTE ... ' ...

So, you must use the "list" and "cons" functions. Hope this helps!

(initget 1) (setq newCenter (getpoint "\nSelect new center: ")) (princ newCenter)
(if (setq circles (ssget "_X" (list '(0 . "CIRCLE") (cons 410 (getvar 'CTAB)))))
  (repeat (setq n (sslength circles))
    (setq name (ssname circles (setq n (1- n))))
    (setq circle (entget name))
    (setq circle (subst (cons 10 newCenter) (assoc 10 circle) circle))
    (entmod circle)
  );repeat
;else
  (prompt "\n...No circles found")
);if

Best,

~DD

Message 5 of 8

hak_vz
Advisor
Advisor

@CodeDing  @ВeekeeCZ  Here we have nice sequence how to update simple code.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 6 of 8

ВeekeeCZ
Consultant
Consultant

Well, that was a nice coincidence... The sadder but expected thing is that the best answer is the least welcome.

Message 7 of 8

CodeDing
Advisor
Advisor

Lol, it's ok! Perhaps somebody in the future can find it useful still!

0 Likes
Message 8 of 8

Kent1Cooper
Consultant
Consultant

How 'bout something like this?  Instead of pulling apart entity data and replacing part of it, you can just assign the new Center more directly as a VLA property:

(vl-load-com); if necessary
(setq
  newCenter (getpoint "New Center for all Circles:")
  circles (ssget "_X" '((0 . "CIRCLE")))
); setq
(repeat (setq n (sslength circles))
  (vlax-put
    (vlax-ename->vla-object (ssname circles (setq n (1- n))))
    'Center newCenter
  ); vlax-put
); repeat
Kent Cooper, AIA
0 Likes