Dhammike Posted May 7, 2020 Share Posted May 7, 2020 i need create two points at either side of a line at once. (setq L1(entsel "Get Line:")) (setq enL1(entget(entlast))) (setq ptL1STT (cdr (assoc 10 enL1))) (setq ptL1END (cdr (assoc 11 enL1))) (setq aa (angle (cdr (assoc 10 enL1)) (cdr (assoc 11 enL1)));angle );setq (setq dd (distance (cdr (assoc 10 enL1)) (cdr (assoc 11 enL1)));distance );setq (setq midpnt(polar ptL1STT aa (/ dd 2))) (setq p1 (polar midpnt (+ aa (/ pi 4)) 1.0) );setq (setq L2(command "offset" 1.0 L1 p1"")) From above code, i can make one offset line at one side. now i need create another offset line at opposite side. Can i get correct code for above. Thank you in advance. Quote Link to comment Share on other sites More sharing options...
dlanorh Posted May 7, 2020 Share Posted May 7, 2020 (edited) 58 minutes ago, Dhammike said: i need create two points at either side of a line at once. (setq L1(entsel "Get Line:")) (setq enL1(entget(entlast))) (setq ptL1STT (cdr (assoc 10 enL1))) (setq ptL1END (cdr (assoc 11 enL1))) (setq aa (angle (cdr (assoc 10 enL1)) (cdr (assoc 11 enL1)));angle );setq (setq dd (distance (cdr (assoc 10 enL1)) (cdr (assoc 11 enL1)));distance );setq (setq midpnt(polar ptL1STT aa (/ dd 2))) (setq p1 (polar midpnt (+ aa (/ pi 4)) 1.0) );setq (setq L2(command "offset" 1.0 L1 p1"")) From above code, i can make one offset line at one side. now i need create another offset line at opposite side. Can i get correct code for above. Thank you in advance. Are you trying to offset the original line 1 unit at 90 degrees or through point p1 which is 1 unit from the midpoint at 45 degrees (/ pi 4 is 45 degrees) ? Edited May 7, 2020 by dlanorh Quote Link to comment Share on other sites More sharing options...
Dhammike Posted May 8, 2020 Author Share Posted May 8, 2020 18 hours ago, dlanorh said: Are you trying to offset the original line 1 unit at 90 degrees or through point p1 which is 1 unit from the midpoint at 45 degrees (/ pi 4 is 45 degrees) ? I just want to two offset lines at either side of a line. (if (< (/ pi 2) aa (* pi 1.5));less than (setq sttp1 (cdr (assoc 11 enL1)) aa (rem (+ aa pi)(* pi 2)) );setq (setq sttp1 (cdr (assoc 10 enL1))));if (setq midpnt(polar sttp1 aa (/ dd 2))) I used above code to solve the problem. now all ok. thankyou again for helping me. 20 hours ago, dlanorh said: Are you trying to offset the original line 1 unit at 90 degrees or through point p1 which is 1 unit from the midpoint at 45 degrees (/ pi 4 is 45 degrees) ? 20 hours ago, dlanorh said: Are you trying to offset the original line 1 unit at 90 degrees or through point p1 which is 1 unit from the midpoint at 45 degrees (/ pi 4 is 45 degrees) ? On 4/26/2020 at 9:50 AM, Dhammike said: (setq x ptlst) (setq lst(mapcar '(lambda ( x ) (read (strcat "(" (vl-string-translate "," " " x) ")"))) lst)) (princ lst) (setq ss4 (ssget "_WP" lst (list (cons 0 "*Text")))) (setq i (1 - i)) (setq en (ssname ss2 (setq k (1 + k)))) (setq ent (entget en)) I used above code and i got below results. ("426982.418,511619.699" "426974.535,511603.142" "426964.041,511609.123" "426954.742,511612.095" "426946.029,511615.082" "426950.240,511625.283" "426955.404,511635.795" "426959.956,511644.578" "426970.869,511642.286" "426979.196,511640.264" "426985.400,511638.352" "426990.116,511635.794") nil nil nil ; error: too many arguments _$ Still my problem not solved. thank you for helping me. I am waiting for your answer. Quote Link to comment Share on other sites More sharing options...
dlanorh Posted May 8, 2020 Share Posted May 8, 2020 14 minutes ago, Dhammike said: I just want to two offset lines at either side of a line. (if (< (/ pi 2) aa (* pi 1.5));less than (setq sttp1 (cdr (assoc 11 enL1)) aa (rem (+ aa pi)(* pi 2)) );setq (setq sttp1 (cdr (assoc 10 enL1))));if (setq midpnt(polar sttp1 aa (/ dd 2))) I used above code to solve the problem. now all ok. thankyou again for helping me. Look at these. They all work in AutoCAD Windows version. There may be a problem with the last one if you are not running windows ;; THIS IS YOUR CODE. I'VE CHANGED THE VARIABLE NAMES TO BETTER REFLECT WHAT EACH VARIABLE IS ;; AT THE END ARE TWO WAYS YOU CAN OFFSET EITHER SIDE USING THE TWO POINTS (defun c:doff ( / ent elst spt ept ang dd mpt p1 p2) (while (not ent) (setq ent (car (entsel "Get Line:")) elst (entget ent) ) (if (/= (cdr (assoc 0 elst)) "LINE") (setq ent nil)) );end_while (setq spt (cdr (assoc 10 elst)) ept (cdr (assoc 11 elst)) ang (angle spt ept) dd (* (distance spt ept) 0.5) mpt (polar spt ang (/ dd 2.0)) p1 (polar mpt (+ ang (* pi 0.25)) 1.0) p2 (polar mpt (- ang (* pi 0.25)) 1.0) ) (foreach pt (list p1 p2) (command "offset" 1.0 ent pt "")) ;(command "offset" 1.0 ent p1 ent p2 "") ) ;; THIS IS YOUR CODE BUT OPTIMISED SLIGHTLY. YOU DON'T NEED TO FIND THE MID POINT ;; AS EVERYTHING CAN BE DONE FROM THE START POINT OF THE LINE (defun c:doff ( / ent elst spt ang p1 p2) (while (not ent) (setq ent (car (entsel "Get Line:")) elst (entget ent) ) (if (/= (cdr (assoc 0 elst)) "LINE") (setq ent nil)) );end_while (setq spt (cdr (assoc 10 elst)) ang (angle spt ept) p1 (polar spt (+ ang (* pi 0.5)) 1.0) p2 (polar spt (- ang (* pi 0.5)) 1.0) ) (foreach pt (list p1 p2) (command "offset" 1.0 ent pt "")) ;(command "offset" 1.0 ent p1 ent p2 "") ) ;; AS YOU PROGRESS YOU WILL FIND THAT THIS IS AN EASIER WAY TO DO THIS ;; THIS IS A SELECTION SET WHERE ONLY ONE ITEM CAN BE SELECTED, BUT ;; IF YOU REMOVE "_+.:E:S" AND LEAVE ":L" YOU CAN SELECT AND OFFSET ;; MULTIPLE LINES ON UNLOCKED LAYERS (defun c:doff ( / dd ss obj) (vl-load-com) (initget 7) (setq dd (getreal "\nEnter Offset Distance : ")) (prompt "Select Entity to Offset : ") (setq ss (ssget "_+.:E:S:L" '((0 . "LINE")))) (cond (ss (setq obj (vlax-ename->vla-object (ssname ss 0))) (foreach d (list dd (* dd -1.0)) (vlax-invoke obj 'offset d)) ) ) ) Quote Link to comment Share on other sites More sharing options...
Dhammike Posted May 8, 2020 Author Share Posted May 8, 2020 2 hours ago, dlanorh said: Look at these. They all work in AutoCAD Windows version. There may be a problem with the last one if you are not running windows ;; THIS IS YOUR CODE. I'VE CHANGED THE VARIABLE NAMES TO BETTER REFLECT WHAT EACH VARIABLE IS ;; AT THE END ARE TWO WAYS YOU CAN OFFSET EITHER SIDE USING THE TWO POINTS (defun c:doff ( / ent elst spt ept ang dd mpt p1 p2) (while (not ent) (setq ent (car (entsel "Get Line:")) elst (entget ent) ) (if (/= (cdr (assoc 0 elst)) "LINE") (setq ent nil)) );end_while (setq spt (cdr (assoc 10 elst)) ept (cdr (assoc 11 elst)) ang (angle spt ept) dd (* (distance spt ept) 0.5) mpt (polar spt ang (/ dd 2.0)) p1 (polar mpt (+ ang (* pi 0.25)) 1.0) p2 (polar mpt (- ang (* pi 0.25)) 1.0) ) (foreach pt (list p1 p2) (command "offset" 1.0 ent pt "")) ;(command "offset" 1.0 ent p1 ent p2 "") ) ;; THIS IS YOUR CODE BUT OPTIMISED SLIGHTLY. YOU DON'T NEED TO FIND THE MID POINT ;; AS EVERYTHING CAN BE DONE FROM THE START POINT OF THE LINE (defun c:doff ( / ent elst spt ang p1 p2) (while (not ent) (setq ent (car (entsel "Get Line:")) elst (entget ent) ) (if (/= (cdr (assoc 0 elst)) "LINE") (setq ent nil)) );end_while (setq spt (cdr (assoc 10 elst)) ang (angle spt ept) p1 (polar spt (+ ang (* pi 0.5)) 1.0) p2 (polar spt (- ang (* pi 0.5)) 1.0) ) (foreach pt (list p1 p2) (command "offset" 1.0 ent pt "")) ;(command "offset" 1.0 ent p1 ent p2 "") ) ;; AS YOU PROGRESS YOU WILL FIND THAT THIS IS AN EASIER WAY TO DO THIS ;; THIS IS A SELECTION SET WHERE ONLY ONE ITEM CAN BE SELECTED, BUT ;; IF YOU REMOVE "_+.:E:S" AND LEAVE ":L" YOU CAN SELECT AND OFFSET ;; MULTIPLE LINES ON UNLOCKED LAYERS (defun c:doff ( / dd ss obj) (vl-load-com) (initget 7) (setq dd (getreal "\nEnter Offset Distance : ")) (prompt "Select Entity to Offset : ") (setq ss (ssget "_+.:E:S:L" '((0 . "LINE")))) (cond (ss (setq obj (vlax-ename->vla-object (ssname ss 0))) (foreach d (list dd (* dd -1.0)) (vlax-invoke obj 'offset d)) ) ) ) Thank you very much. 23 hours ago, dlanorh said: Are you trying to offset the original line 1 unit at 90 degrees or through point p1 which is 1 unit from the midpoint at 45 degrees (/ pi 4 is 45 degrees) ? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 8, 2020 Share Posted May 8, 2020 (edited) A quiker way is using Vla-offset it supports direct +ve and -ve values so get a left and right. Like others I have some offset routines so for both sides the request would be 1,-1 this would do 2 lines -1,1,2,-2 would do 4 lines can be any number all +ve or a mix. An example of vla-offset, as mentioned will not work on MAC (setq obj (vlax-ename->vla-object (car (entsel "Pick object ")))) (while (setq x (getreal "\nEnter offset -ve ok Enter to exit")) (vla-offset obj x) ) Edited May 8, 2020 by BIGAL Quote Link to comment Share on other sites More sharing options...
Dhammike Posted May 9, 2020 Author Share Posted May 9, 2020 thank you very much 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.