Quick copy with spacing - LISP

Quick copy with spacing - LISP

Lukasvop1
Advocate Advocate
1,644 Views
13 Replies
Message 1 of 14

Quick copy with spacing - LISP

Lukasvop1
Advocate
Advocate

Hello guys, I found awesome video with lisp who can easy create multiple copy of object with spacing only with move with mouse.

Can you guys create something like this? Will be great if will be possible create copy in any direction, any spacing (Pick this spacing from drawing).

 

 

@komondormrex @Kent1Cooper 

0 Likes
Accepted solutions (1)
1,645 Views
13 Replies
Replies (13)
Message 2 of 14

komondormrex
Mentor
Mentor

sure thing)

Message 3 of 14

Kent1Cooper
Consultant
Consultant

I have something at least very similar, called CopyAgain.lsp with its CA command, >here<.  It doesn't do the number of copies drag-wise as in your video, but it's close -- you choose what you want to Copy, and specify the displacement by any method the command accepts, and then you hit Enter/space as many times as you want, and with each one it makes another copy of the object(s), displaced at the same distance and direction from the previous copy.  ESCape ends the repeating Copying.

CopyAgain.gif

Kent Cooper, AIA
0 Likes
Message 4 of 14

Lukasvop1
Advocate
Advocate

Thank you Kent, I appreciate your response but when I need copy object 30 times and next one x times and so on.. I will broke my enter key.

0 Likes
Message 5 of 14

CADaSchtroumpf
Advisor
Advisor

And can't the ARRAY command do this job?

0 Likes
Message 6 of 14

Lukasvop1
Advocate
Advocate

Nope, but this should be in Array function default, this thing missing here.

0 Likes
Message 7 of 14

komondormrex
Mentor
Mentor
Accepted solution

here goes a quick shot for your evaluation) need tuning thou.

 

 

 

 

 

;****************************************************************************************************************************

;	komondormrex, jul 2023

;****************************************************************************************************************************

(defun crd (in_list)
	(reverse (cdr (reverse in_list)))
)

;****************************************************************************************************************************

(defun c:dynamic_multiple_copy (/ copy_index command_finished original_copy_instance copied_set base_point second_point
				  copy_distance error_ocurred copied_point current_copy_index
			       )
	(setq copy_index 0
		  original_copy_instance (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget)))))
		  copied_set (list (list copy_index original_copy_instance))
		  base_point (getpoint "\nPick base point: ")
		  second_point (getpoint base_point "\nPick second point: ")
		  copy_distance (distance base_point second_point)
	)
	(while (not command_finished)
		   (setq error_ocurred (if (vl-catch-all-error-p (setq grread_data (vl-catch-all-apply 'grread (list t 12 0)))) t nil))
		   (redraw)
	       	   (cond
			(
				error_ocurred
					(prompt "\nCommand cancelled")
					(mapcar 'vla-erase (apply 'append (mapcar 'cadr (cdr copied_set))))
					(setq command_finished t)
			)
			(
				(= 5 (car grread_data))
					(grdraw base_point
							(setq copied_point (inters base_point
						    				   second_point
						    				   (cadr grread_data)
						    				   (polar (cadr grread_data) (+ (* 0.5 pi) (angle base_point second_point)) 1)
						    				   nil
									   )
						    )
							1
					)
					(cond
						(
							(and
								 (< (car (last copied_set)) (setq current_copy_index (fix (/ (distance base_point (cadr grread_data)) copy_distance))))
								 (null (assoc current_copy_index copied_set))
							)
								(repeat (- current_copy_index (car (last copied_set)))
									(foreach object (setq copied_instance (mapcar 'vla-copy original_copy_instance))
										(vla-move object (vlax-3d-point (trans base_point 1 0))
														 (vlax-3d-point (trans (polar base_point
														 							  (angle base_point copied_point)
																					  (* (setq added_copy_index (1+ (car (last copied_set)))) copy_distance)
																			   )
																			   1 0
																		)
														 )
										)
									)
									(setq copied_set (append copied_set (list (list added_copy_index copied_instance))))
								)
						)
						(
							t
								(repeat (- (car (last copied_set)) current_copy_index)
									(mapcar 'vla-erase (cadr (last copied_set)))
									(setq copied_set (crd copied_set))
								)
						)
					)
			)
			(
				(= 3 (car grread_data))
					(setq command_finished t)
			)
			(
				t
					(prompt "\nWrong key pressed!")
			)
		   )
	)
	(princ)
)

;****************************************************************************************************************************

 

 

 

 

 

Message 8 of 14

Lukasvop1
Advocate
Advocate

Nice, you re like god of lisp, but I found little bit issue when I want copy object vertically sent me error.

dynamic copy issue.png

0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

@CADaSchtroumpf wrote:

And can't the ARRAY command do this job?


Certainly it can!  Here's a horizontal one very like the Message 1 video:

 

(defun C:AHD (/ ss); = Array Horizontally, Dynamic
  (if (setq ss (ssget "_:L"))
    (progn ; then
      (initcommandversion)
      (command "_.array" ss "" "_rectangular"
        "_rows" 1 "" ""
        "_columns" 2 (getdist)
      ); command
    )
  ); if
  (prin1)
)

 

That leaves you with two of them, likely not initially at the right spacing but it's asking you for the spacing, so give it that [either by picking two points as in the video or typing in a value], and then you're left to grab the grip and drag for the number of columns, as in the video.

ahd.gif

It works whether you have ARRAY set to be Associative or not, but that choice could be built in if you have a preference.  Also set DELOBJ for whether you want the source object(s) to remain in addition to the Array result.

 

A single command could be made to offer the choice of going horizontal or vertical, or separate commands could be defined, or....

Kent Cooper, AIA
0 Likes
Message 10 of 14

komondormrex
Mentor
Mentor

check update in 7.

0 Likes
Message 11 of 14

Lukasvop1
Advocate
Advocate

Now it's perfect, exactly the same as on the video, thank you.

0 Likes
Message 12 of 14

komondormrex
Mentor
Mentor

your welcome)

0 Likes
Message 13 of 14

Sea-Haven
Mentor
Mentor

if you want to copy objects on an angle array will work when you say pick start point, end point for angle line use UCS OB (entlast) or UCS 2 points than array will match the angle. Then UCS W to return back. 

 

0 Likes
Message 14 of 14

Lukasvop1
Advocate
Advocate

Yes, but this is simplified, komondormrex solved it in his script.

 

1.) select object to array
2.) pick base point
3.) pick second point - define "angle" and "spacing" at the same time
4.) drag mouse - increase/decrease "number of copies"

0 Likes