Ciupanezul21 Posted July 21, 2024 Posted July 21, 2024 (edited) I created this little autolisp code: But the result of my code is what you see in the first image and I need the result to be like the 2nd image. (defun c:CREATE_DRAWERS_2D (/ width height depth wall_thickness side_margin drawer_spacing top_spacing bottom_spacing num_drawers drawer_width drawer_height y_pos i) ;; Setăm dimensiunile dulapului (setq width 400) (setq height 400) (setq depth 500) ;; Solicită grosimea pere?ilor (setq wall_thickness (getreal "\nEnter the thickness of the cabinet walls (e.g., 18): ")) ;; Solicită distan?a dintre marginea laterală a sertarelor ?i pere?ii laterali ai dulapului (setq side_margin (getreal "\nEnter the side margin between the drawer sides and the cabinet walls (e.g., 10): ")) ;; Solicită spa?iul între sertare (setq drawer_spacing (getreal "\nEnter the spacing between drawers (e.g., 10): ")) ;; Solicită distan?ele de sus ?i de jos (setq top_spacing (getreal "\nEnter the top spacing from the top of the cabinet (e.g., 10): ")) (setq bottom_spacing (getreal "\nEnter the bottom spacing from the bottom of the cabinet (e.g., 10): ")) ;; Solicită numărul de sertare (setq num_drawers (getint "\nEnter the number of drawers (2 or 3): ")) ;; Calculează lă?imea sertarelor (setq drawer_width (- (- width (* 2 wall_thickness)) (* 2 side_margin))) ;; Desenăm pere?ii laterali ai dulapului (command "RECTANGLE" '(0 0) (list wall_thickness height)) ; Peretele stâng (command "RECTANGLE" (list (- width wall_thickness) 0) (list width height)) ; Peretele drept ;; Calculăm înăl?imea fiecărui sertar ?i pozi?ia lor (if (= num_drawers 2) (progn ;; Calculează înăl?imea fiecărui sertar pentru 2 sertare (setq drawer_height (/ (- height top_spacing bottom_spacing (* drawer_spacing (1- num_drawers))) num_drawers)) ;; Desenăm sertarele (setq y_pos bottom_spacing) (repeat num_drawers (command "RECTANGLE" (list (+ wall_thickness side_margin) y_pos) (list (+ wall_thickness side_margin drawer_width) (+ y_pos drawer_height))) ;; Actualizează pozi?ia y pentru următorul sertar (setq y_pos (+ y_pos drawer_height drawer_spacing)) ) ) ((= num_drawers 3) ;; Calculează înăl?imea totală disponibilă pentru sertare (setq available_height (- height top_spacing bottom_spacing (- drawer_spacing (* (1- num_drawers) drawer_spacing)))) ;; Calculează înăl?imea fiecărui sertar (setq drawer_height (/ available_height num_drawers)) ;; Desenăm sertarele (setq y_pos bottom_spacing) (repeat num_drawers (command "RECTANGLE" (list (+ wall_thickness side_margin) y_pos) (list (+ wall_thickness side_margin drawer_width) (+ y_pos drawer_height))) ;; Actualizează pozi?ia y pentru următorul sertar (setq y_pos (+ y_pos drawer_height drawer_spacing)) ) ) ) ;; Afi?ează mesajul de succes (princ "\n2D drawer layout with spacing and side margins created successfully!") (princ) ) Edited July 22, 2024 by SLW210 Added Code Tags! Quote
BIGAL Posted July 22, 2024 Posted July 22, 2024 (edited) You should put your code inside the "<>" makes it easier to read. This is 1100 lines of code. But does multiple window panels. Your request would be a lot less code. You are well on your way to draw what you want, it is a case of looking at what is being output now, like the draw horizontal lines wanting to be 3mm and vertical 2mm. When I do something like this I get a sheet of paper and write on it point numbers say top drawer, would be p10 p11 p12 p13, so an internal offset would be worked out a new rectang drawn with p10a p12a no line would be drawn. I work with points rather than just getting say a rectang 2 corners. It is a task to change the code to look like what you want, in the code above is a defun that draws rectangs (rec pt len ht) it would be used a lot in your task. It may be possible to use what you have. If you pick inside the drawer and use Bpoly it will return a pline you can then get the co-ordinates of that bpoly and use that to draw a new rectang. As you want 3 drawers more or less would need to make a list of the selected points 1st. So repeat for each drawer. I have attached a lisp that will do a dcl for you including default values, for all your input, look at the examples in the top of the code. You will need to read the list of values which are returned as a string into a number. eg (setq width (atof (nth 0 ans)) (setq num_drawers (atoi (nth 8 ans))) So make a start there is plenty here that could help, or you could be lucky and some one has what you want. (if (not AH:getvalsm)(load "Multi Getvals.lsp")) (setq ans (AH:getvalsm (list "Enter values " " Width " 5 4 "400" "height " 5 4 "400" "Depth " 5 4 "400" "Wall thickness " 5 4 "18" "Side Margin" 5 4 "10" "Draw spacing" 5 4 "10" "Number of drawers" 5 4 "2"))) Multi GETVALS.lsp Edited July 22, 2024 by BIGAL Quote
SLW210 Posted July 22, 2024 Posted July 22, 2024 In the future please use Code Tags for code. (<> in the editor toolbar) 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.