Jump to content

LISP for a rectangle inside a rectangle


Grigs

Recommended Posts

Hi

 

I am looking for a lisp routine that will ask for 2 points, then draw a rectangle using those 2 points, then offset that rectangle in a certain set amount the finally turn the outer rectangle's width into a thicker line. Does anyone have something like that?

 

Thanks

Link to comment
Share on other sites

Some obfuscated fun... :playing:

([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] _getdist _corners->list _offsetinside _rectangle a b c d )

   ([color=BLUE]defun[/color] _getdist ( a b c )
       ([color=BLUE]set[/color] a
           ([color=BLUE]cond[/color]
               (
                   ([color=BLUE]getdist[/color]
                       ([color=BLUE]strcat[/color] b [color=MAROON]" <"[/color]
                           ([color=BLUE]rtos[/color] ([color=BLUE]set[/color] a ([color=BLUE]cond[/color] ( ([color=BLUE]eval[/color] a) ) ( c )))) [color=MAROON]">: "[/color]
                       )
                   )
               )
               (   ([color=BLUE]eval[/color] a)   )
           )
       )
   )

   ([color=BLUE]defun[/color] _corners->list ( a b )
       ([color=BLUE]mapcar[/color]
           ([color=BLUE]function[/color]
               ([color=BLUE]lambda[/color] ( a b ) ([color=BLUE]list[/color] ([color=BLUE]car[/color] a) ([color=BLUE]cadr[/color] b)))
           )
           ([color=BLUE]list[/color] a b b a) ([color=BLUE]list[/color] a a b b)
       )
   )

   ([color=BLUE]defun[/color] _offsetinside ( a b )
       ([color=BLUE]mapcar[/color]
           ([color=BLUE]function[/color]
               ([color=BLUE]lambda[/color] ( b c )
                   ([color=BLUE]mapcar[/color]
                       ([color=BLUE]function[/color]
                           ([color=BLUE]lambda[/color] ( b c ) (([color=BLUE]eval[/color] b) c a))
                       )
                       b c
                   )                                
               )
           )
          '(([color=BLUE]+[/color] [color=BLUE]+[/color]) ([color=BLUE]-[/color] [color=BLUE]+[/color]) ([color=BLUE]-[/color] [color=BLUE]-[/color]) ([color=BLUE]+[/color] [color=BLUE]-[/color]))
           b
       )
   )

   ([color=BLUE]defun[/color] _rectangle ( a b c )
       ([color=BLUE]entmakex[/color]
           ([color=BLUE]append[/color]
               ([color=BLUE]list[/color]
                  '(0   . [color=MAROON]"LWPOLYLINE"[/color])
                  '(100 . [color=MAROON]"AcDbEntity"[/color])
                  '(100 . [color=MAROON]"AcDbPolyline"[/color])
                  '(90  . 4)
                  '(70  . 1)
                   ([color=BLUE]cons[/color] 43  a)
                   ([color=BLUE]cons[/color] 210 c)
               )
               ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( d ) ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] d 1 c))) b)
           )
       )
   )

   (_getdist '*off* [color=MAROON]"\nSpecify Offset"[/color]    5.0)
   (_getdist '*thk* [color=MAROON]"\nSpecify Thickness"[/color] 1.0)

   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] a ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify First Corner: "[/color]))
           ([color=BLUE]setq[/color] b
               (
                   ([color=BLUE]if[/color] ([color=BLUE]zerop[/color] ([color=BLUE]getvar[/color] 'WORLDUCS))
                       [color=BLUE]getpoint[/color]
                       [color=BLUE]getcorner[/color]
                   )
                   a [color=MAROON]"\nSpecify Opposite Corner: "[/color]
               )
           )
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] c ([color=BLUE]apply[/color] '_corners->list
                       ([color=BLUE]mapcar[/color]
                           ([color=BLUE]function[/color]
                               ([color=BLUE]lambda[/color] ( c )
                                   ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] c ([color=BLUE]list[/color] a b)))
                               )
                           )
                          '([color=BLUE]min[/color] [color=BLUE]max[/color])
                       )
                   )
                 d ([color=BLUE]trans[/color] '(0.0 0.0 1.0) 1 0 [color=BLUE]t[/color])
           )
           (_rectangle *thk* c d)
           (_rectangle 0.0 (_offsetinside *off* c) d)
       )
   )                   
   ([color=BLUE]princ[/color])
)

 

Should work in all UCS/Views too.

Link to comment
Share on other sites

A variation on the theme draws two rectangs on an angle.

 

; draw pits with 100mm walls
; By Alan H 2011
(setq oldsnap (getvar "osmode"))
(setq oldlayer (getvar "clayer")) 
(command "_layer" "n" "Design-Drainage-Pits" "c" 4 "Design-Drainage-Pits" "")
(setvar "clayer" "Design-Drainage-Pits")
(setq length (getreal "\nPlease enter length m eg 0.9: "))
(setq width (getreal "\nPlease enter width : "))
(setq pt1 (getpoint "\npick 1st point to place pit : "))
(setq pt2 (getpoint "\nPick 2nd point for orientation"))
(setvar "osmode" 0)
(setq pt7 (getpoint "\Pick pt on pit side : "))
(setq ang (angle pt1 pt2))
(setq ang5 (angle pt2 pt7))
(setq diffang (- ang ang5))
(if (> diffang 1.5707) 
(setq ang2 (- ang 1.570796))
(setq ang2 (+ ang 1.570796))
)
(setq ang3 (+ ang 3.1415926))
(setq ang4 (- ang 1.570796))
(setq pt3 (polar pt1 ang length))
(setq pt4 (polar pt3 ang2 width))
(setq pt5 (polar pt4 ang3 length))

(command "pline" pt1 pt3 pt4 pt5 "c")
(setq pt6 (polar pt1 ang 50.0))
(command "offset" 0.1 pt4 pt6 "")
(setvar "osmode" oldsnap)
(setvar "clayer" oldlayer)
(princ)

Link to comment
Share on other sites

hey guy . plaese set fix offset and two differrent layer

thank you.

 

The standard offset command has this functionality:

 

Command: OFFSET

Current settings: Erase source=No  Layer=Source  OFFSETGAPTYPE=0
Specify offset distance or [Through/Erase/[color=red]Layer[/color]] <Through>:

Link to comment
Share on other sites

  • 5 months later...

Lee Mac, this routine works great. I really appreciate you taking the time to help. I do have one tweek. Would it be possible to change the thickness and offset based on the dimscale being used? The offset is defaulted to 1/16" and the thickness at 1/32". But would it be possible to use those base number and use the dimscale as a multiplier?

Link to comment
Share on other sites

Hi Grigs,

 

The first-time defaults are set by the values on these lines:

 

    (_getdist '*off* "\nSpecify Offset"    [b][color=red]5.0[/color][/b])
   (_getdist '*thk* "\nSpecify Thickness" [color=red][b]1.0[/b][/color])

Perhaps change these to:

 

    (_getdist '*off* "\nSpecify Offset"    (* 5.0 (getvar 'DIMSCALE)))
   (_getdist '*thk* "\nSpecify Thickness" (getvar 'DIMSCALE))

 

Or some variation of that to suit.

Link to comment
Share on other sites

Well, I tried that but adding that doesn't seem to change the values. It still says 1/16" and 1/32". Kinda weird.

 

 

(_getdist '*off* "\nSpecify Offset" (* 0.0625 (getvar 'DIMSCALE)))

(_getdist '*thk* "\nSpecify Thickness" (* 0.03125 (getvar 'DIMSCALE)))

Link to comment
Share on other sites

It will stay the same in the same drawing, since the variables are global and so the program remembers the last entered input - you will need to start a new drawing to see the change.

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