mostafa_mashhadi Posted August 27 Posted August 27 I want to draw a line perpendicular to the white line from point P1 so that the program gives me the coordinates of point P2. This text is translated by Google, sorry if it is not good. Quote
Steven P Posted August 27 Posted August 27 I'm not sure of your skill with LISP and routines but, use perpendicular snap to draw the line, use entlast to get line definition and an (assoc 11 ....) from that to get point B This line will set snaps to perpendicular: (setvar 'osmode 128) Remembering to record what the were before the LISP and set them back afterwards. This line will give you the start point (setq P1 (getpoint "Draw Line")) This will draw the line (command "line" P1 pause "") This line will give you point P2 on a selected line drawn P1-P2 (princ (cdr (assoc 11 (entget (car (entsel "Select Line")))))) which can be modified to get the last entity drawn (princ (cdr (assoc 11 (entget (entlast))))) and if you want to be a bit clever (defun c:test ( / ) (setq os_Old (getvar 'osmode)) (setvar 'osmode 128) (command "line" pause (setq p2 (getpoint)) "") (setvar 'osmode os_old) (princ p2) (princ) ) 1 Quote
mostafa_mashhadi Posted August 27 Author Posted August 27 thank you. You wrote correctly, but I meant that the white line is in the file and I want to find its perpendicular by just clicking and specifying the P2 point. Quote
pkenewell Posted August 27 Posted August 27 (edited) @mostafa_mashhadi In simplest terms: (command "._line" pause "_per" pause); draw a line using the "per" (perpendicular) object snap. 1st PAUSE is selected "P1", 2nd PAUSE is the selected point on the line. (setq p2 (getvar "lastpoint")); P2 stores the last point selected, modified to be perpendicular to the line Did you want a more mathematical solution? Please be more specific. - Is the existing line segment just a LINE or a part of a POLYLINE, could it be both? Here is another trick solution I have used which doesn't require that much code: (defun c:foo (/ rp lp1 lp2 a p2 pp sl) (if (and (setq sl (entsel "\nPick a point on the line: ")) (setq rp (cadr sl) lp1 (osnap rp "mid") lp2 (osnap rp "end") a (angle lp1 lp2)) (setq p2 (getpoint "\nSelect Perpendicular source point: ")) ) (progn (setq pp (inters lp1 lp2 p2 (polar p2 (+ a (/ pi 2)) 1.0) nil)) (command "._line" "_non" pp "_non" p2 "") (princ (strcat "\nPerpendicular Coordinate: " (rtos (car pp)) "," (rtos (cadr pp)) "," (rtos (caddr pp)))) ) ) (princ) ) NOTE: the coordinates of the point you want are stored in variable "pp". EDIT - I updated the 1st pick to be a select box for the line for easier selection. Edited August 27 by pkenewell Improved code. 3 Quote
Tsuky Posted August 27 Posted August 27 You can try this. This raises a perpendicular in the current UCS from the feature selection point (straight or curved segment). If you want to start from a specific point, force the appropriate osnap object (near, node, etc.) before selecting the object. (defun elperr (ch) (cond ((or (eq ch "Function cancelled") (eq ch "quit / exit abort") (eq ch "console break")) nil) (T (princ ch)) ) (setvar "osmode" old_osmd) (setvar "orthomode" old_orth) (setvar "snapang" old_snp) (setq *error* olderr) (princ) ) (defun c:elp ( / olderr *error* js ent-sel ent pt_sel obj_curv old_osmd old_snp old_orth param deriv pt_tmp p_from p_to) (vl-load-com) (setq olderr *error* *error* elperr) (princ "\nRaise a perpendicular to: ") (while (not (setq js (ssget "_+.:E:S" '((0 . "*LINE,ARC,CIRCLE,ELLIPSE,RAY")))))) (setq ent-sel (ssnamex js 0) ent (cadar ent-sel) pt_sel (cadar (cdddar ent-sel)) obj_curv (vlax-ename->vla-object ent) ) (cond ((member (vlax-get-property obj_curv 'ObjectName) '("AcDbPolyline" "AcDb2dPolyline" "AcDbLine" "AcDbArc" "AcDbCircle" "AcDbEllipse" "AcDbSpline" "AcDbRay" "AcDbXline") ) (setq old_osmd (getvar "osmode") old_snp (getvar "snapang") old_orth (getvar "orthomode") pt_sel (vlax-curve-getClosestPointTo obj_curv pt_sel) param (vlax-curve-getparamatpoint obj_curv pt_sel) deriv (vlax-curve-getfirstderiv obj_curv param) ) (setq pt_tmp (polar pt_sel (+ (atan (cadr deriv) (car deriv)) (/ pi 2)) 100.0)) (setvar "snapang" (angle (trans pt_sel 0 1) (trans pt_tmp 0 1))) (setvar "orthomode" 1) (if (null (setq p_from (getpoint "\nFrom point <last>: "))) (setq p_from (trans pt_sel 0 1)) ) (setvar "osmode" 0) (initget 9) (setq p_to (getpoint p_from "\nTo the point: ")) (command "_.line" p_from p_to "") (setvar "osmode" old_osmd) (setvar "orthomode" old_orth) (setvar "snapang" old_snp) ) (T (princ "\nInvalid object!")) ) (setq *error* olderr) (princ) ) 1 Quote
mostafa_mashhadi Posted August 27 Author Posted August 27 Thank you very much. This is exactly what I wanted 1 Quote
mostafa_mashhadi Posted August 27 Author Posted August 27 hello friends According to the photo, can someone write a program that selects the points P1 and P2 and the floating point PX in the drawing page of the program next to the floating point line and offset to print it. I translated with Google, it may not be translated correctly. I do not speak English, please help me. Quote
BIGAL Posted August 27 Posted August 27 If I understand correctly, dont need a line you want P2 perpendicular to a point. Look at VL closestpointto function does what you want. If you want snaps for point then do a pt1 and use that in closestpointto. (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) (setq obj (vlax-ename->vla-object (car (entsel "\nSelect a object ")))) (setq pt2 (vlax-curve-getclosestpointto obj (Getpoint "\nPick point "))) Quote
BIGAL Posted August 27 Posted August 27 This is similar to your request can redo it so it asks for values. I think I have it some where. Perp to 2 pts.lsp 1 Quote
mostafa_mashhadi Posted August 28 Author Posted August 28 I made some changes to your program. Please review and give your feedback to improve the app. Thanks Line&Offset.lsp Quote
Tsuky Posted August 28 Posted August 28 And just this? (defun c:foo ( / p1 p2 p3 p4 px dx dy) (initget 9) (setq p1 (getpoint "\nFirst point: ")) (initget 9) (setq p2 (getpoint p1 "\nSecond point: ")) (initget 9) (setq p3 (getpoint "\nPoint to calculate?:") p4 (polar p3 (+ (angle p1 p2) (* 0.5 pi)) (distance p1 p2)) px (inters p1 p2 p3 p4 nil) dx (distance p1 px) dy (distance px p3) ) (entmake (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 p3) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar p3 0.0 (getvar "TEXTSIZE"))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "Line: " (rtos dx))) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar (polar p3 0.0 (getvar "TEXTSIZE")) (- (* 0.5 pi)) (* 1.923076923076925 (getvar "TEXTSIZE")))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "OFFSET: " (rtos dy))) ) ) (prin1) ) 1 Quote
mostafa_mashhadi Posted August 28 Author Posted August 28 28 minutes ago, Tsuky said: And just this? (defun c:foo ( / p1 p2 p3 p4 px dx dy) (initget 9) (setq p1 (getpoint "\nFirst point: ")) (initget 9) (setq p2 (getpoint p1 "\nSecond point: ")) (initget 9) (setq p3 (getpoint "\nPoint to calculate?:") p4 (polar p3 (+ (angle p1 p2) (* 0.5 pi)) (distance p1 p2)) px (inters p1 p2 p3 p4 nil) dx (distance p1 px) dy (distance px p3) ) (entmake (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 p3) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar p3 0.0 (getvar "TEXTSIZE"))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "Line: " (rtos dx))) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar (polar p3 0.0 (getvar "TEXTSIZE")) (- (* 0.5 pi)) (* 1.923076923076925 (getvar "TEXTSIZE")))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "OFFSET: " (rtos dy))) ) ) (prin1) ) (defun c:foo ( / p1 p2 p3 p4 px dx dy) (command "textstyle" "Standard") (command "pdmode" 35) (initget 9) (setq p1 (getpoint "\nFirst point: ")) (initget 9) (setq p2 (getpoint p1 "\nSecond point: ")) (initget 9) (command "Line" p1 p2 "") (while (setq p3 (getpoint "\nPoint to calculate?:") p4 (polar p3 (+ (angle p1 p2) (* 0.5 pi)) (distance p1 p2)) px (inters p1 p2 p3 p4 nil) dx (distance p1 px) dy (distance px p3) ) (entmake (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 p3) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar p3 0.0 (getvar "TEXTSIZE"))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "Line: " (rtos dx))) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar (polar p3 0.0 (getvar "TEXTSIZE")) (- (* 0.5 pi)) (* 1.923076923076925 (getvar "TEXTSIZE")))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "OFFSET: " (rtos dy))) ) )) (prin1) ) Hello, thank you. I saw your program. I made a slight change in it. But there is a problem. I want to ask the user the height of the text at the beginning of the program. I also want the coordinates of the same point to be printed in point 1 and point 2. can you help me Quote
SLW210 Posted August 28 Posted August 28 I merged your posts, stop creating new posts for the same topic. 1 Quote
Tsuky Posted August 28 Posted August 28 Quote Hello, thank you. I saw your program. I made a slight change in it. But there is a problem. I want to ask the user the height of the text at the beginning of the program. I also want the coordinates of the same point to be printed in point 1 and point 2. can you help me (defun make_text (pt str / ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 pt) (cons 40 (getvar "TEXTSIZE")) (cons 1 str) ) ) ) (defun c:line&offset ( / old_styl txt_size p1 p2 p3 p4 px dx dy) (setq old_styl (getvar "TEXTSTYLE")) (setvar "TEXTSTYLE" "Standard") (initget 6) (if (setq txt_size (getdist (getvar "VIEWCTR") (strcat "\nNew textsize <" (rtos (getvar "TEXTSIZE")) ">: "))) (setvar "TEXTSIZE" txt_size) ) (mapcar 'setvar '("PDMODE" "PDSIZE") (list 35 (* 0.25 (getvar "TEXTSIZE")))) (initget 9) (setq p1 (getpoint "\nFirst point: ")) (initget 9) (setq p2 (getpoint p1 "\nSecond point: ")) (entmake (list '(0 . "LINE") '(100 . "AcDbEntity") '(100 . "AcDbLine") (cons 10 p1) (cons 11 p2) ) ) (mapcar '(lambda (x) (make_text (car x) (cdr x))) (list (cons (polar p1 0.0 (getvar "TEXTSIZE")) (strcat "X: " (rtos (car p1)))) (cons (polar (polar p1 0.0 (getvar "TEXTSIZE")) (- (* 0.5 pi)) (* 1.923076923076925 (getvar "TEXTSIZE"))) (strcat "Y: " (rtos (cadr p1)))) (cons (polar p2 0.0 (getvar "TEXTSIZE")) (strcat "X: " (rtos (car p2)))) (cons (polar (polar p2 0.0 (getvar "TEXTSIZE")) (- (* 0.5 pi)) (* 1.923076923076925 (getvar "TEXTSIZE"))) (strcat "Y: " (rtos (cadr p2)))) ) ) (initget 9) (while (setq p3 (getpoint "\nPoint to calculate?:")) (setq p4 (polar p3 (+ (angle p1 p2) (* 0.5 pi)) (distance p1 p2)) px (inters p1 p2 p3 p4 nil) dx (distance p1 px) dy (distance px p3) ) (entmake (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 p3) ) ) (mapcar '(lambda (x) (make_text (car x) (cdr x))) (list (cons (polar p3 0.0 (getvar "TEXTSIZE")) (strcat "Line: " (rtos dx))) (cons (polar (polar p3 0.0 (getvar "TEXTSIZE")) (- (* 0.5 pi)) (* 1.923076923076925 (getvar "TEXTSIZE"))) (strcat "OFFSET: " (rtos dy))) ) ) ) (setvar "TEXTSTYLE" old_styl) (prin1) ) 2 Quote
mostafa_mashhadi Posted August 28 Author Posted August 28 5 hours ago, mostafa_mashhadi said: (defun c:foo ( / p1 p2 p3 p4 px dx dy) (command "textstyle" "Standard") (command "pdmode" 35) (initget 9) (setq p1 (getpoint "\nFirst point: ")) (initget 9) (setq p2 (getpoint p1 "\nSecond point: ")) (initget 9) (command "Line" p1 p2 "") (while (setq p3 (getpoint "\nPoint to calculate?:") p4 (polar p3 (+ (angle p1 p2) (* 0.5 pi)) (distance p1 p2)) px (inters p1 p2 p3 p4 nil) dx (distance p1 px) dy (distance px p3) ) (entmake (list '(0 . "POINT") '(100 . "AcDbEntity") '(100 . "AcDbPoint") (cons 10 p3) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar p3 0.0 (getvar "TEXTSIZE"))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "Line: " (rtos dx))) ) ) (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(100 . "AcDbText") (cons 10 (polar (polar p3 0.0 (getvar "TEXTSIZE")) (- (* 0.5 pi)) (* 1.923076923076925 (getvar "TEXTSIZE")))) (cons 40 (getvar "TEXTSIZE")) (cons 1 (strcat "OFFSET: " (rtos dy))) ) )) (prin1) ) Hello, thank you. I saw your program. I made a slight change in it. But there is a problem. I want to ask the user the height of the text at the beginning of the program. I also want the coordinates of the same point to be printed in point 1 and point 2. can you help me Thank you, great 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.