bigd632 Posted February 13, 2015 Posted February 13, 2015 This seems like an easy program, but I wasn't able to find anything online that has helped me yet. I'd like to select a rectangle and change its width from 10 to 40 from the midpoint. The length would stay the same. I'd like this to be a 1-click thing. Is the best way to go about this to have my LISP select both edges & stretch 15mm each way? Or should I change the 4 vertices Y coordinates? Either way, how would you save the variables for the locations of the corners? Quote
BIGAL Posted February 13, 2015 Posted February 13, 2015 A method you can pick a rectang re pline and compare pick pt to cnr point then supply a +- value and modify the two corners to suit this would be a 1 pick solution. No code. Quote
marko_ribar Posted February 13, 2015 Posted February 13, 2015 Look for all attachments in following link... http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/select-rectangles-to-change-their-lenths-and-widths-at-once/td-p/5478058/page/2 HTH, M.R. Quote
bigd632 Posted February 13, 2015 Author Posted February 13, 2015 Unfortunately, I'm using AutoCAD 2002 at work and I don't think I have the option you've specified, BIGAL. So the reccedit file in that link seems as though it would do what I need, but the program crashes very often. When I select at the first prompt I get an error that there is no function definition. When I select Single, I get another prompt for the option of editing. All 3 of the options give me the same error that there is no function definition and the program ends. So I can't really fine-tune this program because I am a beginner and don't understand most of the code, and also can't see the final result to try to decipher the code myself. The program I would like to create doesn't need to have all these prompts either. I'd just like to select the rectangle and tell it "vertex 1 (Y) = vertex 1 (Y) + 15", "vertex 2 (Y) = vertex 2 (Y) + 15", etc. This task of changing the width from 10 to 40 is done at least 1,000 times per project, so this is a must figure out type of project for me. Quote
bigd632 Posted February 13, 2015 Author Posted February 13, 2015 So I've found a program that is very close to what I need. There is only one modification I need to make to have this do what I want........right now the program increases ALL the "Y" vertices by 15. How can I get the program to move vertices 1 & 2 in the negative direction 15, and vertices 3 & 4 in the positive direction 15? (defun Test (e ed / i vt) (setq i 0) (repeat (length ed) (if (= (car (nth i ed)) 10) ;if item is a vertex (progn (setq vt (cdr (nth i ed))) ; get vertex values (setq X (car vt)) ; get the x value (setq Y (cadr vt)) ; get the y value (setq Y (+ 15 Y)) ; increment the Y value by 15 units ; replace the old y value with the new y value (setq vt (subst Y (nth 1 vt) vt)) ; update the entity definition with new vertex information (setq ed (subst (cons 10 vt) (nth i ed) ed)) (entmod ed) ; update the drawing ) ;progn ) ;if (setq i (1+ i)) ) ;repeat ) ;Test (defun C:MyTest (/ e ed) (setq e (car (entsel)) ed (entget e) ) (if (= (cdr (assoc 0 ed)) "LWPOLYLINE") (test e ed) ) ;if ) ;C:MyTest Quote
BIGAL Posted February 14, 2015 Posted February 14, 2015 Therein lies the problem which vertice is No 1 depending on how the rectang is drawn ie 4 lines then pedit no guarantee that lower left is always the first. I would use this (car (nth i ed)) 10) but make it as shown below then just add or subtract each cnr and update or delete rectang and redraw. (setq pt1 (car (nth 0 ed)) 10)) (setq pt2 (car (nth 1 ed)) 10)) (setq pt3 (car (nth 2 ed)) 10)) (setq pt4 (car (nth 3 ed)) 10)) Quote
bigd632 Posted February 19, 2015 Author Posted February 19, 2015 My rectangle will be drawn the same way every time, since it will be coming in from a previously made LISP. Because of this, I figured I could tie the values to my "i" variable, but my conditional statement is outputting "Nothing" every time. Why is the program not recognizing the value of "i"? (defun Test (e ed / i vt) (setq i 0) (repeat (length ed) (if (= (car (nth i ed)) 10) ;if item is a vertex (progn (setq vt (cdr (nth i ed))) ; get vertex values (setq X (car vt)) ; get the x value (setq Y (cadr vt)) ; get the y value (cond ((or (= i 0) (= i 1));or (setq Y (+ 15 Y)) ; increse the Y value by 15 units (setq vt (subst Y (nth 1 vt) vt)); replace the old y value with the new y value (setq ed (subst (cons 10 vt) (nth i ed) ed)); update the entity definition with new vertex information );cond1 ((or (= i 2) (= i 3));or (setq Y (- 15 Y)) ; decrease the Y value by 15 units (setq vt (subst Y (nth 1 vt) vt)); replace the old y value with the new y value (setq ed (subst (cons 10 vt) (nth i ed) ed)); update the entity definition with new vertex information );cond2 (t (princ "\nNothing")) );cond (entmod ed) ; update the drawing ) ;progn ) ;if (setq i (1+ i)) ) ;repeat ) ;Test (defun C:MyTest (/ e ed) (setq e (car (entsel)) ed (entget e) ) (if (= (cdr (assoc 0 ed)) "LWPOLYLINE") (test e ed) ) ;if ) ;C:MyTest Quote
bigd632 Posted February 20, 2015 Author Posted February 20, 2015 Ok, I finally figured out how to do it. I had to add in an additional counter that only adds to the "j" if the "i" value passes the vertex test. I've posted the solution below. Now I've hit another stopping point. This LISP is "part 2" for my process, and now it seems I'm going to have to go back & modify "part 1". Any rectangle that is drawn vertically (width: 10 / height: 100) has the opposite vertex direction than any rectangle drawn horizontally (width: 100 / height: 10). I'm normally a Vectorworks user, and this just gives me one more reason to hate AutoCAD!! And I know this was fixed in AutoCAD 2011 with pedit, but I'm using a version so old that it would die of old age if it were a dog. Should I do something like this or is there a better solution? vertex2x = (vertex2 "X" position) vertex2y = (vertex2 "Y" position) vertex4x = (vertex4 "X" position) vertex4y = (vertex4 "Y" position) vertex2x = (vertex4 "X" position) vertex2y = (vertex4 "Y" position) vertex4x = (vertex2 "X" position) vertex4y = (vertex2 "Y" position) (defun Test (e ed / i j vt Y)(setq i 0) (setq j 1) (repeat (length ed) (if (= (car (nth i ed)) 10) ;if item is a vertex (progn (setq vt (cdr (nth i ed))) ; get vertex values (setq Y (cadr vt)) ; get the y value (cond ((or (= j 1) (= j 2));or (setq Y (- Y 15)) ; decrease the Y value by 15 units (setq vt (subst Y (nth 1 vt) vt)); replace the old y value with the new y value (setq ed (subst (cons 10 vt) (nth i ed) ed)); update the entity definition with new vertex information (setq j (1+ j)) );cond1 ((or (= j 3) (= j 4));or (setq Y (+ Y 15)) ; increase the Y value by 15 units (setq vt (subst Y (nth 1 vt) vt)); replace the old y value with the new y value (setq ed (subst (cons 10 vt) (nth i ed) ed)); update the entity definition with new vertex information (setq j (1+ j)) );cond2 (t (princ "")) );cond (entmod ed) ; update the drawing ) ;progn ) ;if (setq i (1+ i)) ) ;repeat ) ;Test (defun C:grp40 (/ e ed) (setq e (car (entsel)) ed (entget e) ) (if (= (cdr (assoc 0 ed)) "LWPOLYLINE") (test e ed) ) ;if ) ;C:grp40 Quote
BKT Posted February 21, 2015 Posted February 21, 2015 Did you get this to work for you? If not, maybe try what BIGAL mentioned above and recreate the rectangles. Here's one way... ;; Select the midpoints of the rectangle on the sides to be stretched. ;; (defun c:test (/ ed lay1 osm pt1 pt2) (setq pt1 (getpoint "\nSelect First Midpoint: ")) (setq pt2 (getpoint "\nSelect Second Midpoint: ")) (setq ed (entget (car (nentselp pt1)))) (setq lay1 (cdr (assoc 8 ed))) (if (= (car pt1) (car pt2)) (command "._rectangle" (list (- (car pt1) 20) (cadr pt1)) (list (+ (car pt2) 20) (cadr pt2))) (command "._rectangle" (list (car pt1) (- (cadr pt1) 20)) (list (car pt2) (+ (cadr pt2) 20))) ) (command "._chprop" (entlast) "" "LA" lay1 "") (entdel (cdr (car ed))) (princ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.