Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to make this LISP rectangle positive?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
a22663564
493 Views, 8 Replies

How to make this LISP rectangle positive?

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

 

 

 

 

8 REPLIES 8
Message 2 of 9
paullimapa
in reply to: a22663564

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
Message 3 of 9
a22663564
in reply to: paullimapa

It is successful, but the original rectangle is not needed, can it be deleted?
Message 4 of 9
paullimapa
in reply to: a22663564

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
in reply to: paullimapa

This LISP works very well, thank you very much for your help
Message 6 of 9
paullimapa
in reply to: a22663564

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

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 9
Kent1Cooper
in reply to: a22663564

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
Message 8 of 9
Kent1Cooper
in reply to: a22663564


@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
Message 9 of 9
a22663564
in reply to: Kent1Cooper

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report