View Full Version : Moving in a lisp routine
18th Jun 2003, 02:59 am
I'm new to writing lisp routines, and I'm trying to write a routine in which I insert a block, and move it 12,12,0. At the moment, I just have the basic commands. It calls up the block and lets you pick your insertion point. Then it sizes and rotates the block correctly. Now, I want to move it up and to the right 12 inches. Currently, I'm just using the basic move command, and it still asks what you want to move. It works exactly how I want it, except for having to pick the block to move.
My question is how can I have the routine remember the block it inserted so that I don't have to select it for the move?
18th Jun 2003, 05:44 am
Welcome in the Forum!
The problem can be solved and you are wery close to the solution! Let's imagine that we are in AutoCAD. After inserted and rotated a block we want to move it:
select objects: P
1 selected. Select objects: [enter]
base point or... 12,12,0 [enter] [enter]
This is exactly what do you need in AutoLISP:
(command: "move" "p" ''" (list 12 12 0) "")
I hoope this will help you! For more info you will find us here...
18th Jun 2003, 01:13 pm
I tried a previous selection, but it said there's no previous selection set.
If it helps, this is the code I have: (like I said, I'm a beginner :D )
(defun c:sa ()
(COMMAND \N "-INSERT" "sa" pause "24" "24" "0")
(COMMAND \N "MOVE" pause "" "0,0,0" "12,12,0")
18th Jun 2003, 01:38 pm
If the block was just rotated so the "previous" selection set is not empty. But if the rotation of the block was a phase of the insert command so the block was not selected. If do you want to select the block first time after inserting, just replace the p with l.
(command: "move" "l" ''" (list 12 12 0) "")
This line will select the last element in the drawing.
A more elegant solution: after insert the block extract the coordinates of the insert point (dxf code 10) and add the desired deplasament.
(defun c:mb( / el) ;move block
(setq el (entget (entlast))
el (subst (cons 10
(list (+ 12 (cadr (assoc 10 el)))
(+ 12 (caddr (assoc 10 el)))
(cadddr (assoc 10 el))))
(assoc 10 el) el))
18th Jun 2003, 01:58 pm
Once I realized that was a lower-case L, and not an upper-case i, (it's early) it worked great!
Thanks a lot!
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.