Thread Content
How to achieve this in CAD Lisp programming: 1. I click on any point on the screen, and the program analyzes the x1 and y1 coordinates of that point; after adding a fixed value to each of these values, it assigns them to a variable named pt2. It works roughly as follows: (setq pt1(getpoint “Please select a point on the screen”)) ; ; ; ; Suppose the coordinate values of the point I select on the screen are x1 and y1 (setq pt2(x2,y2)) ; ; ; ; I want to achieve the coordinate values of pt2 as x2 = x1 + a and y2 = y1 + b, where a and b are constants. 2. How to insert a block repeatedly? Suppose the block I defined is named block1: (defun c:isb1() (setq pt1(getpoint "\Please select a point on the screen")) (command\"insert\" \"block1\" pt1 1 1 0)); So, what should be done next? ) The ultimate goal of this program is to enable me to enter ‘isb1’ in the CAD command line, so that CAD will repeatedly insert the block block1 at the point I select. How is this ‘repeated insertion’ achieved?
My first question is actually about how to change the insertion point. For example, I pick a point at one of the endpoints of a line on the CAD screen based on the graphic, but I want to move the insertion point to a distance away from the endpoint I picked.
For the first question, you can use this statement to jump to a new point based on pt1: (setq pt2 (list (+ (car pt1) 5) (+ (cadr pt1) 7))). For the second question, it is likely necessary to use a repeat loop to call the relevant function repeatedly
(defun c:isb1() (setq xy '() a real b real x real y real pt list z 0 ) (while t (setq a (getreal "\nPlease enter the value to add in the X direction:") b (getreal "\nPlease enter the value to add in the Y direction:") ) (setq xy (getpoint "\nSelect a point:") x (car xy) y (cadr xy) ) (setq x (+ x a) y (+ y b) ) (setq pt (list x y z)) (command "insert" "block1" pt "" "" "") ) (princ) ) Sir, the code above should be what you’re looking for. I tried it and it worked fine; however, each time the block is inserted again, it keeps asking for the value to add in the X direction, the value to add in the Y direction, and asks to select a point. If you don’t want to continue inserting the block, just press Esc. I haven’t written Autolisp code in a long time; I’ve almost forgotten everything. If there’s anything you’re not sure about, ask in the comments or send me a message. This post was last edited by gucci218 on 2007-8-4 17:03]
Since what is inserted repeatedly is a block, simply use a loop to enter the insertion point and let the program handle the copying.
1 -----(setq pt2 (list (+(car pt1) a)(+(cadr pt1) b))) 2-----(while (setq p (getpoint)) (command"insert" "blk1" p 1 1 0 "") ) Implemented using a loop