Nikon Posted Thursday at 06:55 PM Posted Thursday at 06:55 PM (edited) The rectangle is drawn using separate polylines. How can they be combined? Using "_C" does not work... ; A 1000x500 rectangle with horizontal sides with a global width of 40, vertical sides with a global width of 0. (defun c:RectWidth-hor40 (/ pt1 pt2 hWidth vWidth p1 p2 p3 p4) (setq width 1000 ; Rectangle width height 500 ; Rectangle height hWidth 40 ; Global width of horizontal sides vWidth 0) ; Global width of vertical sides (setq pt1 (getpoint "\nSpecify the insertion point: ")) (setq p1 pt1 p2 (list (+ (car pt1) width) (cadr pt1)) p3 (list (+ (car pt1) width) (+ (cadr pt1) height)) p4 (list (car pt1) (+ (cadr pt1) height))) (setvar 'PLINEWID hWidth) (command "_.PLINE" p1 p2 "") (command "_.PLINE" p3 p4 "") (setvar 'PLINEWID vWidth) (command "_.PLINE" (list (car p1) (cadr p1)) (list (car p1) (+ (cadr p1) height)) "") (command "_.PLINE" (list (car p2) (cadr p2)) (list (car p2) (+ (cadr p2) height)) "") (princ) ) Edited Thursday at 06:56 PM by Nikon Quote
Nikon Posted Thursday at 07:36 PM Author Posted Thursday at 07:36 PM (edited) On 3/27/2025 at 7:16 PM, GLAVCVS said: Define 'be combined', please Expand 4 separate polylines = a closed rectangle. closed rectangle.dwgFetching info... Edited Thursday at 09:49 PM by Nikon Quote
GLAVCVS Posted Thursday at 09:04 PM Posted Thursday at 09:04 PM Do you mean building a single polyline that preserves the thickness of each segment? Quote
Nikon Posted Thursday at 09:05 PM Author Posted Thursday at 09:05 PM On 3/27/2025 at 9:04 PM, GLAVCVS said: Do you mean building a single polyline that preserves the thickness of each segment? Expand Yes... Quote
GLAVCVS Posted Thursday at 09:07 PM Posted Thursday at 09:07 PM (command "_pedit" "_m" (ssget) "" "_j" 0 "") 1 Quote
GLAVCVS Posted Thursday at 09:10 PM Posted Thursday at 09:10 PM (edited) You should replace (ssget) with the name of the sset in which you have included the created polylines Edited Thursday at 09:11 PM by GLAVCVS Quote
GLAVCVS Posted Thursday at 09:13 PM Posted Thursday at 09:13 PM Or, if there are no more polylines in the drawing, use (ssget "_X" '((0 . "LWP*"))) Quote
Nikon Posted Thursday at 09:14 PM Author Posted Thursday at 09:14 PM On 3/27/2025 at 9:07 PM, GLAVCVS said: (command "_pedit" "_m" (ssget) "" "_j" 0 "") Expand @GLAVCVS thanks, it works, but the created polylines need to be selected... Quote
Nikon Posted Thursday at 09:17 PM Author Posted Thursday at 09:17 PM On 3/27/2025 at 9:10 PM, GLAVCVS said: You should replace (ssget) with the name of the sset in which you have included the created polylines Expand It's not clear to me. Quote
Nikon Posted Thursday at 09:18 PM Author Posted Thursday at 09:18 PM On 3/27/2025 at 9:13 PM, GLAVCVS said: Or, if there are no more polylines in the drawing, use (ssget "_X" '((0 . "LWP*"))) Expand There are other polylines in the drawing. Quote
ronjonp Posted Thursday at 09:28 PM Posted Thursday at 09:28 PM @Nikon Use the JOIN command. Code is not needed. 1 Quote
Stefan BMR Posted Thursday at 09:34 PM Posted Thursday at 09:34 PM Use entmakex. ; A 1000x500 rectangle with horizontal sides with a global width of 40, vertical sides with a global width of 0. (defun c:RectWidth-hor40 (/ pt1 pt2 hWidth vWidth p1 p2 p3 p4 pl) (setq width 1000 ; Rectangle width height 500 ; Rectangle height hWidth 40 ; Global width of horizontal sides vWidth 0) ; Global width of vertical sides (setq pt1 (getpoint "\nSpecify the insertion point: ")) (setq p1 pt1 p2 (list (+ (car pt1) width) (cadr pt1)) p3 (list (+ (car pt1) width) (+ (cadr pt1) height)) p4 (list (car pt1) (+ (cadr pt1) height))) (setq pl (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1) (cons 10 p1) (cons 40 hWidth) (cons 41 hWidth) (cons 10 p2) (cons 40 vWidth) (cons 41 vWidth) (cons 10 p3) (cons 40 hWidth) (cons 41 hWidth) (cons 10 p4) (cons 40 vWidth) (cons 41 vWidth) ) ) ) (princ) ) 1 1 Quote
Nikon Posted Thursday at 09:45 PM Author Posted Thursday at 09:45 PM On 3/27/2025 at 9:34 PM, Stefan BMR said: Use entmakex. Expand @Stefan BMR thank you very much, a closed rectangle is immediately created, this is what I need! Quote
GLAVCVS Posted Thursday at 09:46 PM Posted Thursday at 09:46 PM On 3/27/2025 at 9:28 PM, ronjonp said: @Nikon Use the JOIN command. Code is not needed. Expand I think your explanation is too short. I assume you mean there are better ways to do it than with 'command'. But I'm not sure Nikon would understand if you didn't explain it a little more. Quote
Nikon Posted Thursday at 09:54 PM Author Posted Thursday at 09:54 PM (edited) On 3/27/2025 at 9:46 PM, GLAVCVS said: I assume you mean there are better ways to do it than with 'command'. But I'm not sure Nikon would understand if you didn't explain it a little more. Expand I think you just need to type JOIN into the command prompt and select the objects to combine, without any code... But I just wanted to complete the code. Edited Thursday at 09:55 PM by Nikon Quote
GLAVCVS Posted Thursday at 10:04 PM Posted Thursday at 10:04 PM This is the easiest way to do it, taking advantage of your code (defun c:RectWidth-hor40 (/ pt1 pt2 hWidth vWidth p1 p2 p3 p4 cj) (setq width 1000 ; Rectangle width height 500 ; Rectangle height hWidth 40 ; Global width of horizontal sides vWidth 0) ; Global width of vertical sides (setq pt1 (getpoint "\nSpecify the insertion point: ")) (setq p1 pt1 p2 (list (+ (car pt1) width) (cadr pt1)) p3 (list (+ (car pt1) width) (+ (cadr pt1) height)) p4 (list (car pt1) (+ (cadr pt1) height))) (setvar 'PLINEWID hWidth) (setq cj (ssadd)) (command "_.PLINE" p1 p2 "") (ssadd (entlast) cj) (command "_.PLINE" p3 p4 "") (ssadd (entlast) cj) (setvar 'PLINEWID vWidth) (command "_.PLINE" (list (car p1) (cadr p1)) (list (car p1) (+ (cadr p1) height)) "") (ssadd (entlast) cj) (command "_.PLINE" (list (car p2) (cadr p2)) (list (car p2) (+ (cadr p2) height)) "") (ssadd (entlast) cj) (command "_pedit" "_m" cj "" "_j" 0 "") (princ) ) 1 Quote
ronjonp Posted Thursday at 10:05 PM Posted Thursday at 10:05 PM (edited) On 3/27/2025 at 9:54 PM, Nikon said: I think you just need to type JOIN into the command prompt and select the objects to combine, without any code... Expand Exactly. Why don't you use a block for this? (defun c:foo (/ p) (cond ((null (tblobjname "block" "FOO")) (entmake '((0 . "BLOCK") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbBlockReference") (2 . "FOO") (10 0. 0. 0.) (70 . 0) ) ) (entmake '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (67 . 0) (8 . "L-MVIEW") (100 . "AcDbPolyline") (90 . 4) (70 . 129) (38 . 0.) (39 . 0.) (10 1000. 0.) (40 . 0.) (41 . 0.) (42 . 0.) (91 . 0) (10 1000. 500.) (40 . 40.) (41 . 40.) (42 . 0.) (91 . 0) (10 0. 500.) (40 . 0.) (41 . 0.) (42 . 0.) (91 . 0) (10 0. 0.) (40 . 40.) (41 . 40.) (42 . 0.) (91 . 0) ) ) (entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0"))) ) ) (while (setq p (getpoint "\\nPick a point: ")) (entmakex (list '(0 . "INSERT") '(2 . "FOO") (cons 10 p))) ) (princ) ) Edited Thursday at 10:07 PM by ronjonp 1 Quote
ronjonp Posted Thursday at 10:13 PM Posted Thursday at 10:13 PM @Nikon It's also good practice to retrieve variables before changing them. ;; Change this (setq vwidth 0) ;; To this (setq vwidth (getvar 'plinewid)) 1 Quote
Nikon Posted Thursday at 10:36 PM Author Posted Thursday at 10:36 PM @GLAVCVS @ronjonp Thank you, your codes are working well! 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.