Batch Align multiple objects

Batch Align multiple objects

rponsell
Participant Participant
3,203 Views
8 Replies
Message 1 of 9

Batch Align multiple objects

rponsell
Participant
Participant

Is there a way to use LISP or macro to align multiple objects to multiple other objects?

In the Sample.dwg I have 6 rectangles: 1, 2, 3, A, B, and C. I have shown what I would be starting with and what I would like to to look like when finished (rectangles A, B, C on top of 1, 2, 3).

 

Essentially, I want to use the align command multiple times without the need to repeat the command. Pick one point on each object and give them each a separate destination.

 

Any ideas?

 

Thanks,

 

Ryan

0 Likes
Accepted solutions (1)
3,204 Views
8 Replies
Replies (8)
Message 2 of 9

Sea-Haven
Mentor
Mentor

This is a simple approach say as a start. I can see a real dwg being a lot more complex than just 1=A and so on this could be done but what happens when no B ?

 

(defun c:stack ( / obj point1min point2min point2max point2max ss)
(while (setq ent1 (entsel "\nPick 1st object Enter to exit"))
	(setq obj (vlax-ename->vla-object (car ent1)))
		(vla-GetBoundingBox obj 'minpoint 'maxpoint)
		(setq point1min (vlax-safearray->list minpoint))
		(setq point1max (vlax-safearray->list maxpoint))
	(setq ent2 (entsel "\nPick object to move "))
		(setq obj (vlax-ename->vla-object (car ent2)))
		(vla-GetBoundingBox obj 'minpoint 'maxpoint)
		(setq point2min (vlax-safearray->list minpoint))
		(setq point2max (vlax-safearray->list maxpoint))
		(setq ss (ssget "W" point2min point2max))
	(command "move" ss "" point2min (list (car point1min)(cadr point1max)))
)
(princ)
)

 

 

0 Likes
Message 3 of 9

pbejse
Mentor
Mentor
Accepted solution

@rponsell wrote:

Essentially, I want to use the align command multiple times without the need to repeat the command. Pick one point on each object and give them each a separate destination.

 


Command: MULTIPLE
Enter command name to repeat: align

it will start the command immediately and continue until you done want it anymore 

Try it

 

 

 

 

0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

Not sure whether your sample drawing is just too much simplified, but I would simply MOVE the objects.

0 Likes
Message 5 of 9

JTBWorld
Advisor
Advisor

You might find our app JTB Align Plus helpful. 


Jimmy Bergmark
JTB World - Software development and consulting for CAD and license usage reports
https://jtbworld.com

0 Likes
Message 6 of 9

rponsell
Participant
Participant

I forgot all about the MULTIPLE command. It does increase my workflow, and I'm going to count this as a solution. I am still interested in finding a way to select all the objects at once, then using the ALIGN or MOVE commands on each item in the selection set separately rather than the whole set. I basically want to eliminate the step when using MULTIPLE -> ALIGN/MOVE and having to select a new object each time.

 

That may be being too picky though, lol. MULTIPLE works great. Thanks for the reminder!

 

Ryan

0 Likes
Message 7 of 9

rponsell
Participant
Participant

I forgot all about the MULTIPLE command. It does increase my workflow, and I'm going to count this as a solution. I am still interested in finding a way to select all the objects at once, then using the ALIGN or MOVE commands on each item in the selection set separately rather than the whole set. I basically want to eliminate the step when using MULTIPLE -> ALIGN/MOVE and having to select a new object each time.

0 Likes
Message 8 of 9

ВeekeeCZ
Consultant
Consultant

How about something like this.

 

(defun c:MoveR ( / p e)
  (while (setq p (getpoint "\nSource ref point: "))
    (if (or (setq e (car (nentselp p)))
	    (and (setq e (car (entsel "\nNOT SELECTED, select manually: ")))
		 (setq p (getpoint "\nSource ref point: "))))
      (command-s "_.move" e "" p)))
  (princ)
  )

 

This will work if your ref. points are laying ON an object to move. Then the object is selected automatically.

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant
@rponsell wrote:

... I want to use the align command multiple times without the need to repeat the command. Pick one point on each object and give them each a separate destination.

....

I am still interested in finding a way to select all the objects at once, then using the ALIGN or MOVE commands on each item in the selection set separately rather than the whole set. ....


If they're already oriented correctly as in the sample drawing, so that MOVE will do instead of ALIGN, and if those letters are only for identification and not part of what you want to reposition, then here's another way:

 

(defun C:MultiMove (/ ss n)
  (prompt "\nTo Move a selected set of objects, each individually,")
  (if (setq ss (ssget "_:L")); [reject things on locked Layers]
    (repeat (setq n (sslength ss))
      (command "_.move" (ssname ss (setq n (1- n))) "" pause pause)
    ); repeat
  ); if
  (princ)
); defun

 

Each one is selected/highlighted so you can see which one it's Moving as it steps through.  Pick your "one point on each object" and then its "separate destination."

Kent Cooper, AIA
0 Likes