Author Topic: copy and paste multiple  (Read 1023 times)

0 Members and 1 Guest are viewing this topic.

andi.lad2909

  • Mosquito
  • Posts: 2
copy and paste multiple
« on: July 04, 2022, 03:43:00 AM »
Hello everyone.

I am a new member of this group. Trying to find a lisp code to select the object and then paste it in left and right both direction at given specified distance and given specified times. Please refer attached CAD file for problem statement.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: copy and paste multiple
« Reply #1 on: July 05, 2022, 02:38:22 AM »
This is a excellent task for learning lisp, hope fully others will follow my lead and offer how to do it not code. I will talk about not using the array command.

Select a object use (entsel you can also get the selection point at same time Pt.
how many (getint
Distance apart (getdist or (getreal
(repeat howmany
Use (polar pt angle distance) to work out a new point
Copy object pt to newpt
set pt to newpt
end repeat

The use of a -ve distance will make the object go left if say simple circle.

Try Afralisp tutorials as a start or just Google say "getint lisp autocad" look up other commands.

Once you have 1 side working can then look at 2 sides.

A man who never made a mistake never made anything

masao

  • Newt
  • Posts: 83
Re: copy and paste multiple
« Reply #2 on: July 06, 2022, 08:46:46 AM »
sorry i'm a LISP newbie.

but this LISP can try it.

Code: [Select]
(defun c:test()

(setq po (getpoint "\nchosebase:"))

(setq ss (ssget))

(setq a (getreal "\ndistance:"))
(setq n (getint "\nlefttimes:"))
(setq n2 (getint "\nrighttimes:"))

(setq p1 (polar po pi a));left
(setq p2 (polar po 0 a));right

(command "copybase" po ss "")
(command "PASTECLIP" p1)
(command "PASTECLIP" p2)

(repeat (- n 1) ;left
 (setq p3 (polar p1 pi a));left
 (setq p1 p3)
(command "PASTECLIP" p1)
);repeat


(repeat (- n2 1) ;right
 (setq p4 (polar p2 0 a));right
 (setq p2 p4)
(command "PASTECLIP" p2)
);repeat

);test

masao

  • Newt
  • Posts: 83
Re: copy and paste multiple
« Reply #3 on: July 06, 2022, 09:02:32 AM »
if you want change paste place
 
can try this LISP

first copybase circle,and then chose new place

Code: [Select]
(defun c:test()

(setq po (getpoint "\nchosebase:"))

(setq ss (ssget))

(setq a (getreal "\ndistance:"))
(setq n (getint "\nlefttimes:"))
(setq n2 (getint "\nrighttimes:"))

(setq p1 (polar po pi a));left
(setq p2 (polar po 0 a));right

(command "copybase" po ss "")
(command "PASTECLIP" p1)
(command "PASTECLIP" p2)

(repeat (- n 1) ;left
 (setq p3 (polar p1 pi a));left
 (setq p1 p3)
(command "PASTECLIP" p1)
);repeat


(repeat (- n2 1) ;right
 (setq p4 (polar p2 0 a));right
 (setq p2 p4)
(command "PASTECLIP" p2)
);repeat

);test

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: copy and paste multiple
« Reply #4 on: July 06, 2022, 08:23:21 PM »
Masao you dont need pasteclip if you look at distance in a repeat just use something like (setq p1 (polar po pi (* a (setq mult (1+ mult))))) start with (setq mult 0) then repeat is inside copy command.
A man who never made a mistake never made anything

andi.lad2909

  • Mosquito
  • Posts: 2
Re: copy and paste multiple
« Reply #5 on: July 07, 2022, 03:46:23 AM »
@ Bigal - thanks for explaining how to code.
@ Masao - for your code. Its working and fulfills my requirement.
Thanks both of you for your prompt reply.

masao

  • Newt
  • Posts: 83
Re: copy and paste multiple
« Reply #6 on: July 07, 2022, 08:18:49 AM »
Code: [Select]
(defun c:test()

(setq ss (ssget))

(setq po (getpoint "\nchosebase:"))

(setq a (getreal "\ndistance:"))
(setq n (getint "\nlefttimes:"))
(setq n2 (getint "\nrighttimes:"))

(setq p1 (polar po pi a));left
(setq p2 (polar po 0 a));right

(command "copy" ss "" po p1)
(command "copy" ss "" po p2)

(repeat (- n 1) ;left
(setq mult 0)
(setq p3 (polar p1 pi (* a (setq mult (1+ mult)))))
(setq p1 p3)
(command "copy" ss "" po p1)
);repeat

(repeat (- n2 1) ;right
(setq mult2 0)
(setq p4 (polar p2 0 (* a (setq mult2 (1+ mult2)))))
(setq p2 p4)
(command "copy" ss "" po p2)
);repeat

);test

new code study

but why mult can plus 1? in repeat funtion can make it?

masao

  • Newt
  • Posts: 83
Re: copy and paste multiple
« Reply #7 on: July 07, 2022, 08:55:48 AM »
sorry that is right code

Code: [Select]
(defun c:test()

(setq ss (ssget))

(setq po (getpoint "\nchosebase:"))

(setq a (getreal "\ndistance:"))
(setq n (getint "\nlefttimes:"))
(setq n2 (getint "\nrighttimes:"))

(setq p1 (polar po pi a));left
(setq p2 (polar po 0 a));right

(command "copy" ss "" po p1)
(command "copy" ss "" po p2)

(repeat (- n 1) ;left

(setq mult 0)

(setq p1 (polar p1 pi (* a (setq mult (1+ mult)))))

(command "copy" ss "" po p1)
);repeat

(repeat (- n2 1) ;right

(setq mult2 0)

(setq p2 (polar p2 0 (* a (setq mult2 (1+ mult2)))))

(command "copy" ss "" po p2)
);repeat

);test

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: copy and paste multiple
« Reply #8 on: July 07, 2022, 09:35:31 PM »
For masao look for sample code in top of Multi Getvals.lsp

A man who never made a mistake never made anything