How to modify lisp to do automatically copy

How to modify lisp to do automatically copy

tencome
Contributor Contributor
522 Views
4 Replies
Message 1 of 5

How to modify lisp to do automatically copy

tencome
Contributor
Contributor

Hello guys, 

 

CAD file have 3 graphics  in area (0:0) to (50:50),  I want one lisp command to perform three layer simultaneous copies and  moves.   How to modify below lisp to do automatically copy?   

 

 

layer names 1, 2, and 3. 

Layer 1 needs to be copied and offset horizontally by 50mm along the X-axis,

layer 2 needs to be copied and offset vertically by 50mm along the Y-axis,

layer 3 needs to be copied and offset horizontally by 50mm along the X-axis and vertically by 50mm along the Y-axis.

 

(defun c:CopyAndOffsetLayers (/ ss1 ss2 ss3)  
  (setq ss1 (ssget '((0 . "CIRCLE,LINE,*") (8 . "1"))))  
  (if ss1  
    (progn  
      (command "_.copy" ss1 "" "_non" '(50 0))  
      (princ "\nlayer1Xoffset50\n")  
    )  
  )  
  (setq ss2 (ssget '((0 . "CIRCLE,LINE,*") (8 . "2"))))  
  (if ss2  
    (progn  
      (command "_.copy" ss2 "" "_non" '(0 50))  
      (princ "\nlayer2Yoffset50\n")  
    )  
  )  
  (setq ss3 (ssget '((0 . "CIRCLE,LINE,*") (8 . "3"))))  
  (if ss3  
    (progn  
      (command "_.copy" ss3 "" "_non" '(50 50)) 
      (princ "\nlayer3X&Yoffset50\n")  
    )  
  )  
  (princ)  
)  
  
(princ "\nCOPYANDOFFSETLAYERS\n")  
(princ)

 

 

0 Likes
Accepted solutions (2)
523 Views
4 Replies
Replies (4)
Message 2 of 5

ryanatkins49056
Enthusiast
Enthusiast

Just a few quick things to double check, (I'm not allowed to download that attached file to my work machine)

Are they just a single set of entities that you wish to copy three times to three separate layers and then move them to separate positions depending on the layer they have been give?
Do you wish for the items to be selected automatically first time round or you select the items first time round manually then they are automatically selected as you process through each layer?

In the example you posted what is the "non" part of the command? (I use the english language version and that would be displacement).

0 Likes
Message 3 of 5

komondormrex
Mentor
Mentor
Accepted solution

hey,

check this

(defun c:copy_move_1_2_3 (/ move_sset)
	(if (setq move_sset (ssget "_w" '(0 0) '(50 50) '((8 . "1,2,3"))))
		(foreach object (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex move_sset))))
			(cond
				((= "1" (vla-get-layer object))
					(vla-move (vla-copy object) (vlax-3d-point 0 0) (vlax-3d-point 50 0))
				)
				((= "2" (vla-get-layer object))
					(vla-move (vla-copy object) (vlax-3d-point 0 0) (vlax-3d-point 0 50))
				)
				((= "3" (vla-get-layer object))
					(vla-move (vla-copy object) (vlax-3d-point 0 0) (vlax-3d-point 50 50))
				)
			)
		)
	)
	(princ)
)

 

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

 

If what is to be Copied is everything on each Layer:

 

(defun C:C123 (/ ss)
  (foreach entry '(("1" (50 0)) ("2" (0 50)) ("3" (50 50)))
    (if (setq ss (ssget "_X" (list (cons 8 (car entry)))))
      (command "_.copy" ss "" (cadr entry) "")
    ); if
  ); foreach
  (prin1)
)

 

If only those things within that initial area:

 

(defun C:C123 (/ ss)
  (foreach entry '(("1" (50 0)) ("2" (0 50)) ("3" (50 50)))
    (if (setq ss (ssget "_W" '(0 0) '(50 50) (list (cons 8 (car entry)))))
      (command "_.copy" ss "" (cadr entry) "")
    ); if
  ); foreach
  (prin1)
)

 

It's the "_X" in the first one [for finding everything that fits the filter], and the "_W" with following window corners in the second one [for defines the selection area], that make them automatic, not requiring User selection.

Kent Cooper, AIA
Message 5 of 5

Kent1Cooper
Consultant
Consultant

By the way, this [Layer 2 instance]:

(setq ss2 (ssget '((0 . "CIRCLE,LINE,*") (8 . "2"))))

has an object-type entry in the filter that makes it pointless.  The asterisk * allows it to select any and all kinds of objects, which is what makes it usable in your sample drawing with some Polylines.  With the resulting no limit on object type, that whole filter entry serves no purpose, and this would have exactly the same result:

(setq ss2 (ssget '((8 . "2"))))

The routines in Message 4 could have object-type filtering added if needed.

And these:

(command "_.copy" ss2 "" "_non" '(0 50))

need the second point of displacement [in this case Enter for use-the-first-point-as-a-displacement]:

(command "_.copy" ss2 "" "_non" '(0 50) "")

As it is, the notification is being fed in as the second point, which triggers an error.  It could also be like this:

(command "_.copy" ss2 "" "_non" '(0 0) "_non" '(0 50))

Kent Cooper, AIA
0 Likes