Jump to content

Help on Offset


LISP2LEARN

Recommended Posts

Hi guys,

 

How can I fix my code. I want to offset a line and then lengthen the resultant line by 3 inch on both sides. Since I pick my points on the end points on the resultant line when there is a line on pt1 and pt2 it also lengthen that line. In short I only want to lenghten the result offseted line. I want to use entmod but I can't figure it out. Thanks.

 

(defun C:test (/ ol ent pt pt1 pt2)

(while
  (and
     (setq ent (car (entsel "\nSelect a line to offset or <exit>:")))
     (setq pt (getpoint "\nSpecify point on side to offset:"))
   )
(command "._offset" 3 ent "_non" pt "")
(setq ol (entlast))
;(command "._change" ol "" "_P" "_LA" "no_plot" "")


(setq pt1 (cdr(assoc 10 (entget ol))))
(command "_.lengthen" "_de" "3" "_non" pt1 "")

(setq pt2 (cdr(assoc 11(entget ol))))
(command "_.lengthen" "_de" "3" "_non" pt2 "")

(princ)
)
)

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    5

  • Lee Mac

    5

  • Tharwat

    4

  • LISP2LEARN

    4

Top Posters In This Topic

If you are working with Line entities, I would be inclined to perform the offset and lengthen operations by calculating the endpoints of the new Line entity and using entmake.

 

Here is an example which should also work in all UCS/Views:

 

(defun c:test ( / a b c d e f l o p )

   (setq o 3.0) ;; Offset

   (while
       (progn (setvar 'ERRNO 0) (setq e (car (entsel "\nSelect a Line to Offset: ")))
           (cond
               (   (= 7 (getvar 'ERRNO))
                   (princ "\nMissed, Try Again.")
               )
               (   (not e)
                   nil
               )
               (   (not (eq "LINE" (cdr (assoc 0 (setq l (entget e))))))
                   (princ "\nPlease Select a Line.")
               )
               (   (setq p (getpoint "\nSpecify Side to Offset: "))
                   (setq a (trans (cdr (assoc 10 l)) 0 1)
                         b (trans (cdr (assoc 11 l)) 0 1)
                         c (angle a b)
                         d (+ c (/ pi 2.0))
                         f (if (minusp (cos (- d (angle a p)))) - +)
                   )
                   (entmakex
                       (list
                           (cons 0 "LINE")
                           (cons 10 (trans (polar (polar a d (f o)) c (- o)) 1 0))
                           (cons 11 (trans (polar (polar b d (f o)) c    o ) 1 0))
                       )
                   )
               )
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

Ok thanks, didn't put it that way. I always modify the entity after I created it. I will keep that in mind.

 

If you are working with Line entities, I would be inclined to perform the offset and lengthen operations by calculating the endpoints of the new Line entity and using entmake.

 

Last thing, how can I pick multiple lines at once so I can offset multiple lines on one side like:

 

(setq e (ssget ":L" '((0 . "line"))))

 

If it's much trouble don't bother, you have help me enough.

 

Thanks again Lee!

Link to comment
Share on other sites

Last thing, how can I pick multiple lines at once so I can offset multiple lines on one side like:

 

(setq e (ssget ":L" '((0 . "line"))))

 

You could use the first line in the Selection to gauge to which side to offset, but since the lines could have any orientation, you could receive different results for each line.

Link to comment
Share on other sites

This would use the same method, the offet determined by the point relative to the first line in the Selection:

 

(defun c:test ( / a b c d f i l o p s )

   (setq o 3.0) ;; Offset

   (if
       (and
           (setq s (ssget '((0 . "LINE"))))
           (progn
               (redraw (ssname s 0) 3)
               (setq p (getpoint "\nSpecify Side of Highlighted Line to Offset: "))
               (redraw (ssname s 0) 4)
               p
           )
       )
       (progn
           (setq l (entget (ssname s 0))
                 a (trans (cdr (assoc 10 l)) 0 1)
                 b (trans (cdr (assoc 11 l)) 0 1)
                 c (angle a b)
                 d (+ c (/ pi 2.0))
                 f (if (minusp (cos (- d (angle a p)))) - +)
           )
           (repeat (setq i (sslength s))
               (setq l (entget (ssname s (setq i (1- i))))
                     a (trans (cdr (assoc 10 l)) 0 1)
                     b (trans (cdr (assoc 11 l)) 0 1)
                     c (angle a b)
                     d (+ c (/ pi 2.0))
               )
               (entmakex
                   (list
                       (cons 0 "LINE")
                       (cons 10 (trans (polar (polar a d (f o)) c (- o)) 1 0))
                       (cons 11 (trans (polar (polar b d (f o)) c    o ) 1 0))
                   )
               )
           )
       )
   )
   (princ)
)

 

If you have any questions about the method, please ask - I thought this was meant to be a learning exercise.

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