gvgbabu Posted April 15, 2011 Share Posted April 15, 2011 hi all how to write a lisp program for drawing which is attached to this thread i am thinking like this a. using getpoint for getting the lower left corner coordinates b. 2 foreach loops will come for length and depth but i could not get how to write the 2 foreach loops in the program can somebody help me to find the solution thanks Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 hi all how to write the lisp program for drawing which is attached to this thread i am thinking like this a. using getpoint for getting the lower left corner coordinates b. 2 foreach loops will come for length and depth but i could not get how to write the 2 foreach loops in the program can somebody help me to find the solution thanks sample.dwg Quote Link to comment Share on other sites More sharing options...
SOliver Posted April 15, 2011 Share Posted April 15, 2011 an embedded foreach statement is written the same way as a single foreach statement (foreach c someList (foreach d someOtherList ) ) Just make sure you use different variable names for list elements, in this case "c" and "d" Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 thanks soliver see my drawing (sample.dwg) i will set the 2 lists as below (setq length (list 1.5 2.5 2.0 3.0)) (setq depth (list 0.23 0.38 0.45 0.6)) my intension is that top horizontal linea are at same elevation but lower horizontal lines are differenet with respect to depths 1st pick the lower left corner from the getpoint and draw vertical line with depth 0.23 and draw top and bottom horizontal lines with a lenth 1.5 and then start second rectangle with depth 0.38 and lenth 2.5 again it should start from the left corner ans so on i am asking how to write this lisp can any body help me thanks Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 You don't need two FOREACH cycles to achive that (by doing this will get 25 rectangles instead of 5). Please check if this is what you are looking for: (setq OldOsmode (getvar "OSMODE")) (setq theCorner (getpoint "\nPick the corner: ")) (setq theLength (list 1.5 2.5 2.0 3.0)) (setq theDepth (list 0.23 0.38 0.45 0.6)) (setq CrIndex 0) (setvar "OSMODE" 0) (repeat (length theLength) (command "_RECTANGLE" theCorner (list (+ (car theCorner) (nth CrIndex theLength)) (- (cadr theCorner) (nth CrIndex theDepth)))) (setq CrIndex (1+ CrIndex)) ) (setvar "OSMODE" OldOsmode) Please take care that isn't recomended to use "length" or any other AutoLISP protected symbol to name your variables. Regards, Mircea Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 thanks msasu in ur program rectangles are overlapping. i am required as shown in the sample.dwg can u modify it thanks Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 Sorry, I don't have now access to AutoCAD; can you post a picture? Thank you. Regards, Mircea Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 hi i am attached a jpeg file Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 So, please find below the fixed version: (setq OldOsmode (getvar "OSMODE")) (setq theCorner (getpoint "\nPick the corner: ")) (setq theLength (list 1.5 2.5 2.0 3.0)) (setq theDepth (list 0.23 0.38 0.45 0.6)) (setq CrIndex 0) (setvar "OSMODE" 0) (repeat (length theLength) (command "_RECTANGLE" theCorner (list (+ (car theCorner) (nth CrIndex theLength)) (- (cadr theCorner) (nth CrIndex theDepth)))) (setq theCorner (polar theCorner 0.0 (nth CrIndex theLength))) (setq CrIndex (1+ CrIndex)) ) (setvar "OSMODE" OldOsmode) Regards, Mircea Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 thanks Mircea, i got the same but you are taking the pick corner as upper left corner if the selected pick corner is lower left corner what would be the program can u modify it thanks Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 Sorry, the reference point isn't marked on your sketch... so, please check the code below to see if is the right one: (setq OldOsmode (getvar "OSMODE")) (setq theCorner (getpoint "\nPick the corner: ")) (setq theLength (list 1.5 2.5 2.0 3.0)) (setq theDepth (list 0.23 0.38 0.45 0.6)) (setq theCorner (polar theCorner (* 0.5 pi) (car theDepth))) (setq CrIndex 0) (setvar "OSMODE" 0) (repeat (length theLength) (command "_RECTANGLE" theCorner (list (+ (car theCorner) (nth CrIndex theLength)) (- (cadr theCorner) (nth CrIndex theDepth)))) (setq theCorner (polar theCorner 0.0 (nth CrIndex theLength))) (setq CrIndex (1+ CrIndex)) ) (setvar "OSMODE" OldOsmode) Regards, Mircea Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 thanks Mircea, i got it but one more thing is there u are using rectangle in my case, lines are needed if we use line is there any change in the program can u modify it again thank u very much Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 Here you go: [font=monospace](setq OldOsmode (getvar "OSMODE")) (setq theCorner (getpoint "\nPick the corner: ")) (setq theLength (list 1.5 2.5 2.0 3.0)) (setq theDepth (list 0.23 0.38 0.45 0.6)) (setq theCorner (polar theCorner (* 0.5 pi) (car theDepth))) (setq CrIndex 0) (setvar "OSMODE" 0) (repeat (length theLength) (command "_RECTANGLE" theCorner (list (+ (car theCorner) (nth CrIndex theLength)) (- (cadr theCorner) (nth CrIndex theDepth))) "_EXPLODE" (entlast)) (setq theCorner (polar theCorner 0.0 (nth CrIndex theLength))) (setq CrIndex (1+ CrIndex)) ) (setvar "OSMODE" OldOsmode)[/font] Regards, Mircea Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 thanks Mircea, but in the program only first rectangle only picking the lower left corner for other rectangles again it goes to upper left corner in some cases, there must be some gapes in between rectangles (ie gaps 0.23 0.6 0.45 etc) if that is the case every time it should go to lower left corner while drawing rectangles can u modify it again with gaps in between the rectangles thank u very much Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 15, 2011 Share Posted April 15, 2011 Mircea, you have the patience of a saint Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 Sorry, but really don't understand your explanations - so, why don't you try to edit my code to suit your needs? Just post your attempt and I will provide you support. Also, please post an image to help me understand the desired result. Thank you. Regards, Mircea Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 I have commented my last "release" to give you a clue: (setq OldOsmode (getvar "OSMODE")) ;retain user's OSMODE (setq theCorner (getpoint "\nPick the corner: ")) ;ask user to input base point (setq theLength (list 1.5 2.5 2.0 3.0)) ;lists of lengths / depths (size should match) (setq theDepth (list 0.23 0.38 0.45 0.6)) (setq theCorner (polar theCorner (* 0.5 pi) (car theDepth))) ;translate the base point on vertical, positive (setq CrIndex 0) ;start counting items (setvar "OSMODE" 0) ;disable OSMODE to don't interfere with drawing process (repeat (length theLength) ;repeat procesing for all items (command "_RECTANGLE" theCorner ;start rectangle from base point ;calculate the coordinates of second point (list (+ (car theCorner) (nth CrIndex theLength)) ;displacement on horizontal from X of first point (- (cadr theCorner) (nth CrIndex theDepth))) ;displacement on vertical from Y of first point "_EXPLODE" (entlast)) ;explode to convert the PLINE to LINEs ;translate on horizontal the base point with length of current item (setq theCorner (polar theCorner 0.0 (nth CrIndex theLength))) (setq CrIndex (1+ CrIndex)) ;indexate the counter to draw next item ) (setvar "OSMODE" OldOsmode) ;restore user's OSMODE Regards, Mircea Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 Mircea, you have the patience of a saint Ooops, I saw this just after my last post... Quote Link to comment Share on other sites More sharing options...
gvgbabu Posted April 15, 2011 Author Share Posted April 15, 2011 hi Mircea yeah u have lot of patience i tried ur code which suit my requirement finally i got what i want with ur guidance thank u very much Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 15, 2011 Share Posted April 15, 2011 Sound good. You're welcome! Regards, Mircea Quote Link to comment Share on other sites More sharing options...
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.