Macro: Move/Copy Multiple Objects in One Axe Direction up to a Selected Point

Macro: Move/Copy Multiple Objects in One Axe Direction up to a Selected Point

Nik4_99
Enthusiast Enthusiast
1,808 Views
14 Replies
Message 1 of 15

Macro: Move/Copy Multiple Objects in One Axe Direction up to a Selected Point

Nik4_99
Enthusiast
Enthusiast

Hi all.

A few days ago I opened the topic

Macro: Modifying an ".X" Filter not Successful

the problem was successfully solved, thanks to Sebastian.

I was hoping that I will be able to make on my own a few more macros to speed up the workflow, but it turned out that it is not that easy...

Target:
Move object(s) in the selected direction of one axe - take the desired coordinate from the next selected point.

Semi-solution:
I tried an easy approach mixing "move", "@", "/", ";" but had no success. I tried to combine parts of codes from different sources. Close, but not a solution.
In the end, the only one that did the job was (for me) a rather complicated one:

move;\;(setq p1 (getpoint)) \(list (car (getpoint)) (cadr p1) (caddr p1))

(took the main part of code from here (setq p1 (getpoint "\nPick the point on the screen for the first corner:") ) )

Problem:
I can move one by one object, and the object can't be preselected. I have to start the command, select the (only one) object, select the base point, and then select the point-donor of desired (X or Y or Z) coordinate.

I tried to adopt the code to be able to pre-select multiple, but had no success.

 

Is there a way (of course there is - it's just a matter of knowledge) to move the (pre)selected objects in only one direction, to the that specific (X or Y or Z) coordinate taken from the specific point?

 

Thanks in advance,
N

 

P.s. - I made a "copy" version of the mentioned macro, and tried to make a variants for .xy, .xz, .yz commands. Hopefully, the possible solution will be clear enough that I will be able to make these variants by myself.

 

0 Likes
Accepted solutions (2)
1,809 Views
14 Replies
Replies (14)
Message 2 of 15

Moshe-A
Mentor
Mentor

@Nik4_99  hi,

 


Target:
Move object(s) in the selected direction of one axe - take the desired coordinate from the next selected point.

Semi-solution:
I tried an easy approach mixing "move", "@", "/", ";" but had no success. I tried to combine parts of codes from different sources. Close, but not a solution.
In the end, the only one that did the job was (for me) a rather complicated one:

 

 

 

 

move;\;(setq p1 (getpoint)) \(list (car (getpoint)) (cadr p1) (caddr p1))

 

 

 

 

(took the main part of code from here (setq p1 (getpoint "\nPick the point on the screen for the first corner:") ) )

 


if you can do it manually then it can be done by macro (no use of lisp is needed 😀)

but you cannot have one macro for both XY so make two.

 

[MoveX]^C^Cmove \;\.y @ .xz

[MoveY]^C^Cmove \;\.x @ .yz

 

at first backslash ('\') AutoCAD will pause until you finish selecting objects and the semicolon (';') after will advance to move base point. the '@' will take the X\Y from current selected point.

 

and another cool trick that macros have 😀

if the macro will start with asterisk ('*') this denote multiple action, run it in a loop.

[MoveX]*^C^Cmove \;\.y @ .xz

[MoveY]*^C^Cmove \;\.x @ .yz

 

 

enjoy

Moshe

 

0 Likes
Message 3 of 15

Nik4_99
Enthusiast
Enthusiast

Hi Moshe,

 

thanks for looking into the problem.

 

I tried your code, however - it does not work for me.

 

I drove a few lines.

 

If I preselect the lines, start the command, it asks me to select the base point.

As soon as I select the point - the lines get kind of mirrored away from 0,0, above the selected point. Looks like it uses "<use first point as displacement>" and ends the command (moving in both X and Y dir).

 

If I start the command, and then select the lines, then select the base point - the lines get moved to the new point (with out filtering .y coordinate) - like basic MOVE command.

 

Any idea what's wrong?

I tried to understand the code:

^C^Cmove \;\

part of the code: move, select the object(s), select the base point.

Then

.y filter the Y coordinate from

@

previous point (base point).

 

What about

.xz

It should filter the XY position of next point?

 

Thanks,

Cheers,

N

0 Likes
Message 4 of 15

ВeekeeCZ
Consultant
Consultant

What's wrong about using ORTHO?

0 Likes
Message 5 of 15

Nik4_99
Enthusiast
Enthusiast
I don't understand the question.
I keep ORTHO turned ON 90% of time.
It's excellent help for drawing straight lines etc. But in my case, I often need to move elements in one axe direction, or to keep just one coordinate, and "take" the other two" from the next selected point.
Filters like .X are the tool, and I am using them now, but I look for a way to leave out the unneeded parts.
Select the objects, select the base point, and find the point whose "X" coordinate I need.
Nothing wrong with typing all the commands every time, but then again - nothing wrong with using drawing board and rapidograph pens, and yet, we all look for an easier and faster way...
Cheers,
Nika



0 Likes
Message 6 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

This seems to work, for me, with or without pre-selection [here to Move in the X-axis direction only]:

 

(defun C:MoveX ()
  (if (ssget "_I")
    (command "_.move" pause ".YZ" "@")
    (command "_.move" (ssget) "" pause ".YZ" "@")
  ); if
  (prin1)
)

 

With that loaded [it can be all the time, by acaddoc.lsp], put simply MoveX into a macro button, with or without the common ^C^C prefix that I thought would clear any pre-selection, but in fact doesn't.

 

Similar commands can be defined for the other axis directions.

Kent Cooper, AIA
0 Likes
Message 7 of 15

Moshe-A
Mentor
Mentor

@Nik4_99 , 

 

it did not work cause it was not designed to work with preselect objects. for that we have to modify a little the macro. if you decide to work with all options (with preselect) you will end up with 4 macros (or even 6 for the Z direction)

 

[macro with preselect]

[MoveX]*^C^Cmove \.y @ .xz

[MoveY]*^C^Cmove \.x @ .yz

 

if we do not use .yz it would not be complete reply and autocad will issue (need Z): 

 

Moshe

 

0 Likes
Message 8 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Macros with the selection of multiple objects are possible in... 

** Noun/verb style. That's what Moshe suggested.

** Or Verb/Noun style. SELECT;\MOVE;P;;....

 

But it isn't easy to make them work both together. Therefore is it better to use a LISP, as Kent suggests, or just a macro (without the command name):

((lambda () (command "_.move" (ssget) "" pause ".YZ" "@")))

Message 9 of 15

Moshe-A
Mentor
Mentor

@ВeekeeCZ  hi,

 


((lambda () (command "_.move" (ssget) "" pause ".YZ" "@")))


Can you please explain what is the idea of using this form in putting the (command) in (lambda), does it have any advantage?

 

Moshe

0 Likes
Message 10 of 15

ВeekeeCZ
Consultant
Consultant

@Moshe-A wrote:

 


((lambda () (command "_.move" (ssget) "" pause ".YZ" "@")))


Can you please explain what is the idea of using this form in putting the (command) in (lambda), does it have any advantage?

 

Moshe


 

@Moshe-A 

 

It's so to have a self-running command that could be repeated by RT click or enter. Also, variables could be localized there if needed.

0 Likes
Message 11 of 15

Moshe-A
Mentor
Mentor

@ВeekeeCZ ,

 

command: LINE <point> <point> <enter>

((lambda () (command "_.move" (ssget) "" pause ".YZ" "@")))

command:  <enter>

invoke the LINE command (not the macro)

 

what i'm missing?

 

 

0 Likes
Message 12 of 15

ВeekeeCZ
Consultant
Consultant

This was supposed to be a "macro" resp "command string" for the Tool Palettes launched with a click.

 

BeekeeCZ_0-1671222099730.png

0 Likes
Message 13 of 15

Sea-Haven
Mentor
Mentor

An oldy and I do mean old. 

 

(defun C:CHX ()
  (SETVAR "CMDECHO" 0)
  (setq sn (getvar "osmode"))
  (command "osnap" "near")
  (princ "\nalters object in X direction")
  (setq ht (getstring "\n What is amount of change: "))
  (setq newht (strcat ht ",0"))
  (while (setq newobj (entsel "\nPoint to object: "))
    (command "move" newobj "" "0,0" newht)
  )
)
;
(defun C:CHY ()
  (SETVAR "CMDECHO" 0)
  (setq sn (getvar "osmode"))
  (command "osnap" "near")
  (princ "alters object in Y direction")
  (setq ht (getstring "\n What is amount of change: "))
  (setq newht (strcat  "0," ht))
  (while (SETQ NEWobj (entsel "\nPoint to object: "))
    (command "move" newobj "" "0,0" newht)
  )
)

;simple routine to change objects in the z direction
(defun C:CHZ ()
  (SETVAR "CMDECHO" 0)
  (setq sn (getvar "osmode"))
  (command "osnap" "near")
  (setq x 0)
  (princ "alters object in Z direction")
  (setq ht (getstring "\n What is amount of change: "))
  (setq newht (strcat "0,0," ht))
  (while (SETQ NEWobj (entsel "\nPoint to object: "))
    (command "move" newobj "" "0,0,0" newht)
  )
)

 

0 Likes
Message 14 of 15

Nik4_99
Enthusiast
Enthusiast

Hey guys,

I was absent from work yesterday (as well as during the weekend), and you all have been quite active and productive 🙂

Thank you all very much for replies and solutions,

I will check them all.

Cheers,

Nika

0 Likes
Message 15 of 15

Nik4_99
Enthusiast
Enthusiast


@Kent1Cooper

Your macro is working as expected, with preselection as well as with command start first. Thank you very much.
I have managed to adopt the code for other directions. Once again - thank you.

 

@ BeekeeCZ

((lambda () (command "_.move" (ssget) "" pause ".YZ" "@")))

This command work with both preselected objects and if the command is started first. Thank you very much, this is exact what I was looking for.

I also tried

((lambda () (command "_.move" (ssget) "" pause ".X" "@")))

to keep the X coordinate of the (pre)selected objects, and to take the Y and Z coordinate of the next selected point - and it works also.

 

Basically - both approaches are fully applicable.

 

@ Moshe-A

^C^Cmove \.x @ .yz


This one keeps the X coordinate of the preselected objects, and take the Y and Z coordinates of the next selected point.
A little modified

^C^Cmove \.yz @ .x

does the trick.
However - it is limited to the preselected objects.
Anyway - thank you for your time.

 

@ Sea-Haven

Your macro is not running as expected.
- I can't preselect any object.
- Once the command "CHX" is activated - I get the question "What is ammount of change". When I enter (for example) 1000 - I can select just one object and the macro moves the object in X dirrection by 1000.
- if I try to rectangle select multiple objects - I get "Point to object: nil" with command terminated.
- I am not able to select next point and to "take" the X coordinate for movement...

Thank you anyway for your time.