I hate doing things I can make my computer do for me. My adventures in customizing and automating computers. Primarily with AutoCAD and Microsoft Office.

Thursday, August 23, 2012

EZOffset and leveraging a code snippet to create multiple routines

It's been a while.

Since I am emailing tips to my coworkers I thought I would start posting some of the background on those tips.

This is a link to EZOFFSET.LSP which has the following aliases for offsetting specific distances:


;;;  Offsets by sixteenths of an inch  -  OF (the "F" is for fraction") followed by the number of 16ths you want to offset
OF1        offset 1/16"
OF2        offset 2/16"   (1/8")
OF3        offset 3/16"
OF4        offset 4/16"   (1/4")
OF5        offset 5/16"
OF6        offset 6/16"   (3/8")
OF7        offset 7/16"
OF8        offset 8/16"   (1/2")
OF9        offset 9/16"
OF10      offset 10/16"  (5/8")
OF11      offset 11/16"
OF12      offset 12/16"  (3/4")
OF13      offset 13/16"
OF14      offset 14/16"  (7/8")
OF15      offset 15/16"

;;;  Offsets by inches - O followed by the number of inches you want to offset.  This has some variations shown below in red.
O1          offset 1"
O1F4      offset 1 4/16"  (1 1/4")
O1F8      offset 1 8/16"  (1 1/2")
O1F12   offset 1 12/16" (1 3/4")
O2          offset 2"
O3          offset 3"
O3F8      offset 3 8/16" (3 1/2")
O4          offset 4"
O5          offset 5"
O5F8      offset 5 8/16" (5 1/2")
O6          offset 6"
O7          offset 7"
O8          offset 8"
O9          offset 9"
O10        offset 10"
O11        offset 11"
O12        offset 12"
O13        offset 13"
O14        offset 14"
O15        offset 15"
O16        offset 16"
O17        offset 17"
O18        offset 18"
O19        offset 19"
O20        offset 20"
O21        offset 21"
O22        offset 22"
O23        offset 23"
O24        offset 24"
O30        offset 30"
O36        offset 36"
O42        offset 42"
O48        offset 48"
O60        offset 60"
O72        offset 72"
O84        offset 84"
O96        offset 96"
O108      offset 108"  (9')
O120      offset 120"  (10')
O132      offset 132"  (11')
O144      offset 144"  (12')
O156      offset 156"  (13')
O168      offset 168"  (14')
O180      offset 180"  (15')
O240      offset 240"  (20')
O360      offset 360"  (30')
O480      offset 480"  (40')

The meat of the code is thus:

(defun ezoffset(
                dist
                /
                offsetdist
                )
  (setq offsetdist (getvar "offsetdist"))
  (setvar "offsetdist" dist)
  (command "offset" dist)
  (while (wcmatch (getvar "cmdnames") "*offset*")
    (command pause)
    )
  (setvar "offsetdist" offsetdist)
  (princ)
  )
(princ)
)
and can be called, like this:

(defun c:OF1()(ezoffset 0.0625))  ;offset 1/16"
(defun c:OF2()(ezoffset 0.125))   ;offset 2/16"   (1/8")



The naming conventions I have used for these routines are arbitrary, but they work for me.

Let me know if you find these useful.

No comments: