LSP to Offset to just one side and then join (of modify a LSP that offset to both sides)

LSP to Offset to just one side and then join (of modify a LSP that offset to both sides)

aitorm
Advocate Advocate
534 Views
4 Replies
Message 1 of 5

LSP to Offset to just one side and then join (of modify a LSP that offset to both sides)

aitorm
Advocate
Advocate

Hi!

 

I found this interesting lsp that offsets a polyline / line and then it join its ends. But I only need to offset to one side. Could you help me transform it?

 

Thanks!

 

 

 

;;  OffsetBothSidesJoin.lsp [command name: OBSJ]
;;  To Offset the same object to Both Sides at the same distance, and
;;    if open-ended, Join the resulting objects with PEDIT.
;;  On first use, offers regular Offset command's default distance,
;;    but only if numerical [not "Through"].
;;  Remembers specified offset distance, separately from regular
;;    Offset command's default, and offers as default on later use.
;;  Kent Cooper, 21 March 2014
;
(defun C:OBSJ (/ osd disttemp obj); = Offset to Both Sides
;
  (setq osd (getvar 'offsetdist))
  (setvar 'peditaccept 1)
;
  (if *obsjdist (initget 6) (initget 7))
    ; no 0, no negative, no Enter on first use
  (setq
    disttemp
      (getdist
        (strcat
          "\nBoth-sides-offset distance"
          (strcat
            (if (or *obsjdist (> osd 0))
              (strcat ; then - construct default
                " <"
                (if *obsjdist
                  (rtos *obsjdist)
                  (rtos osd)
                ); end if
                ">"
              ); end strcat
              "" ; else - no default offered on first use if Offset's is Through
            ); end if
          ); end strcat
          ": "
        ); end strcat
      ); end getdist
    *obsjdist
      (cond
        (disttemp); User specified something other than Enter - use it
        (*obsjdist); Enter with prior value set - use that
        ((> osd 0) osd)
          ; Enter on first use with non-Through Offset default - use that
      ); end cond & *obsjdist
  ); end setq
;
  (while T
    (if
      (setq obj
        (vlax-ename->vla-object
          (car (entsel "\nSelect object to Offset to Both Sides [Esc to exit]: "))
        ); end vlax-...
      ); end setq
      (progn
        (vla-offset obj *obsjdist)
        (setq ent1 (entlast))
        (vla-offset obj (- *obsjdist))
        (if (not (vlax-curve-isClosed obj)); e.g. Line, Arc, open Polyline
          (command "_.pedit" "_m" ent1 (entlast) "" "_j" "_j" "_b" (* *obsjdist 2.5) "")
        ); if
      ); end progn
    ); end if
  ); end while
;
  (princ)
); end defun
(prompt "Type OBSJ to Offset to Both Sides by the same distance and Join if possible.")

 

 

0 Likes
Accepted solutions (2)
535 Views
4 Replies
Replies (4)
Message 2 of 5

paullimapa
Mentor
Mentor

looks like one of @Kent1Cooper 's creation...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 5

LDShaw
Collaborator
Collaborator

Here is a thread on something similar.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/drawing-a-line-between-the-two-endpo...

Lots of different ideas.

I had a bit of time so I took this out of that thread. I think it will work for you.

 

(defun c:foo (/ ss offsetDist pt plineEntity)
  ;; Step 1: Get the polyline to offset
  (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE,POLYLINE")))) ; Select polyline
  (if ss
    (progn
      ;; Ask for offset distance
      (setq offsetDist (getreal "\nEnter the offset distance: "))
      
      ;; Ask the user to pick a point to determine the offset side
      (setq pt (getpoint "\nSpecify a point on the side to offset: "))
      
      ;; Offset the polyline
      (command "_.OFFSET" offsetDist ss pt "")
      
      ;; Pause to allow user to select items
      (prompt "\nSelect the polylines to join and press Enter: ")
      (setq plineEntity (ssget))
      
      ;; Perform PEDIT on the selected polylines
      (if plineEntity
        (command "_.PEDIT" "_M" plineEntity "" "_J" "_J" "_A" offsetDist "")
        (prompt "\nNo polylines selected for PEDIT.")
      )
    )
    (prompt "\nNo polyline selected.")
  )
  (princ)
)

 

all I did was remove to close. 

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

As a start, try OffsetCloseHatch.lsp, >here<.  Comment out the line that does the Hatching if you don't want that part; if it works for you otherwise, the Hatching itself and some related elements no longer needed can easily be removed entirely, and the file and command appropriately renamed, etc.

Kent Cooper, AIA
Message 5 of 5

aitorm
Advocate
Advocate
Accepted solution

That was hlepful!

 

Here the modified LSP that fits my requirements:

 

;|  OffsetClose.lsp [command name: OC]
To Offset selected object(s), if open-ended close ends & join into single closed
  object [Polyline or Spline].
Asks for side to Offset to for each object individually [current object will be highlighted].
On first use, offers regular Offset command's default distance, but only if
  numerical [not "Through"]. Remembers specified offset distance, separately
  from regular Offset command's default, and offers as default on later use.
Works on any planar object(s) with linearity [of (vlax-curve) classes], other than
  3D Polylines [can't be Offset even if planar] or Xlines or Rays [can't close ends],
  in any Coordinate System.
|;

(defun C:22 (/ *error* doc svn svv osd ss n ent clo ucschanged toJoin); = Offset, Close
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    )
    (if ucschanged (command-s "_.ucs" "_previous"))
    (mapcar 'setvar svn svv); reset System Variables
    (vla-endundomark doc)
    (princ)
  )
  (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (setq
    svn '(osmode cmdecho blipmode peditaccept offsetdist)
    svv (mapcar 'getvar svn)
    osd (last svv)
  )
  (initget (if (or *ochdist (> osd 0)) 6 7))
  (setq *ochdist 
    (cond
      ((getdist
         (strcat
           "\nOffset distance"
           (if (or *ochdist (> osd 0))
             (strcat " <" (if *ochdist (rtos *ochdist) (rtos osd)) ">")
             ""
           )
           ": "
         )
       )
      )
      (*ochdist)
      ((> osd 0) osd)
    )
  )
  (prompt "\nTo Offset, Close ends if open.")
  (if
    (setq ss
      (ssget "_:L"
        '(
          (-4 . "<OR")
            (0 . "LINE,ARC,CIRCLE,LWPOLYLINE,ELLIPSE")
            (-4 . "<AND")
              (0 . "POLYLINE")
              (-4 . "<NOT") (-4 . "&") (70 . 24) (-4 . "NOT>")
            (-4 . "AND>")
            (-4 . "<AND") (0 . "SPLINE") (-4 . "&") (70 . 8) (-4 . "AND>")
          (-4 . "OR>")
        )
      )
    )
    (progn
      (mapcar 'setvar svn '(0 0 0 1))
      (repeat (setq n (sslength ss))
        (setq
          ent (ssname ss (setq n (1- n)))
          clo (vlax-curve-isClosed ent)
        )
        (command "_.ucs" "_new" "_object" ent)
        (setq
          ucschanged T
          toJoin (ssadd ent)
        )
        (command "_.offset" *ochdist (list ent (vlax-curve-getStartPoint ent)) pause "")
        (ssadd (entlast) toJoin)
        (if (not clo)
          (progn
            (command "_.line"
              "_none" (trans (vlax-curve-getStartPoint ent) 0 1)
              "_none" (trans (vlax-curve-getStartPoint (entlast)) 0 1)
              ""
            )
            (ssadd (entlast) toJoin)
            (command "_.line"
              "_none" (trans (vlax-curve-getEndPoint ent) 0 1)
              "_none" (trans (vlax-curve-getEndPoint (ssname toJoin 1)) 0 1)
              ""
            )
            (ssadd (entlast) toJoin)
            (initcommandversion)
            (command "_.join" toJoin "")
            (setq toJoin (if (entget ent) ent (entlast)))
          )
        )
        (command "_.ucs" "_prev")
        (setq ucschanged nil)
      )
    )
  )
  (mapcar 'setvar svn svv)
  (vla-endundomark doc)
  (princ)
)

(vl-load-com)
(prompt "Type OC to Offset and Close open ends if appropriate.")
0 Likes