Jump to content

Recommended Posts

Posted (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)
)

 

RectWidth.png

Edited by Nikon
Posted

Do you mean building a single polyline that preserves the thickness of each segment?

Posted
  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...

Posted (edited)

You should replace (ssget) with the name of the sset in which you have included the created polylines

Edited by GLAVCVS
Posted

Or, if there are no more polylines in the drawing, use (ssget "_X" '((0 . "LWP*")))

Posted
  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...

Posted
  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.

Posted
  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.

Posted

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)
)
  • Like 1
  • Agree 1
Posted
  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!

Posted
  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.

Posted (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 by Nikon
Posted

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)
)

 

  • Like 1
Posted (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 by ronjonp
  • Like 1
Posted

@Nikon It's also good practice to retrieve variables before changing them.

;; Change this
(setq vwidth 0)
;; To this
(setq vwidth (getvar 'plinewid))

 

  • Thanks 1
Posted

@GLAVCVS  @ronjonp

Thank you, your codes are working well!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...