Jump to content

Multiple copy of selected objects


Isaac26a

Recommended Posts

Hello everyone, I was trying to find out a way to solve this task, that for many of you may be boring or simple, but I happen to deal with this from time to time, I have this texts or other objects that are in a rectangle and I have to copy this items in so many rectangles in order to continue with other tasks, as you may see in the pictures it can't be solved using an array because they're not all in the same size.

I was thinking that a way to approach this matter is to create a selection set of the objects and a list of the polylines (rectangles) where I should copy the objects and do a loop with while, but how do I get to paste them in the lower right corner of every object if that is my reference point.

I hope you can help me solve this matter or at least give me some hints or directions, thanks in advance to you all.example01.thumb.png.3ff59f8488caff179f99c770f2d06994.pngexample02.thumb.png.0ba6b323cfaebc3273f0c3edff16548b.png

example.dwg

Link to comment
Share on other sites

Try this

 

; copy an object to multi rectangs 
; based on Lower Right cnr of rectang
; By AlanH Jan 2021

(defun c:test ( / ss lst co-ord ent pt x )
(setq ss (ssget (list (cons 0 "LWpolyline")))) ; select all the rectangs 1st
(setq lst '())
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (- x 1))))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))))
(setq co-ord (vl-sort co-ord
	 '(lambda (a b)
	    (cond
	      ((< (car a) (car b)))
	      ((= (car a) (car b)) (< (cadr a) (cadr b)))
	    )
	  )
))
(setq pt (list (car (nth 2 co-ord))(cadr (nth 2 co-ord)) 0.0))
(setq lst (cons pt lst))
)
(princ "\n")
(princ "\nSelect objects to copy ")
(setq ss (ssget)) ; select all the objects to copy 
(setq pt (getpoint "\nPick base point LR ? "))
(repeat (setq x (length lst))
(setq pt2 (nth (setq x (- x 1)) lst))
(command "copy" ss "" pt pt2)
)
(princ)
)

 

Edited by BIGAL
  • Like 2
Link to comment
Share on other sites

36 minutes ago, BIGAL said:

Try this

 


; copy an object to multi rectangs 
; based on Lower Right cnr of rectang
; By AlanH Jan 2021

(defun c:test ( / ss lst co-ord ent pt x )
(setq ss (ssget (list (cons 0 "LWpolyline"))))
(setq lst '())
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (- x 1))))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))))
(setq co-ord (vl-sort co-ord
	 '(lambda (a b)
	    (cond
	      ((< (car a) (car b)))
	      ((= (car a) (car b)) (< (cadr a) (cadr b)))
	    )
	  )
))
(setq pt (list (car (nth 2 co-ord))(cadr (nth 2 co-ord)) 0.0))
(setq lst (cons pt lst))
)
(princ "\n")
(princ "\nSelect objects to copy ")
(setq ss (ssget))
(setq pt (getpoint "\nPick base point LR ? "))
(repeat (setq x (length lst))
(setq pt2 (nth (setq x (- x 1)) lst))
(command "copy" ss "" pt pt2)
)
(princ)
)

 

Hey man, I really appreciate your help, Thank you very much, It works perfectly. At the beginning I was expecting to select the objects to copy, but then I read the code and found out that you first ask for the objects where it's going to be copied. It does what was expected.

Thanks again Alan

Link to comment
Share on other sites

I am hoping to fix up problem of posting a movie to show how to use code. You can change the order if you want just make one of the selection sets say ss2 move the ssget to above the other asking in the order you want.

 

 

 

Link to comment
Share on other sites

2 hours ago, BIGAL said:

I am hoping to fix up problem of posting a movie to show how to use code. You can change the order if you want just make one of the selection sets say ss2 move the ssget to above the other asking in the order you want.

 

 

 

Really there's no need for that, I just didn't know how to indicate the bottom right corner of the list of objects, but you did all the solution. A really good one. Thanks, and you're right, just have to swap the order.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...