LISP2LEARN Posted August 16, 2011 Posted August 16, 2011 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) ) ) Quote
Lee Mac Posted August 16, 2011 Posted August 16, 2011 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) ) Quote
LISP2LEARN Posted August 16, 2011 Author Posted August 16, 2011 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! Quote
Lee Mac Posted August 16, 2011 Posted August 16, 2011 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. Quote
LISP2LEARN Posted August 16, 2011 Author Posted August 16, 2011 all my lines are parallel so I just pick all vertical, horizontal or diagonal and offset those lines. Quote
Lee Mac Posted August 16, 2011 Posted August 16, 2011 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. Quote
LISP2LEARN Posted August 16, 2011 Author Posted August 16, 2011 That was quick. Thanks Lee. I'll break up your code and learn from it... Thanks again. Quote
alanjt Posted August 16, 2011 Posted August 16, 2011 (defun c:test ( / a b c d e[color=red] [b]f l o p[/b][/color] ) LoL............... Quote
alanjt Posted August 17, 2011 Posted August 17, 2011 Please tell me what does "LOL" mean Laugh Out Loud Quote
ketxu Posted August 17, 2011 Posted August 17, 2011 Ah, i see ^^ LOL -> Thank you. (srr OP for this marginal question ) Quote
Lee Mac Posted August 17, 2011 Posted August 17, 2011 What is that mean ? I shall let Alan explain that one... Quote
Tharwat Posted August 17, 2011 Posted August 17, 2011 I shall let Alan explain that one... I know that he can't. Quote
alanjt Posted August 17, 2011 Posted August 17, 2011 I know that he can't. What The £µ¢k are you talking about? Quote
Tharwat Posted August 17, 2011 Posted August 17, 2011 Now Ketxu have more extra abbreviations to learn . Enjoy it buddy. Thank you Alan . Quote
Recommended Posts
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.