Jump to content

Creating Rectangles


gpd

Recommended Posts

Hi Everybody

 

When creating a rectangle first we pick a point and then pick opposite point or give the dimensions. Is it possible to first create a rectangle of specified dimensions and then pick an insertion point such as lower left corner.

 

I do not want to use blocks for this. Anyhow if block is the only option. It must be dynamic and before inserting it we must be able to change its dimensions as per requirements. How to achieve this task.

 

Thanks

Link to comment
Share on other sites

Perhaps something like this? It should work in all UCS/Views:

 

(defun c:rect ( / norm xAng p q )
 (vl-load-com)
 ;; © Lee Mac 2010

 (mapcar
   (function
     (lambda ( sym foo str def )
       (set sym
         (cond
           (
             ((eval foo)
               (strcat str " <"
                 (vl-princ-to-string
                   (set sym
                     (cond ( (eval sym) ) ( def ))
                   )
                 )
                 "> : "
               )
             )
           )
           ( (eval sym) )
         )
       )
     )
   )
   '(*l* *w*) '(getdist getdist)
   '("\nSpecify Length" "\nSpecify Width") '(1.0 1.0)
 )

 (setq norm (trans '(0. 0. 1.) 1 0 t)
       xAng (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))

 (while (setq p (getpoint "\nSpecify Point for Rectangle <Exit> : "))
   (setq p (trans p 1 norm) q (polar p xAng *l*))
   
   (entmakex
     (list
       (cons 0 "LWPOLYLINE")
       (cons 100 "AcDbEntity")
       (cons 100 "AcDbPolyline")
       (cons 90 4)
       (cons 70 1)
       (cons 10 p)
       (cons 10 q)
       (cons 10 (polar q (+ xAng (/ pi 2.)) *w*))
       (cons 10 (polar p (+ xAng (/ pi 2.)) *w*))
       (cons 210 norm)
     )
   )
 )

 (princ)
)


 

Link to comment
Share on other sites

Thanks Lee

 

But I want the rectangle to be displayed and keep moving with the mouse unless we pick its insertion point. The way blocks do when we start insert command. What you have done, I can do that. Still thanks and see if you can help now.

Link to comment
Share on other sites

Could you be more detailed in your explanation of what you want to do?

Is this going to be part of a larger code?

If not, the rectangle command will do what you need.

Seems like you already know the base point?

Start the rectangle command

Pick the base point

Use the at symbol @

Then enter the x value the comma , then the y value

You can enter negative numbers for to have it draw in different directions

@120,120 this will draw 120 in the positive x direction and 120 in the pos. y

@-120,120 this will draw 120 in the negative x direction and 120 in the pos. y

@120,-120 this will draw 120 in the positive x direction and 120 in the neg. y

@-120,-120 this will draw 120 in the neg. x direction and 120 in the neg. y

If you need to code it:

Use a typical base point like (0.0 0.0 0.0)

Get width

Get heigth

Establish the 4 corner points using the polar function (pt1 pt2 pt3 pt4)

Make the rectangle (entmake or command functions)

Use the move command (command “move” “last” “” pt1 pause)

There are many ways to do it you just have to figure out exactly what you need

Link to comment
Share on other sites

The basic engine could look something like this:

 

 [b][color=BLACK]([/color][/b]initget 7[b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]setq x [b][color=FUCHSIA]([/color][/b]getdist [color=#2f4f4f]"\nX Axis Value:   "[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 [b][color=BLACK]([/color][/b]initget 7[b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]setq y [b][color=FUCHSIA]([/color][/b]getdist [color=#2f4f4f]"\nY Axis Value:   "[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 [b][color=BLACK]([/color][/b]setvar [color=#2f4f4f]"CMDECHO"[/color] 0[b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]setvar [color=#2f4f4f]"DRAGMODE"[/color] 2[b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]setvar [color=#2f4f4f]"DIMZIN"[/color] 8[b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]and [b][color=FUCHSIA]([/color][/b]not [b][color=NAVY]([/color][/b]tblsearch [color=#2f4f4f]"BLOCK"[/color]
             [b][color=MAROON]([/color][/b]setq bn [b][color=GREEN]([/color][/b]strcat [b][color=BLUE]([/color][/b]rtos [b][color=RED]([/color][/b]* x 1e+8[b][color=RED])[/color][/b] 2 0[b][color=BLUE])[/color][/b] [color=#2f4f4f]"X"[/color]
                              [b][color=BLUE]([/color][/b]rtos [b][color=RED]([/color][/b]* y 1e+8[b][color=RED])[/color][/b] 2 0[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]"BLOCK"[/color][b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]cons 2 bn[b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]list 10 0 0 0[b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]cons 70 0[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]"3DFACE"[/color][b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]cons 8 [color=#2f4f4f]"0"[/color][b][color=MAROON])[/color][/b]
                     [b][color=MAROON]([/color][/b]list 10 0 0 0[b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]list 11 x 0 0[b][color=MAROON])[/color][/b]
                     [b][color=MAROON]([/color][/b]list 12 x y 0[b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]list 13 0 y 0[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]"ENDBLK"[/color][b][color=MAROON])[/color][/b][b][color=MAROON]([/color][/b]cons 8 [color=#2f4f4f]"0"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]setq fe [b][color=FUCHSIA]([/color][/b]entlast[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]while [b][color=FUCHSIA]([/color][/b]eq fe [b][color=NAVY]([/color][/b]entlast[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
        [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.INSERT"[/color] bn[b][color=FUCHSIA])[/color][/b]
        [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nLower Left Point:  "[/color][b][color=FUCHSIA])[/color][/b]
        [b][color=FUCHSIA]([/color][/b]command pause[b][color=FUCHSIA])[/color][/b]
        [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]> [b][color=MAROON]([/color][/b]getvar [color=#2f4f4f]"CMDACTIVE"[/color][b][color=MAROON])[/color][/b] 0[b][color=NAVY])[/color][/b]
               [b][color=NAVY]([/color][/b]command [color=#2f4f4f]""[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 [b][color=BLACK]([/color][/b]entdel [b][color=FUCHSIA]([/color][/b]entlast[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
 [b][color=BLACK]([/color][/b]prin1 [b][color=FUCHSIA]([/color][/b]getvar [color=#2f4f4f]"LASTPOINT"[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

It would need a good bit of expansion in order to make this into a robust routine. -David

Edited by David Bethel
Link to comment
Share on other sites

Do you want the rectangle aligned as well ? then like Johnm pick say line near end of rectang to be aligned this gives angle etc then pick side to go to and L & W all done save worrying about + - values.

 

This is based on an old routine where you pick near an end to establish line angle and start point with one pick

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