Author Topic: Roll your own OFFSET command  (Read 2551 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Roll your own OFFSET command
« on: February 05, 2021, 08:38:26 AM »
Greetings
Roll my own OFFSET command

Vanilla AutoLISP only

I need to create a simple 2D offset routine
( I have several kludges from years ago )  ie  use the TRACE Command

Fixed values / rules :
  Center line ( White )
     Point list is always 2D
     3 adjacent path points can never be coliner

  Offset Lines
    GREEN and YELLOW
      Always equal distance from path ( same as command )


;;;INPUT FIXED OFFSET Distance from USER

;;;INPUT LIST from USER

(setq path (list
  (list  0  0)
  (list 36  0)
  (list 36 37)
  (list 59 61)
  (list 92 61)
  (list 92 21)
))

;;;RETURN LISTS
(setq yellow (list
  (list  0.248 6 0)
  (list 30 6 0)
  (list 30 39.411 0)
  (list 56.44 67 0)
  (list 98 67 0)
  (list 98 21.215 0)
))

(setq green (list
(list -0.248 -6)
(list 42 -6)
(list 42 34.589)
(list 61.56 55)
(list 86 55)
(list 86 20.785)
))

Has anyone already fought this battle ?

Regards  -David

R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Roll your own OFFSET command
« Reply #1 on: February 05, 2021, 08:41:49 AM »
Perhaps one of these:
-------------   Offset  -----------------
Advanced Offset to both side by VVA <Vladimir Azarko>
Offset selected object to both side and change (optional) layer of new object to current
http://www.theswamp.org/index.php?topic=23069.0
http://www.theswamp.org/index.php?topic=30650.0  Dynamic Offset by LeeMac
http://www.theswamp.org/index.php?topic=39645.msg449444#msg449444
http://www.theswamp.org/index.php?topic=32743.0 VLA-Offset using Point Selection
http://www.theswamp.org/index.php?topic=24688.0 Staggered Multiple Offset by RonJonp
http://www.theswamp.org/index.php?topic=6209.0 Here is a nice example of Offset by Jürg Menzi
http://www.theswamp.org/index.php?topic=23921.0 Offset direction discussion
http://www.theswamp.org/index.php?topic=21933.msg266096#msg266096 Offset Segments by Gile
http://www.theswamp.org/index.php?topic=27636.0  Array

http://www.theswamp.org/index.php?topic=32789.0  Copy along a curve AJ
http://www.theswamp.org/index.php?topic=32789.msg400746#msg400746 Copy along a curve T Willey
http://www.theswamp.org/index.php?topic=32789.msg400494#msg400494  ContinuousCopy AJ
http://www.theswamp.org/index.php?topic=34792.0  SpaceAlongCurve  LeeMac

http://www.theswamp.org/index.php?topic=50343.msg554674#msg554674
http://bit.ly/1H6qnHT    Offset Polyline Between Two Points
http://bit.ly/16HhIyM    Offset Polyline Section
http://bit.ly/1fDRDm9    Offset & Hatch
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Roll your own OFFSET command
« Reply #2 on: February 05, 2021, 09:22:16 AM »
Wow   Thanks !
R12 Dos - A2K

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Roll your own OFFSET command
« Reply #3 on: February 05, 2021, 12:50:26 PM »
Have you thought about using an MLINE for this ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Roll your own OFFSET command
« Reply #4 on: February 05, 2021, 02:30:14 PM »
Thanks, but I do not have access to MLINE commands.  I'm still using R12(dos)  for most of my work.

In the past I've used :

TRACE command
(inters) calls ( my current work in progress, updating )
PEDIT width and then converting the edges

The end result is to extruded millwork shapes ( etc) along a center of the bar die or center line paths

Lots of other fabricated metal shapes as well




R12 Dos - A2K

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Roll your own OFFSET command
« Reply #5 on: February 05, 2021, 03:10:41 PM »
That's awesome you're still rockin r12 8-)  .. I do miss the simplicity and speed of those old versions.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Roll your own OFFSET command
« Reply #6 on: February 05, 2021, 08:31:15 PM »
A couple more

Offset with taper ends.

What about this multi offset 12,-12,-5,3,4,-16 as values. Have that somewhere.

Or O12 will do a offset at 12, Oxxx is supported xxx can be any positive value, only bug is I use "-" for decimal point. but change code say "~" for decimal. It uses a catch a error method and a "." is part of command line entry.

This is Offset, Fillet and Circle use "-" for decimal eg C12-3 will draw a circle 12.3 radius at selected point.

Interested to know if it works with 2012.

Code: [Select]
; Enter the filet radius as part of a command line entry f100 offset O234 circle c123-45
; note - is used for decimal point
; original code and methology by Alan H info@alanh.com.au
; assistance and code that worked by Lee-Mac
; OCT 2015
 
(   (lambda nil
        (vl-load-com)
        (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
            (if (= "fillet-reactor" (vlr-data obj))
                (vlr-remove obj)
            )
        )
        (vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
    )
)

(defun filletrad ( / rad)
(setq rad (distof (substr com 2) 2))
            (if (<= 0.0 rad)
              (progn       
              (setvar 'filletrad rad)
              (vla-sendcommand fillet-reactor-acdoc "_.fillet ")
              )
              )
)

(defun makecirc ( / rad radd)
(setvar 'users1 (substr com 2 2))
(setq rad (distof (substr com 2) 2))
            (if (<= 0.0 rad)
            (progn
            (setvar 'circlerad rad)
            (setq pt (getpoint "Pick centre pt"))       
            (vla-sendcommand fillet-reactor-acdoc "_.Circle !pt  ")       
            )
            )
)

(defun offdist ( / dist)
(setq dist (distof (substr com 2) 2))
            (if (<= 0.0 dist)
            (progn       
            (setvar 'offsetdist dist)
            (vla-sendcommand fillet-reactor-acdoc "_.Offset  ")
            )
            )
)


(defun fillet-reactor-callback ( obj com )
(setq com (vl-string-translate "-" "." (strcase (car com))))
    (cond   
        (   (and
            (wcmatch com "~*[~F.0-9]*")
            (wcmatch com "F*")
            (wcmatch com "~F*F*")
            (wcmatch com "~*.*.*")
            ) ; and
            (filletrad)
         )

         (  (and
            (wcmatch com "~*[~C.0-9]*")
            (wcmatch com "C*")
            (wcmatch com "~C*C*")
            (wcmatch com "~*.*.*")
            ) ;and
            (makecirc)
         )
         (  (and
            (wcmatch com "~*[~O.0-9]*")
            (wcmatch com "O*")
            (wcmatch com "~O*O*")
            (wcmatch com "~*.*.*")
            ) ; and
            (offdist)
         )

    ) ; master cond
) ; defun

(or fillet-reactor-acdoc
    (setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
)

Great image a usual as you say R12, maybe time to go to Bricscad ?
« Last Edit: February 05, 2021, 08:38:33 PM by BIGAL »
A man who never made a mistake never made anything

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Roll your own OFFSET command
« Reply #7 on: February 06, 2021, 07:25:27 AM »
Thanks, but I don't have access visual lisp calls either.

Here's my latest approach.  For this project, arc segments are not needed.  If I have an arc segment , I convert it to a 3DPOLY Path
Code: [Select]

;++++++++++++ Simple OFFSET Using INTERS Points ++++++++++++++
;;;
;;;ARG PointList Total_Width
;;;RET -> (2) Lists of Offset Points

(defun offintrs (pl w / bl cl tl ll
                          cs bs ce be i vs vc ve p1 p2 hd)

 (setq hd (* w 0.5)
       ll (length pl))

;;;START AND END POINTS  Customer_Side Bar_Side
 (setq cs (polar (nth 0 pl)
                 (+ (angle (nth 0 pl) (nth 1 pl)) (* pi 0.5))
                 hd))
 (setq bs (polar (nth 0 pl)
                 (+ (angle (nth 0 pl) (nth 1 pl)) (* pi -0.5))
                 hd))

 (setq ce (polar (nth (- ll 1) pl)
                 (+ (angle (nth (- ll 1) pl) (nth (- ll 2) pl)) (* pi -0.5))
                 hd))
 (setq be (polar (nth (- ll 1) pl)
                 (+ (angle (nth (- ll 1) pl) (nth (- ll 2) pl)) (* pi 0.5))
                 hd))

;;;  CL - CUSTOMER SIDE LIST
;;;  BL - OPERATOR SIDE LIST
  (setq tl pl)
  (setq i 1)

  (while (> (length tl) 2)
       (setq vs (nth (1- i) tl))
       (setq vc (nth     i  tl))
       (setq ve (nth (1+ i) tl))
       (setq p1 (inters (polar vs (+ (angle vs vc) (* pi 0.5)) hd)
                        (polar vc (+ (angle vs vc) (* pi 0.5)) hd)
                        (polar vc (+ (angle vc ve) (* pi 0.5)) hd)
                        (polar ve (+ (angle vc ve) (* pi 0.5)) hd) nil))
       (setq cl (cons p1 cl))
       (setq p2 (inters (polar vs (+ (angle vs vc) (* pi -0.5)) hd)
                        (polar vc (+ (angle vs vc) (* pi -0.5)) hd)
                        (polar vc (+ (angle vc ve) (* pi -0.5)) hd)
                        (polar ve (+ (angle vc ve) (* pi -0.5)) hd) nil))
       (setq bl (cons p2 bl))
       (setq tl (cdr tl)))

  (setq cl (cons ce cl))
  (setq cl (cons cs (reverse cl)))

  (setq bl (cons be bl))
  (setq bl (cons bs (reverse bl)))

  (command "_.PLINE")
  (command (car bl))
  (command (car cl))
  (foreach p cl (command p))
  (command (last bl))
  (foreach p (reverse bl) (command p))
  (command bs)
  (command "")

  (list cl bl))


(defun c:foo ()
(offintrs '((9.0 -152.0) (9.0 -110.0) (17.605 -105.502) (26.4269 -101.446)
(35.443 -97.8422) (44.6302 -94.6999) (53.9648 -92.0273) (63.4229 -89.8312)
(72.9801 -88.1172) (82.6118 -86.8898) (92.2934 -86.1521) (102.0 -85.906)
(111.707 -86.1521) (121.388 -86.8898) (131.02 -88.1172) (140.577 -89.8312)
 (150.035 -92.0273) (159.37 -94.6999) (168.557 -97.8422) (177.573 -101.446)
 (186.395 -105.502) (195.0 -110.0) (195.0 -152.0))
            10)
(prin1))


The PLINE command is just for visual reference as I will build various profiles on the offset sides

It's not pretty, but works fairly well so far

Regards  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Roll your own OFFSET command
« Reply #8 on: February 06, 2021, 02:24:45 PM »
You could quite easily modify my Polyline Outline application to achieve the desired result - supplying the offset value in place of the polyline width, and outputting a point list in place of generating a polyline. I have designed the program with no reliance on Visual LISP, so it should be compatible with R12.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Roll your own OFFSET command
« Reply #9 on: February 07, 2021, 07:35:04 AM »
Thanks Lee,

I will take a look.  I did see LWPOLYLINEs and (function) calls that I would figure out a work around.

I think I see you are using the (inters) function similar to what I did.

Regards  -David
R12 Dos - A2K

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Roll your own OFFSET command
« Reply #10 on: February 12, 2021, 06:41:55 PM »
This was done re 1990. You can set offsets, use left right or other offset for pick points. Use a trim corner code for last point. It was for house walls. As you pick points 4 lines are drawn. Similar to Mline method. Sent you a PM.

A man who never made a mistake never made anything

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Roll your own OFFSET command
« Reply #11 on: February 13, 2021, 09:28:16 AM »
Thanks !

I have similar ones to draw the bodies of cafeteria carts from path points.

The advantage is that all of the corners and trims are preset distances that cannot vary.

Regards  -David
R12 Dos - A2K

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Roll your own OFFSET command
« Reply #12 on: February 13, 2021, 09:56:42 PM »
Great image as usual, pity person who built kitchen in my house I bought overlooked no overhang on bench tops. Delving deeper revealed done on the cheap.
A man who never made a mistake never made anything