Rectangle that starts at Center of One End

Rectangle that starts at Center of One End

Anonymous
Not applicable
542 Views
4 Replies
Message 1 of 5

Rectangle that starts at Center of One End

Anonymous
Not applicable

Does anyone have a lisp that draws a rectangle starting at the midpoint of one end?

 

Psuedo Code:

Specify starting point
Specify End point
Enter diameter

 

I realise that Mline would acomplish this however we cannot use multilines in these drawings because some of the rectangle will need a chamfer at one corner.

 

 

 

 

0 Likes
Accepted solutions (1)
543 Views
4 Replies
Replies (4)
Message 2 of 5

hmsilva
Mentor
Mentor

Hello sbanister,

not quite what you are looking for, but probably a strting point for your code...

 

These two excellent codes, one from Gian Paolo Cattaneo and the other from Lee Mac have a dynamic approach to a 3 points rectangle.

 

Hats off to @Lee_Mac and @gpcattaneo

 

Henrique

EESignature

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

Does anyone have a lisp that draws a rectangle starting at the midpoint of one end?

 

Psuedo Code:

Specify starting point
Specify End point
Enter diameter

.... 


In simplest terms, and untested, try this:

 

(defun C:RME (/ pt1 pt2 ang wid hwid); = Rectangle by Midpoints of Ends

  (setq

    pt1 (getpoint "\nSpecify midpoint of starting end: ")

    pt2 (getpoint pt1 "\nSpecify midpoint of other end: ")

    ang (angle pt1 pt2

    wid (getdist "\nRectangle width [e.g. pipe diameter]: ")

    hwid (/  wid 2)

  ); setq

  (command "_.pline"

    "_none" (polar pt1 (- ang (/ pi 2)) hwid)

    "_none" (polar pt2 (- ang (/ pi 2)) hwid)

    "_none" (polar pt2 (+ ang (/ pi 2)) hwid)

    "_none" (polar pt1 (+ ang (/ pi 2)) hwid)

    "_close"

  ); command

); defun

 

It could be made more sophisticated, e.g. to suppress command echoing, remember the width/diameter and offer it as default next time, work in other-than-World coordinate systems, ensure Polyline width of zero, etc.

Kent Cooper, AIA
Message 4 of 5

stevor
Collaborator
Collaborator

Try:

 ; 2 pt rectangLe by midpts, width, 2D: in UCS only  auscadd.com
 (DEFUN Rec_2MP (P Q W / D P1 P2 P3 P4 A B REN PEN ) ; (PP_"p") (P_"q")
  (setq @u"Rec_2MP"  i 0  B (/ pi 2 )  A (angLe P Q )  D (/ W 2)
        P1  (poLar P (- A B ) D )  P2 (poLar P (+ A B ) D )
        P3  (poLar Q (+ A B ) D )  P4 (poLar Q (- A B ) D )
        REN (entlast) ) ; (gr_xdc P 1 1) (gr_xdc Q 1 2)
  (COMMAND "PLINE" "_non" P1 "_non" P2 "_non" P3 "_non" P4 "C")  
  ; nyet (command "_.rectangle" "_non" P1 "_non" P3)  
 ) ; def

S
0 Likes
Message 5 of 5

Anonymous
Not applicable

Hello again Kent

 

Apart from the missing closing parenthisis after ang (angle pt1 pt2 it was bang on, well done.

 

I have tried numerous coding options & was begining to think it wasn't possible

 

Thank you very much indeed, it's just as needed.

 

PS my usual mistake is to put too many opening parethesis in 😕

0 Likes