TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andi.lad2909 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.
-
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.
-
sorry i'm a LISP newbie.
but this LISP can try it.
(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
-
if you want change paste place
can try this LISP
first copybase circle,and then chose new place
(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 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.
-
@ 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.
-
(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?
-
sorry that is right code
(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
-
For masao look for sample code in top of Multi Getvals.lsp
(http://)