Move Objects to Specific Coordinates

Move Objects to Specific Coordinates

Anonymous
Not applicable
6,298 Views
10 Replies
Message 1 of 11

Move Objects to Specific Coordinates

Anonymous
Not applicable

Has anybody got a macro or lisp to move objects to specific coordinates?

 

I'd like to select the objects, specify the base point then move to 0,0,0

 

I know that entering a '#' before the coordinates overrides Dynmode, but I am forgetful & keep forgetting to switch off Dynmode or use the '#'

 

I might be as follows:

 

DYNMODE 0 ;;switch dynmode off
MOVE
(Select Objects)
(Specify Second Point)
0,0,0;; second point
DYNMODE 1 ;;switch dynmode back on

0 Likes
Accepted solutions (1)
6,299 Views
10 Replies
Replies (10)
Message 2 of 11

hmsilva
Mentor
Mentor
Accepted solution

Something like this, perhaps...

 

(defun c:demo ( / pt ss)
  (if (and (princ "\n Select objects to move to 0,0 ")
	   (setq ss (ssget "_:L"))
	   (setq pt (getpoint "\n Enter base point: "))
	   )
    (command "_move" ss "" "_NONE" pt "_NONE" '(0.0 0.0 0.0))
    )
  (princ)
  )

 

Henrique

EESignature

Message 3 of 11

Anonymous
Not applicable
Excellent, exactly as required

Thank you hmsilva

Simon
0 Likes
Message 4 of 11

hmsilva
Mentor
Mentor
You're welcome, Simon
Glad I could help

Henrique

EESignature

0 Likes
Message 5 of 11

mihai_bantas
Enthusiast
Enthusiast

Hi, I need some help.
I want to move 4 items at the same time ... I tried to adapt the code below and do not know where I'm wrong.
Thank you for your time.

 

(defun c:test ( / p1 p2 p3 p4 ss )
    (if
        (and
            (setq ss (ssget "_:L"))
            (setq p1 (getpoint "\Point for Basepoint1: "))
            (setq p2 (getpoint "\Point for Basepoint2: "))
            (setq p3 (getpoint "\Point for Basepoint3: "))
            (setq p4 (getpoint "\Point for Basepoint4: "))
        )
		(progn
		(command "_.move" ss "" "_none" p1 "_none" '(25.00 166.00 0.00))
		(command "_.move" ss "" "_none" p2 "_none" '(25.00 45.00 0.00))
		(command "_.move" ss "" "_none" p3 "_none" '(217.50 166.00 0.00))
		(command "_.move" ss "" "_none" p4 "_none" '(217.50 45.00 0.00))
		)
)
	(princ)
 )

 

0 Likes
Message 6 of 11

Kent1Cooper
Consultant
Consultant

@mihai_bantas wrote:

....I want to move 4 items at the same time .... 


That code will Move all of them, together [the 'ss' variable], four times, leaving their positional relationship to each other as it was originally.  Are you trying to move each one of them to one of those destination points?  If so, are P1/P2/P3/P4 on the items, so that they could be used for selection as well as the Move base points?

 

It would be possible to Move one of them in each Move command with (ssname) to get just one out of the selection set, but you would need to specify that they be selected in order -- with a "raw" (ssget) to select them, if you did that with a window, the order they'd be Moved would be determined, I think, by drawing order, so you couldn't count on the results.

 

And it would be worth testing that the selection is of four and only four objects, with (sslength), before proceeding.

 

What kind(s) of objects are you talking about?  If they have some logical reference point [such as a Block's insertion point, or a Circle's center], could those be used as the Move base points, without having the User pick the base points?

Kent Cooper, AIA
Message 7 of 11

mihai_bantas
Enthusiast
Enthusiast

Hi Kent (thanks for the reply) .... I want to automatically mute cross sections into sheet page. I attached you a DWG with objects I want to move.

 

Thank you for your time.

0 Likes
Message 8 of 11

Kent1Cooper
Consultant
Consultant

You're certainly not going to be able to do that with just one selection.  It will probably require an approach something like this [lightly tested]:

 

(prompt "\nTo move detail to UPPER LEFT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(25 166 0))

(prompt "\nTo move detail to LOWER LEFT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(25 45 0))

(prompt "\nTo move detail to UPPER RIGHT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(217.5 166 0))

(prompt "\nTo move detail to LOWER RIGHT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(217.5 45 0))

 

The pauses are for User input of the Move base point [answering the Move command's own prompt], what you indicate as PT1/PT2/PT3/PT4, but no variables are needed this way.  It worked for me in your drawing when Zoomed in around the source area, without the sheet area visible.  [I find that the ones that go in the left side are too wide for the quadrants in the sheet.]

 

I omitted the "none" Osnap call before the destination points, on the assumption that if you have running Osnap on, it will probably include END and/or INT mode(s), so it won't snap to anything other than the quadrant-rectangle corners anyway.  If you might ever have something like only MIDpoint Osnap mode running, things would go to the wrong place -- put the "none" calls  back in.

 

By the way, the trailing zeros in your point-coordinate lists do nothing at all for you, nor even the decimal point if nothing but zeros follow it.

Kent Cooper, AIA
0 Likes
Message 9 of 11

mihai_bantas
Enthusiast
Enthusiast

hy kent,

I managed to make my code to bring the four frames in the desired points.

(defun c:test ( / p1 p2 p3 p4 ss1 )
    (if
        (and
            (setq ss1 (ssget "_:L"))
                (setq p1 (getpoint "\Point for Basepoint1: "))
                (setq ss2 (ssget "_:L"))
                (setq p2 (getpoint "\Point for Basepoint2: "))
                (setq ss3 (ssget "_:L"))
                (setq p3 (getpoint "\Point for Basepoint3: "))
                (setq ss4 (ssget "_:L"))
                (setq p4 (getpoint "\Point for Basepoint4: "))
        )
        (progn
        (command "_.move" ss1 "" "_none" p1 "_none" '(25.00 166.00 0.00))
        (command "_.move" ss2 "" "_none" p2 "_none" '(25.00 45.00 0.00))
        (command "_.move" ss3 "" "_none" p3 "_none" '(217.50 166.00 0.00))
        (command "_.move" ss4 "" "_none" p4 "_none" '(217.50 45.00 0.00))
        )
)
    (princ)
 )
0 Likes
Message 10 of 11

Kent1Cooper
Consultant
Consultant

Just some thoughts....

 

My approach does not require setting any variables at all.  [In yours, you should also localize ss2/ss3/ss4.]

 

Your version requires the User to know which quadrant of the sheet is 1, which is 2, etc., whereas my prompts inform them which quadrant they're filling.

 

What if you don't have enough details remaining to fill all four quadrants of a sheet?  Your version requires four and only four selections.  It won't Move any of them if you have fewer than that.

 

You can add the "_:L" locked-layer-prevention part to the (ssget) functions in my version, but it really serves no purpose.  If there are things on locked Layers, in my version (ssget) will select them, but Move will leave them behind anyway, so the effect will be exactly the same as if it prevented selection of them.  If it happens that all objects you try to select for a given detail are on locked Layers, it will fail, but so will your version, which won't Move any of the selections if any one of them is of objects all on locked Layers.

Kent Cooper, AIA
Message 11 of 11

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... 

(prompt "\nTo move detail to UPPER LEFT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(25 166 0))

(prompt "\nTo move detail to LOWER LEFT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(25 45 0))

(prompt "\nTo move detail to UPPER RIGHT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(217.5 166 0))

(prompt "\nTo move detail to LOWER RIGHT quadrant in sheet,")

(command "_.move" (ssget) "" pause '(217.5 45 0))

....


A more concise way to do that:

 

(foreach entry
  '(("UPPER LEFT" (25 166 0)) ("LOWER LEFT" (25 45 0)) ("UPPER RIGHT" (217.5 166 0)) ("LOWER RIGHT" (217.5 45 0)))
  (prompt (strcat "\nTo move detail to " (car entry) " quadrant in sheet,"))
  (command "_.move" (ssget) "" pause (cadr entry))
); foreach

 

Comments in Post 8 also apply.

Kent Cooper, AIA