heng7653 Posted September 17, 2016 Posted September 17, 2016 Hi i need a LISP for draw a line(2 point), offset it(erase source) and then repeat again draw line and offset until i press Esc for end this command. Ask for offset distance before i draw a line for one time only. Thanks for your help.. Quote
Tharwat Posted September 17, 2016 Posted September 17, 2016 Hi, Try this program and just hit ENTER if you want to end the program. (defun c:test (/ off pt1 pt2 ent vla) ;; Tharwat - 17.Sep.2016 ;; (cond ((= 4 (logand 4 (cdr (assoc 70 (entget (tblobjname "LAYER" (getvar 'clayer))))))) (alert "Current layer is Locked <!>")) ((setq off (getdist "\nSpecify offset distance :")) (while (and (setq pt1 (getpoint "\n1st point :")) (setq pt2 (getpoint "\n2nd point :" pt1)) (setq ent (entmakex (list '(0 . "LINE") (cons 10 (trans pt1 1 0)) (cons 11 (trans pt2 1 0))))) (setq vla (vlax-ename->vla-object ent)) ) (mapcar '(lambda (d) (vla-offset vla d)) (list off (- off))) (entdel ent) ) ) ) (princ) )(vl-load-com) Quote
Grrr Posted September 17, 2016 Posted September 17, 2016 Heres my practice/attempt (didn't fully understood what should've be the result from the offset): [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / acDoc uFlag SysVars *error* d p pl pn OFFpoly [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq uFlag [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]vla-StartUndoMark [b][color=GREEN]([/color][/b]setq acDoc [b][color=BLUE]([/color][/b]vla-get-ActiveDocument [b][color=RED]([/color][/b]vlax-get-acad-object[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [color=#8b4513]; [b][color=FUCHSIA]([/color][/b]vlax-invoke [b][color=NAVY]([/color][/b]or acDoc [b][color=MAROON]([/color][/b]setq acDoc [b][color=GREEN]([/color][/b]vla-get-ActiveDocument [b][color=BLUE]([/color][/b]vlax-get-acad-object[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] 'StartUndoMark[b][color=FUCHSIA])[/color][/b][/color] [b][color=FUCHSIA]([/color][/b]setq SysVars [b][color=NAVY]([/color][/b]mapcar '[b][color=MAROON]([/color][/b]lambda [b][color=GREEN]([/color][/b]x[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]list x [b][color=BLUE]([/color][/b]getvar x[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] '[b][color=MAROON]([/color][/b][color=#2f4f4f]"CMDECHO"[/color] [color=#2f4f4f]"CLIPROMPTLINES"[/color] [color=#2f4f4f]"NOMUTT"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]mapcar '[b][color=NAVY]([/color][/b]lambda [b][color=MAROON]([/color][/b]n v[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setvar n v[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]mapcar 'car SysVars[b][color=NAVY])[/color][/b] '[b][color=NAVY]([/color][/b]0 2 0[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun stringp [b][color=NAVY]([/color][/b] x / [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]= [b][color=GREEN]([/color][/b]type x[b][color=GREEN])[/color][/b] 'STR[b][color=MAROON])[/color][/b] 'T nil[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun *error* [b][color=NAVY]([/color][/b] msg [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and uFlag [b][color=MAROON]([/color][/b]vla-EndUndoMark acDoc[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [color=#8b4513]; [b][color=NAVY]([/color][/b]and acDoc [b][color=MAROON]([/color][/b]vlax-invoke acDoc 'EndUndoMark[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][/color] [b][color=NAVY]([/color][/b]if SysVars [b][color=MAROON]([/color][/b]mapcar '[b][color=GREEN]([/color][/b]lambda [b][color=BLUE]([/color][/b]x[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]setvar [b][color=RED]([/color][/b]car x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cadr x[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] SysVars[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]if OFFpoly [b][color=MAROON]([/color][/b]entdel OFFpoly[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]or [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]member msg '[b][color=RED]([/color][/b][color=#2f4f4f]"Function cancelled"[/color] [color=#2f4f4f]"quit / exit abort"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]wcmatch [b][color=BLUE]([/color][/b]strcase msg[b][color=BLUE])[/color][/b] [color=#2f4f4f]"*BREAK,*CANCEL*,*EXIT*"[/color][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]princ [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"\nError: "[/color] msg[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ[b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]setq d [b][color=MAROON]([/color][/b]getreal [color=#2f4f4f]"\nSpecify offset distance: "[/color][b][color=MAROON])[/color][/b] p [b][color=MAROON]([/color][/b]getpoint [color=#2f4f4f]"\nSpecify first point for the line: "[/color][b][color=MAROON])[/color][/b] pl [b][color=MAROON]([/color][/b]list p[b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]setvar 'errno 0[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]/= [b][color=BLUE]([/color][/b]getvar 'errno[b][color=BLUE])[/color][/b] 52[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]initget 128 [color=#2f4f4f]"Done Exit"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]if pn [b][color=BLUE]([/color][/b]setq pn [b][color=RED]([/color][/b]getpoint pn [color=#2f4f4f]"\nSpecify next point or [Done/Exit]: "[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]setq pn [b][color=RED]([/color][/b]getpoint p [color=#2f4f4f]"\nSpecify next point: "[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cond [b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]or [b][color=PURPLE]([/color][/b]= pn [color=#2f4f4f]""[/color][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]not pn[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]null pn[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]setq pn pn[b][color=RED])[/color][/b] [b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]and [b][color=PURPLE]([/color][/b]not [b][color=TEAL]([/color][/b]stringp pn[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]/= pn [color=#2f4f4f]""[/color][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]listp pn[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]setq pl [b][color=PURPLE]([/color][/b]append pl [b][color=TEAL]([/color][/b]list pn[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]if OFFpoly [b][color=PURPLE]([/color][/b]entdel OFFpoly[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]if [b][color=PURPLE]([/color][/b]LWPoly pl 0[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]progn [b][color=TEAL]([/color][/b]vl-cmdf [color=#2f4f4f]"_.OFFSET"[/color] [color=#2f4f4f]"_Erase"[/color] [color=#2f4f4f]"_Y"[/color] d [b][color=OLIVE]([/color][/b]entlast[b][color=OLIVE])[/color][/b] d [color=#2f4f4f]""[/color][b][color=TEAL])[/color][/b] [b][color=TEAL]([/color][/b]setq OFFpoly [b][color=OLIVE]([/color][/b]entlast[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] [b][color=PURPLE])[/color][/b] [b][color=RED])[/color][/b] [b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]and [b][color=PURPLE]([/color][/b]stringp pn[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]/= pn [color=#2f4f4f]""[/color][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]wcmatch pn [color=#2f4f4f]"D*"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]if OFFpoly [b][color=PURPLE]([/color][/b]vl-cmdf [color=#2f4f4f]"_.EXPLODE"[/color] OFFpoly[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]setvar 'errno 52[b][color=RED])[/color][/b] [b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]and [b][color=PURPLE]([/color][/b]stringp pn[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]wcmatch pn [color=#2f4f4f]"E*"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]princ [color=#2f4f4f]"\nExiting! "[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]if OFFpoly [b][color=PURPLE]([/color][/b]entdel OFFpoly[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]setvar 'errno 52[b][color=RED])[/color][/b] [b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]T nil [b][color=BLUE])[/color][/b] [b][color=GREEN])[/color][/b][color=#8b4513]; cond[/color] [b][color=MAROON])[/color][/b][color=#8b4513]; while[/color] [b][color=NAVY])[/color][/b][color=#8b4513]; progn[/color] [b][color=FUCHSIA])[/color][/b][color=#8b4513]; if[/color] [b][color=FUCHSIA]([/color][/b]mapcar '[b][color=NAVY]([/color][/b]lambda [b][color=MAROON]([/color][/b]x[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setvar [b][color=GREEN]([/color][/b]car x[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cadr x[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] SysVars[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq uFlag [b][color=NAVY]([/color][/b]vla-EndUndoMark acDoc[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [color=#8b4513]; [b][color=FUCHSIA]([/color][/b]vlax-invoke acDoc 'EndUndoMark[b][color=FUCHSIA])[/color][/b][/color] [b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b][color=#8b4513];| defun |; [b][color=BLACK]([/color][/b]vl-load-com[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]princ[b][color=BLACK])[/color][/b][/color] [color=#8b4513]; © Lee Mac[/color] [b][color=BLACK]([/color][/b]defun LWPoly [b][color=FUCHSIA]([/color][/b]lst cls[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]entmakex [b][color=NAVY]([/color][/b]append [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"LWPOLYLINE"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 100 [color=#2f4f4f]"AcDbEntity"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 100 [color=#2f4f4f]"AcDbPolyline"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 90 [b][color=BLUE]([/color][/b]length lst[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 70 cls[b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]mapcar [b][color=GREEN]([/color][/b]function [b][color=BLUE]([/color][/b]lambda [b][color=RED]([/color][/b]p[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cons 10 p[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] lst[b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] Quote
Tharwat Posted September 17, 2016 Posted September 17, 2016 @Grrr, copy and paste the following codes into you Vlide Console and when codes ask you for values just hit ENTER: (if (setq d (getreal "\nSpecify offset distance: ") p (getpoint "\nSpecify first point for the line: ") pl (list p) ) (alert "passed ...")) After that check the value for each variable (d p pl). What will you find out? Quote
Grrr Posted September 17, 2016 Posted September 17, 2016 @Grrr, copy and paste the following codes into you Vlide Console and when codes ask you for values just hit ENTER: (if (setq d (getreal "\nSpecify offset distance: ") p (getpoint "\nSpecify first point for the line: ") pl (list p) ) (alert "passed ...")) After that check the value for each variable (d p pl). What will you find out? It added the nil symbol to the 'pl' list, and evaluated the if expression as T... so I should've wrote it like this: (if (setq d (getreal "\nSpecify offset distance: ") p (getpoint "\nSpecify first point for the line: ") ) (progn (setq pl (list p)) (alert "passed ...") ) ) Thank you for the catch... Unfortunately I have alot free time to write codes and read the forums, but I don't have ACAD on that PC I'm working, so no debugging nor consoles. Atleast I'm happy that you are helping and I really appreciate it! Quote
Tharwat Posted September 17, 2016 Posted September 17, 2016 That should work for the last expression ONLY. As in your example, hit enter for the first input and after that specify a point when codes ask for that, then you'd have the same result as if you are entering values for the two inputs. eg: (if (setq d (getreal "\nSpecify offset distance: ") [color="red"];; Hit enter for this expression [/color] p (getpoint "\nSpecify first point for the line: ") [color="blue"];; specify a point[/color] ) (progn (setq pl (list p)) (alert "passed ...") [color="magenta"];; this should be altered for sure although variable 'd' is equal to NIL [/color] ) ) Quote
Grrr Posted September 17, 2016 Posted September 17, 2016 That should work for the last expression ONLY. As in your example, hit enter for the first input and after that specify a point when codes ask for that, then you'd have the same result as if you are entering values for the two inputs. Damn... I thought I did something clever by skipping some (and) function, but you proved me wrong, thanks once again! Quote
Tharwat Posted September 17, 2016 Posted September 17, 2016 You are welcome. As a conclusion: Just be aware when you add more than one expression with setq, only the last expression would return the value. I am just trying to help here and not trying to pick up mistakes - Happy coding. Quote
heng7653 Posted September 19, 2016 Author Posted September 19, 2016 (edited) Hi @Tharwat Thanks for the reply and help. this is what i want, but i need one side offset only (maybe i have to click mouse for offset direction). How to modify the LISP? Thank you very much. Edited September 19, 2016 by heng7653 Quote
Tharwat Posted September 19, 2016 Posted September 19, 2016 Which side you would like to offset the line to? Quote
BIGAL Posted September 19, 2016 Posted September 19, 2016 A simple method for single line using code above. ;(mapcar '(lambda (d) (vla-offset vla d)) (list off (- off))) ; two lines (vla-offset vla off) ; one side only note -ve off value will go to right +ve to left Quote
Tharwat Posted September 19, 2016 Posted September 19, 2016 A simple method for single line using code above. @BIGAL, I think I know how to modify MY codes so if you have any COMPLETE codes just post them to OP and please don't modify mine in that way. Quote
heng7653 Posted September 20, 2016 Author Posted September 20, 2016 @tharwat not fix which side because not same side every time, so hope can select side as usual offset like normal, just no need to select object. Quote
Tharwat Posted September 20, 2016 Posted September 20, 2016 @tharwat not fix which side because not same side every time, so hope can select side as usual offset like normal, just no need to select object. Try this: (defun c:test (/ off pt1 pt2 pt3 ang) ;; Tharwat - 20.Sep.2016 ;; (if (setq off (getdist "\nSpecify offset distance :")) (while (and (setq pt1 (getpoint "\n1st point :")) (setq pt2 (getpoint "\n2nd point :" pt1)) (setq pt3 (getpoint "\nSpecify offset side :")) (setq ang (angle pt1 pt2)) ) (setq ang (if (minusp (sin (- ang (angle pt2 pt3)))) (+ ang (* pi 0.5)) (- ang (* pi 0.5)) ) ) (entmakex (list '(0 . "LINE") (cons 10 (trans (polar pt1 ang off) 1 0)) (cons 11 (trans (polar pt2 ang off) 1 0))))) ) (princ) ) Quote
heng7653 Posted September 20, 2016 Author Posted September 20, 2016 It worked. Thank you very much Tharwat. Quote
Tharwat Posted September 20, 2016 Posted September 20, 2016 It worked. Thank you very much Tharwat. You are welcome. Quote
alanjt Posted September 26, 2016 Posted September 26, 2016 Try this: (defun c:test (/ off pt1 pt2 pt3 ang) ;; Tharwat - 20.Sep.2016 ;; (if (setq off (getdist "\nSpecify offset distance :")) (while (and (setq pt1 (getpoint "\n1st point :")) (setq pt2 (getpoint "\n2nd point :" pt1)) (setq pt3 (getpoint "\nSpecify offset side :")) (setq ang (angle pt1 pt2)) ) (setq ang (if (minusp (sin (- ang (angle pt2 pt3)))) (+ ang (* pi 0.5)) (- ang (* pi 0.5)) ) ) (entmakex (list '(0 . "LINE") (cons 10 (trans (polar pt1 ang off) 1 0)) (cons 11 (trans (polar pt2 ang off) 1 0))))) ) (princ) ) Consider adding the following line of code before prompting for offset side point. (not (grdraw (getpoint) (getpoint) 7 -1)) Quote
Tharwat Posted September 27, 2016 Posted September 27, 2016 Consider adding the following line of code before prompting for offset side point. (not (grdraw (getpoint) (getpoint) 7 -1)) I agree with you if we have more than two points to pick but in this case there are only two points and that is already handled by the getpoint function. Nice to see you contributing again Alanjt. Quote
alanjt Posted September 27, 2016 Posted September 27, 2016 I agree with you if we have more than two points to pick but in this case there are only two points and that is already handled by the getpoint function. Nice to see you contributing again Alanjt. You are picking more than two points. You pick the two points to draw the line, then you are blindly picking a third point for the offsetting side. grdraw'ing the line before picking the offset side would remove the blind point selection. Nice to be seen. I'll pop in from time-to-time. Quote
heng7653 Posted June 4, 2018 Author Posted June 4, 2018 hi anyone know how to edit this code? as I want it show previous offset distance every time command start. (defun c:aa (/ off pt1 pt2 pt3 ang) ;; Tharwat - 20.Sep.2016 ;; (if (setq off (getdist "\nSpecify offset distance :")) (while (and (setq pt1 (getpoint "\n1st point :")) (setq pt2 (getpoint "\n2nd point :" pt1)) (setq pt3 (getpoint "\nSpecify offset side :")) (setq ang (angle pt1 pt2)) ) (setq ang (if (minusp (sin (- ang (angle pt2 pt3)))) (+ ang (* pi 0.5)) (- ang (* pi 0.5)) ) ) (entmakex (list '(0 . "LINE") (cons 10 (trans (polar pt1 ang off) 1 0)) (cons 11 (trans (polar pt2 ang off) 1 0))))) ) (princ) ) 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.