Jump to content

Lisp for rectangle


RRS1987

Recommended Posts

I was recently looking for one which could draw a rectangle from two corner points but take the rotation from a selected polyline but I didn't find one.

 

Why not just change your UCS? :?

 

UCSRec.gif

Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

  • ReMark

    9

  • David Bethel

    7

  • pBe

    6

  • martinle

    5

Top Posters In This Topic

Posted Images

Oh yeah, sorry I got my wires crossed.

 

I thought snapline.lsp changed the ucs but it seems it doesn't as when I used it the rectangle was still drawn ortho. It seems this snapline.lsp only modifies the snapang. Ucs works great

 

Good stuff

Link to comment
Share on other sites

This is what I have come up:

(defun c:RP (/ temperr p1 p3)

(setq temperr *error*)                ;store *error*
   (setq *error* trap1)            ;re-assign *error*

(command "undo" "m")                ;undo mark

(prompt "Select object to align UCS:")
(command "_.ucs" "_OB" pause)

(setq oldecho (getvar "cmdecho"))
(setvar "cmdecho" 1)

      (command "rectangle" pause pause "")

(setvar "cmdecho" oldecho)            ;reset variable

   (command "_.ucs" "W")
   (prompt "\nReset UCS")

(setq *error* temperr)                ;restore *error*

 (princ)
)

(prompt "\nRectangle By Polyline Angle Loaded, Enter RP to run.")
(princ)



(defun trap1 (errmsg)                        ;define function
   (command "undo" "b")                    ;undo back;
   (setvar "cmdecho" oldecho)                ;restore vriable
   (setq *error* temperr)                    ;restore *error*
   (prompt "\nResetting System Variables")            ;inform user
   (princ)
)

but it doesn't reset the crosshairs on error any idea why??

 

Thanks

Link to comment
Share on other sites

but it doesn't reset the crosshairs on error any idea why??

 

For something like this, I would be inclined to retain the original command-line prompts so that the user can access the other options provided by the command, maybe something as simple as:

 

(defun c:rp nil
   (command "_.ucs" "_ob" pause "_.rectangle")
   (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause))
   (command "_.ucs" "_P")
   (princ)
)

 

Or to include the error handler to reset the UCS:

 

(defun c:rp ( / *error* )
   
   (defun *error* ( msg )
       (command "_.ucs" "_P")
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )
   
   (command "_.ucs" "_ob" pause "_.rectangle")
   (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause))
   (command "_.ucs" "_P")
   (princ)
)

Link to comment
Share on other sites

I use SNAPANG when I temporarily want to change the angle of my cross-hairs for matching some geometry that I am editing. When done I click on a macro button that resets the snapang to "0". I know of one user that has set up SNAPANG buttons for the angles 22.5 and 45 for doing piping layouts in 2D.

Link to comment
Share on other sites

Dear Mr. David,

I want to modify Lisp (Polyline rectangle lisp) as per my one requirement, Which i got from here.

I want to give offset width from the points P1 & P2, which showed in the attachment.

Please refer the attachment.

Thanks in advance.

RECT.pdf

Link to comment
Share on other sites

(defun c:rect3v (/ p1 p2 d1 c1 c2 c3 c4)
 (initget 1)
 (setq p1 (getpoint "\nCenter Of 1st Side:   "))

 (initget 1)
 (setq p2 (getpoint p1 "\nCenter Of 2nd Side:   "))
 (grdraw p1 p2 2 1)

 (initget 7)
 (setq d1 (getdist "\nOpposing Width: "))
 (setq c1 (polar p1 (+ (angle p1 p2) (* pi  0.5)) (* d1 0.5))
       c2 (polar p1 (+ (angle p1 p2) (* pi -0.5)) (* d1 0.5))
       c3 (polar p2 (+ (angle p2 p1) (* pi  0.5)) (* d1 0.5))
       c4 (polar p2 (+ (angle p2 p1) (* pi -0.5)) (* d1 0.5)))

 (entmake (list (cons 0 "POLYLINE")(cons 66 1)(cons 70 1)(list 10 0 0 0)))
 (foreach v '(c1 c2 c3 c4)
      (entmake (list (cons 0 "VERTEX")
                     (cons 10 (eval v)))))
 (entmake (list (cons 0 "SEQEND")))

 (prin1))

 

 

Hello!

 

This is a great Lisp!

I manage not to rebuild Sun is not taken but the center of the left corner!

Could someone show me?

Please help!

 

lg. Martin

Link to comment
Share on other sites

RRS, I used the offset distance as a default for the extensions:

 

[b][color=BLACK]([/color][/b]defun c:rect4v [b][color=FUCHSIA]([/color][/b]/ p1 p2 d1 d2 m1 m2 c1 c2 c3 c4[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq p1 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nCenter Of 1st Side:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq p2 [b][color=NAVY]([/color][/b]getpoint p1 [color=#2f4f4f]"\nCenter Of 2nd Side:   "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]grdraw p1 p2 2 1[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 7[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq d1 [b][color=NAVY]([/color][/b]getdist [color=#2f4f4f]"\nOpposing Width: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]initget 6[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq d2 [b][color=NAVY]([/color][/b]getdist [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nExtension Distance <"[/color] [b][color=GREEN]([/color][/b]rtos d1 2 2[b][color=GREEN])[/color][/b] [color=#2f4f4f]">:   "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]or d2 [b][color=NAVY]([/color][/b]setq d2 d1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq m1 [b][color=NAVY]([/color][/b]polar p1 [b][color=MAROON]([/color][/b]angle p2 p1[b][color=MAROON])[/color][/b] d2[b][color=NAVY])[/color][/b]
       m2 [b][color=NAVY]([/color][/b]polar p2 [b][color=MAROON]([/color][/b]angle p1 p2[b][color=MAROON])[/color][/b] d2[b][color=NAVY])[/color][/b]
       c1 [b][color=NAVY]([/color][/b]polar m1 [b][color=MAROON]([/color][/b]+ [b][color=GREEN]([/color][/b]angle p1 p2[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]* pi  0.5[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]* d1 0.5[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       c2 [b][color=NAVY]([/color][/b]polar m1 [b][color=MAROON]([/color][/b]+ [b][color=GREEN]([/color][/b]angle p1 p2[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]* pi -0.5[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]* d1 0.5[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       c3 [b][color=NAVY]([/color][/b]polar m2 [b][color=MAROON]([/color][/b]+ [b][color=GREEN]([/color][/b]angle p2 p1[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]* pi  0.5[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]* d1 0.5[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       c4 [b][color=NAVY]([/color][/b]polar m2 [b][color=MAROON]([/color][/b]+ [b][color=GREEN]([/color][/b]angle p2 p1[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]* pi -0.5[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]* d1 0.5[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]entmake [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"POLYLINE"[/color][b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]cons 66 1[b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]cons 70 1[b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]list 10 0 0 0[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]foreach v '[b][color=NAVY]([/color][/b]c1 c2 c3 c4[b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]entmake [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"VERTEX"[/color][b][color=GREEN])[/color][/b]
                     [b][color=GREEN]([/color][/b]cons 10 [b][color=BLUE]([/color][/b]eval v[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]entmake [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons 0 [color=#2f4f4f]"SEQEND"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

-David

Link to comment
Share on other sites

RRS,

You are welcome !

 

Tharwat,

grdraw lines are a bit like blipmode tick marks, Some people like 'em, some detest 'em. I like 'em in most cases as they give a visual indication as to things that have just been added or changed.

 

Martin,

I really don't quite understand your request. The original function used middle left and middle right

 

 

 

-David

Link to comment
Share on other sites

Hi David.

I mean the entry of the width is set in the middle of p1, p2.

The rectangle should be set but completely left or right of p1 p2.

I hope the Google translator is now well rested and does his job well!:lol:

 

Best regards Martin:)

Link to comment
Share on other sites

Hi David.

I mean the entry of the width is set in the middle of p1, p2.

The rectangle should be set but completely left or right of p1 p2.

I hope the Google translator is now well rested and does his job well!:lol:

 

Best regards Martin:)

 

Sorry, I just saw your request. What you've listed basically makes a square. Is that what you need? -David

Link to comment
Share on other sites

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