How to make this LISP rectangle positive?

How to make this LISP rectangle positive?

a22663564
Contributor Contributor
737 Views
8 Replies
Message 1 of 9

How to make this LISP rectangle positive?

a22663564
Contributor
Contributor

Hey everyone, I'm in trouble again

This LISP is a square made of two triangles

Can achieve the effect of drawing two points into a rectangle

But the rectangle is not in the positive direction

Can this LISP be changed to a rectangle in the positive direction?

Above the photo is the LISP effect

I want the effect of red below

 

 

123.jpg

 

 

 

(defun :GR (a) (* pi (/ a 180.0)))
(defun C:SQR ( / ANG12 ANG1X ANG2X P1 P2 PXL PXR)
   (setq p1 (getpoint "\nfirst point :"))
   (setq p2 (getpoint p1 "\nsecond point :"))
   (setq   ang12   (angle p1 p2)
         ang2x   (+ ang12 (:GR 45.0))
         ang1x   (+ ang12 (:GR 135.0))
   )
   (setq pxl (inters p2 (polar p2 ang2x 1.0) p1 (polar p1 ang1x 1.0) nil))

   (setq pxr (inters p1 (polar p1 (+ ang2x pi) 1.0) p2 (polar p2 (+ ang1x pi) 1.0) nil))

   (vl-cmdf "line" p1 p2 "")
   (vl-cmdf "pline" p1 pxr p2 pxl p1 "")
)

 

 

 

 

0 Likes
Accepted solutions (3)
738 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor
Accepted solution

After you've drawn the rotated white square, then do the following:

(setq en(entlast)) ; select last object

(setq ob(vlax-ename->vla-object en)) ; convert to vla object

(vla-getboundingbox ob 'mn 'mx) ; get coordinates of object's bounding box

(setq llpt (vlax-safearray->list mn)) ; convert to lower left coordinate point

(setq urpt (vlax-safearray->list mx)) ; convert to upper right coordinate point

(command"_.Rectang" llpt urpt) ; draw the square


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 9

a22663564
Contributor
Contributor
It is successful, but the original rectangle is not needed, can it be deleted?
0 Likes
Message 4 of 9

paullimapa
Mentor
Mentor
Accepted solution

sure remember the first line of code where I saved the original square as en:

(setq en(entlast)) ; select last object

All you have to do is now add this line of code at the end:

(entdel en)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 9

a22663564
Contributor
Contributor
This LISP works very well, thank you very much for your help
0 Likes
Message 6 of 9

paullimapa
Mentor
Mentor
Glad that worked out for you...cheers!!!

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

I would not do it by drawing the diagonal box, then finding its bounding box, then drawing the box you want [EDIT: if it is really the box you want -- see my next Message], then deleting the diagonal one.  I would do it directly:

 

(defun C:SQR (/ ANG12 ANG1X ANG2X P1 P2)
  (setq p1 (getpoint "\nfirst point :"))
  (setq p2 (getpoint p1 "\nsecond point :"))
  (setq
    ang12   (angle p1 p2)
    ang2x   (+ ang12 (/ pi 2))
    ang1x   (- ang12 (/ pi 2))
    rad (/ (distance p1 p2) 2)
  )
  (vl-cmdf "line" p1 p2 ""); if still desired
  (vl-cmdf "pline"
    (polar p1 ang1x rad) (polar p2 ang1x rad)
    (polar p2 ang2x rad) (polar p1 ang2x rad)
    "_close"
  )
)

 

That's in simplest terms as yours is, but I would suggest adding control over Object Snap, at least, and other typical enhancements.

It looks from the end of your video as though maybe you don't want the Line across the middle, but I wasn't sure.

Kent Cooper, AIA
0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant

@a22663564 wrote:
It is successful....

... if the two points are in an orthogonal relationship to one another, but not if they are at some other angle:

Kent1Cooper_0-1662130486433.png

My routine in Message 7 works at any angle [as does your original that draws the diagonal box]:

Kent1Cooper_1-1662130554721.png

 

Kent Cooper, AIA
0 Likes
Message 9 of 9

a22663564
Contributor
Contributor
Yes, paulli's LISP will not work in other angles will not make positive angles
But the LISP you all changed all gave me very good results, thank you very much
Need to cross the middle line he is necessary
Because of the effect of the product
That is, the rectangle of the blank part of the dotted line needs to be broken
But CNC programming to process many small straight lines is too troublesome to process
So choose to draw a long straight line first and then let the rectangular part break it
So a straight line that will pass in the middle is needed
But if the result last can be overkill and pe , it will be more perfect
Because of the multiple small line segments, I will finally do OVERKILL and PE to make it a straight line
In this way, CNC programming is more convenient
0 Likes