john_ Posted October 12, 2009 Share Posted October 12, 2009 Hi All, Does anyone have a lisp or can help me make one that can draws a line based on the angle of a line that is selected? Example: I have a line that is on a 45 degrees and I have text at the end of the line I want to select the line and have a predetermined line drawn in after the text based on scale of the drawing see attached picture for better clarification. Thank you Quote Link to comment Share on other sites More sharing options...
john_ Posted October 19, 2009 Author Share Posted October 19, 2009 can anyone help? Quote Link to comment Share on other sites More sharing options...
Raggi_Thor Posted October 19, 2009 Share Posted October 19, 2009 How about OSNAP Extension turned on? Or in this (special?) case Polar angle 45? Quote Link to comment Share on other sites More sharing options...
LauKwokFai Posted October 19, 2009 Share Posted October 19, 2009 try "snapang" maybe... (setq draw_obj (entget (car (entsel)))) (command "snapang" (cdr (assoc 10 draw_obj)) (cdr (assoc 11 draw_obj))) Quote Link to comment Share on other sites More sharing options...
Raggi_Thor Posted October 19, 2009 Share Posted October 19, 2009 See here, turn on Extension and Parallell. Then draw your line, use extension to find the first point, move the cursor over your first line and then to the second point to get the Paralell Osnap. Quote Link to comment Share on other sites More sharing options...
dhl Posted October 19, 2009 Share Posted October 19, 2009 not sure if this is what you want, good exercise it was none the less (defun c:angline (/ scale lne selpt pt1 pt2 dist1 dist2 bp bp2 rad) (setq scale (getvar "cannoscalevalue")) (setq lne (entsel "\nSelect line: ")) (setq selpt (cadr lne)) (setq pt1 (cdr (assoc 10 (entget (car lne))))) (setq pt2 (cdr (assoc 11 (entget (car lne))))) (setq dist1 (/ (distance pt1 pt2) 2)) (setq dist2 (distance pt1 selpt)) (if (< dist1 dist2) (progn (setq rad (angle pt1 pt2)) (setq bp (polar pt2 rad (* 1 (/ 1 scale)))) (setq bp2 (polar bp rad 1)) (command "_.line" bp bp2 "") (command "_.lengthen" "dy" bp2 pause) ) (progn (setq rad (angle pt2 pt1)) (setq bp (polar pt1 rad (* 1 (/ 1 scale)))) (setq bp2 (polar bp rad 1)) (command "_.line" bp bp2 "") (command "_.lengthen" "dy" bp2 pause "" "") ) ) (princ) ) this is probably what many of you would call 'clumpsy' code, and as I'm very much a learner I'd love some input on this code and how to possibly improve it Quote Link to comment Share on other sites More sharing options...
Raggi_Thor Posted October 19, 2009 Share Posted October 19, 2009 I tried your code in Acad 2010. It starts Lengthen again it seems. Maybe you need an extra (Command) to cancel everything? Otherwise it works very good. Quote Link to comment Share on other sites More sharing options...
SteveK Posted October 20, 2009 Share Posted October 20, 2009 not sure if this is what you want, good exercise it was none the less (defun c:angline (/ scale lne selpt pt1 pt2 dist1 dist2 bp bp2 rad) (setq scale (getvar "cannoscalevalue")) (setq lne (entsel "\nSelect line: ")) (setq selpt (cadr lne)) (setq pt1 (cdr (assoc 10 (entget (car lne))))) (setq pt2 (cdr (assoc 11 (entget (car lne))))) (setq dist1 (/ (distance pt1 pt2) 2)) (setq dist2 (distance pt1 selpt)) (if (< dist1 dist2) (progn (setq rad (angle pt1 pt2)) (setq bp (polar pt2 rad (* 1 (/ 1 scale)))) (setq bp2 (polar bp rad 1)) (command "_.line" bp bp2 "") (command "_.lengthen" "dy" bp2 pause) ) (progn (setq rad (angle pt2 pt1)) (setq bp (polar pt1 rad (* 1 (/ 1 scale)))) (setq bp2 (polar bp rad 1)) (command "_.line" bp bp2 "") (command "_.lengthen" "dy" bp2 pause "" "") ) ) (princ) ) this is probably what many of you would call 'clumpsy' code, and as I'm very much a learner I'd love some input on this code and how to possibly improve it I am by no means an expert but two things I'd suggest to improve your code is error trapping for your entsel and pts, eg: (if (setq lne (entsel "\nSelect line: ")) (progn ...) (princ "\nNothing Selected.")) The other thing is that you'll notice with other peoples code pretty soon, you can assign multiple variables with setq, eg: (setq a 1 b 2 c 3) sets a = 1, b = 2 and c = 3 Hope that helps a bit. Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 20, 2009 Share Posted October 20, 2009 Would something like this help? (defun c:PAR (/ #Obj #Point) (vl-load-com) (and (setq #Obj (car (entsel "\nSelect line: "))) (eq "LINE" (cdr (assoc 0 (entget #Obj)))) (setq #Point (getpoint "\nSpecify first point: ")) (vl-cmdf "_.line" "_non" #Point (strcat "<" (angtos (vla-get-angle (vlax-ename->vla-object #Obj)) 0 4)) PAUSE "" ) ;_ vl-cmdf ) ;_ and (princ) ) ;_ defun When you get to the point to pick a point, just use the osnap override "ext" and mouse-over the other line. Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 20, 2009 Share Posted October 20, 2009 Oh, and here's a nice addon, perpendicular. :wink: (defun c:Per (/ #Obj #Point #Ang) (and (setq #Obj (entsel "\nSelect line: ")) (eq "LINE" (cdr (assoc 0 (entget (car #Obj))))) (or (setq #Point (getpoint "\nSpecify first point <At Selection>: ")) (setq #Point (vlax-curve-GetClosestPointTo (car #Obj) (cadr #Obj))) ) ;_ or (setq #Ang (angtos (+ (* 0.5 pi) (vla-get-angle (vlax-ename->vla-object (car #Obj)))) 0 4)) (vl-cmdf "_.line" "_non" #Point (strcat "<" #Ang) PAUSE "") ) ;_ and (princ) ) ;_ defun Quote Link to comment Share on other sites More sharing options...
dhl Posted October 21, 2009 Share Posted October 21, 2009 I am by no means an expert but two things I'd suggest to improve your code is error trapping for your entsel and pts, eg: (if (setq lne (entsel "\nSelect line: ")) (progn ...) (princ "\nNothing Selected.")) The other thing is that you'll notice with other peoples code pretty soon, you can assign multiple variables with setq, eg: (setq a 1 b 2 c 3) sets a = 1, b = 2 and c = 3 Hope that helps a bit. thanks a lot for the input. I actually thought I had an error trapping term, but it seems to gone lost somehow. I like to use the while statement however. (defun c:angline (/ scale lne selpt pt1 pt2 dist1 dist2 bp bp2 rad) (setq scale (getvar "cannoscalevalue")) (while (= lne nil) (setq lne (entsel "\nSelect line: ")) ) (setq selpt (cadr lne)) (setq pt1 (cdr (assoc 10 (entget (car lne))))) (setq pt2 (cdr (assoc 11 (entget (car lne))))) (setq dist1 (/ (distance pt1 pt2) 2)) (setq dist2 (distance pt1 selpt)) (if (< dist1 dist2) (progn (setq rad (angle pt1 pt2)) (setq bp (polar pt2 rad (* 1 (/ 1 scale)))) (setq bp2 (polar bp rad 1)) (command "_.line" bp bp2 "") (command "_.lengthen" "dy" bp2 pause) ) (progn (setq rad (angle pt2 pt1)) (setq bp (polar pt1 rad (* 1 (/ 1 scale)))) (setq bp2 (polar bp rad 1)) (command "_.line" bp bp2 "") (command "_.lengthen" "dy" bp2 pause "" "") ) ) (princ) ) I tried your code in Acad 2010. It starts Lengthen again it seems. Maybe you need an extra (Command) to cancel everything? Otherwise it works very good. I tried it in 2009 and it worked for me. I guees I have on too many "" in the last command for 2010. Quote Link to comment Share on other sites More sharing options...
john_ Posted October 21, 2009 Author Share Posted October 21, 2009 Thank you very much dhl and alanjt. Both almost do the exact same thing only difference is the program alanjt made, when you pick the start point for the additional line, the point that you pick can be anywhere and not even with the original line. The program dhl made does exactly what I was looking for. So again thank you all very much for your help and time. Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 21, 2009 Share Posted October 21, 2009 Thank you very much dhl and alanjt.Both almost do the exact same thing only difference is the program alanjt made, when you pick the start point for the additional line, the point that you pick can be anywhere and not even with the original line. The program dhl made does exactly what I was looking for. So again thank you all very much for your help and time. Yeah, I apologize for that, I didn't properly read the request. However, I ended up putting something together that I find useful....not that it helps you. Quote Link to comment Share on other sites More sharing options...
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.