jonthan313 Posted July 25, 2013 Share Posted July 25, 2013 I am able to plot to PNG with a lisp, but during the process I have to drag a window of the rectangle of what I am trying to plot within. (Doing screenshots for work). I want to be able to type in a command --> select polyline --> plot within the vertices. Is there a way to get the 2 (two) vertex points, the upper left and lower right, save the coordinates and put them back in during the plot lisp? Thank you Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 25, 2013 Share Posted July 25, 2013 Welcome to CADTutor jonthan The following example will prompt the user to select an LWPolyline object and will return the lower-left and upper-right coordinates of the vertex extents (for a rectangular polyline, this corresponds to the lower-left & upper-right corner vertices): ([color=BLUE]defun[/color] getwindowpoints ( [color=BLUE]/[/color] ent ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Polyline: "[/color]))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] ent)) ([color=BLUE]if[/color] ([color=BLUE]/=[/color] [color=MAROON]"LWPOLYLINE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ent)))) ([color=BLUE]princ[/color] [color=MAROON]"\nPlease select an LWPolyline."[/color]) ) ) ) ) ) ([color=BLUE]if[/color] ent ( ([color=BLUE]lambda[/color] ( lst ) ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] x lst))) '([color=BLUE]min[/color] [color=BLUE]max[/color]))) ([color=BLUE]mapcar[/color] '[color=BLUE]cdr[/color] ([color=BLUE]vl-remove-if-not[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]=[/color] 10 ([color=BLUE]car[/color] x))) ([color=BLUE]entget[/color] ent))) ) ) ) You could call the above function from your program and assign the points returned by the function to the variables in your program storing the plot window points. Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 25, 2013 Author Share Posted July 25, 2013 Thank you for the fast response. I will give it a try and let you know if it worked. Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 25, 2013 Author Share Posted July 25, 2013 So it gave me the right points, but how can I assign those coordinates to variables? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 25, 2013 Share Posted July 25, 2013 So it gave me the right points, but how can I assign those coordinates to variables? Assign the variables the points returned by the function, e.g.: (if (setq lst (getwindowpoints)) (setq pt1 (car lst) pt2 (cadr lst) ) ) Or: (mapcar 'set '(pt1 pt2) (getwindowpoints)) Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 25, 2013 Author Share Posted July 25, 2013 Please bare with me since I am new at this and still learning how to write Lisp programs, but I dont know where to insert the code where you assign the variables. Can you please help me out? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 25, 2013 Share Posted July 25, 2013 You will need to post your existing code. Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 25, 2013 Author Share Posted July 25, 2013 Sorry for the long code still working on how to properly code, it's just more of a script than lisp. I want to get rid of the two pauses and automatically pick the points from your code. I need help implementing your code into mine. (defun C:HMI () (command "-plot" ;Detailed plot configuration? "Yes" ;Enter Layout Name "Model" ;Enter an output device name "PublishToWeb PNG.pc3" ;Enter Paper Size (User Defined) "HMI" ;Enter Drawing Orientation "L" ;Plot Upside Down? "No" ;Enter Plot Area "Window" ;Pause the lisp for users input of points pause pause ;Enter Plot Scale "Fit" ;Enter plot offset "center" ;Plot with Style "yes" ;Enter plot style table name (none) "." ;Plot with lineweights? "yes" ;Enter Shade Plot Settings "As Displayed" ;Creating plot file and saving pause ;Save Changes to page setup "no" ;Proceed with plot "yes") ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 25, 2013 Share Posted July 25, 2013 Try the following: (defun c:hmi ( / lst ) (if (setq lst (getwindowpoints)) (command "_.-plot" "_Yes" ; Detailed plot configuration? "Model" ; Enter Layout Name "PublishToWeb PNG.pc3" ; Enter an output device name "HMI" ; Enter Paper Size (User Defined) "_L" ; Enter Drawing Orientation "_N" ; Plot Upside Down? "_W" ; Enter Plot Area "_non" (car lst) "_non" (cadr lst) "_F" ; Enter Plot Scale "_C" ; Enter plot offset "_Y" ; Plot with Style "." ; Enter plot style table name (none) "_Y" ; Plot with lineweights? "As Displayed" ; Enter Shade Plot Settings "\\" ; Creating plot file and saving "_N" ; Save Changes to page setup "_Y" ; Proceed with plot ) ) (princ) ) (defun getwindowpoints ( / ent ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect Polyline: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (= 'ename (type ent)) (if (/= "LWPOLYLINE" (cdr (assoc 0 (entget ent)))) (princ "\nPlease select an LWPolyline.") ) ) ) ) ) (if ent ( (lambda ( lst ) (mapcar '(lambda ( x ) (apply 'mapcar (cons x lst))) '(min max))) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent))) ) ) ) (princ) Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 26, 2013 Author Share Posted July 26, 2013 Thank you so much Lee Mac, you are the best! Maybe I am asking too much, but would it be possible to select multiple rectangles polylines and save each of them individually with different names? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 26, 2013 Share Posted July 26, 2013 I'm not sure what naming convention you are looking to use, but try the following: (defun c:hmi ( / i s ) (if (setq s (ssget '((0 . "LWPOLYLINE")))) (repeat (setq i (sslength s)) (apply 'plotwindow (windowpoints (ssname s (setq i (1- i))))) ) ) (princ) ) (defun plotwindow ( p q ) (command "_.-plot" "_Yes" ; Detailed plot configuration? "Model" ; Enter Layout Name "PublishToWeb PNG.pc3" ; Enter an output device name "HMI" ; Enter Paper Size (User Defined) "_L" ; Enter Drawing Orientation "_N" ; Plot Upside Down? "_W" ; Enter Plot Area "_non" p "_non" q "_F" ; Enter Plot Scale "_C" ; Enter plot offset "_Y" ; Plot with Style "." ; Enter plot style table name (none) "_Y" ; Plot with lineweights? "As Displayed" ; Enter Shade Plot Settings "\\" ; Creating plot file and saving "_N" ; Save Changes to page setup "_Y" ; Proceed with plot ) ) (defun windowpoints ( ent ) ( (lambda ( lst ) (mapcar '(lambda ( x ) (apply 'mapcar (cons x lst))) '(min max))) (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent))) ) ) (princ) Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 26, 2013 Author Share Posted July 26, 2013 I tried your code and I selected two polylines, but when one rectangle polyline plots, a PNG is created, but then it's overwritten by the next polyline plot. It would be nice if it would be able to create two different PNG with _A, _B, _C...etc at the end or some other naming convention that differs the files. Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 26, 2013 Author Share Posted July 26, 2013 Any luck with the code Mr. Lee Mac? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 26, 2013 Share Posted July 26, 2013 Any luck with the code Mr. Lee Mac? Please understand that my time participating on this forum is voluntary; if you require a more prompt response, we can discuss an hourly rate. Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 26, 2013 Author Share Posted July 26, 2013 I wasnt trying to be rude ... I appreciate all of the help. Thank you. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 27, 2013 Share Posted July 27, 2013 Try this: ([color=BLUE]defun[/color] c:hmi ( [color=BLUE]/[/color] f i s ) ([color=BLUE]setq[/color] f ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) ([color=BLUE]vl-filename-base[/color] ([color=BLUE]getvar[/color] 'dwgname)))) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"LWPOLYLINE"[/color])))) ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s)) ([color=BLUE]apply[/color] 'plotwindow ([color=BLUE]cons[/color] f (windowpoints ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)))))) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] plotwindow ( f p q ) ([color=BLUE]command[/color] [color=MAROON]"_.-plot"[/color] [color=MAROON]"_Yes"[/color] [color=GREEN]; Detailed plot configuration?[/color] [color=MAROON]"Model"[/color] [color=GREEN]; Enter Layout Name[/color] [color=MAROON]"PublishToWeb PNG.pc3"[/color] [color=GREEN]; Enter an output device name[/color] [color=MAROON]"HMI"[/color] [color=GREEN]; Enter Paper Size (User Defined)[/color] [color=MAROON]"_L"[/color] [color=GREEN]; Enter Drawing Orientation[/color] [color=MAROON]"_N"[/color] [color=GREEN]; Plot Upside Down?[/color] [color=MAROON]"_W"[/color] [color=GREEN]; Enter Plot Area[/color] [color=MAROON]"_non"[/color] p [color=MAROON]"_non"[/color] q [color=MAROON]"_F"[/color] [color=GREEN]; Enter Plot Scale[/color] [color=MAROON]"_C"[/color] [color=GREEN]; Enter plot offset[/color] [color=MAROON]"_Y"[/color] [color=GREEN]; Plot with Style[/color] [color=MAROON]"."[/color] [color=GREEN]; Enter plot style table name (none)[/color] [color=MAROON]"_Y"[/color] [color=GREEN]; Plot with lineweights?[/color] [color=MAROON]"As Displayed"[/color] [color=GREEN]; Enter Shade Plot Settings[/color] (uniquefilename f [color=MAROON]".png"[/color]) [color=MAROON]"_N"[/color] [color=GREEN]; Save Changes to page setup[/color] [color=MAROON]"_Y"[/color] [color=GREEN]; Proceed with plot[/color] ) ) ([color=BLUE]defun[/color] uniquefilename ( pth ext [color=BLUE]/[/color] fnm tmp ) ([color=BLUE]if[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] fnm ([color=BLUE]strcat[/color] pth ext))) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] tmp 1) ([color=BLUE]while[/color] ([color=BLUE]findfile[/color] ([color=BLUE]setq[/color] fnm ([color=BLUE]strcat[/color] pth [color=MAROON]"("[/color] ([color=BLUE]itoa[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]1+[/color] tmp))) [color=MAROON]")"[/color] ext)))) ) ) fnm ) ([color=BLUE]defun[/color] windowpoints ( ent ) ( ([color=BLUE]lambda[/color] ( lst ) ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] x lst))) '([color=BLUE]min[/color] [color=BLUE]max[/color]))) ([color=BLUE]mapcar[/color] '[color=BLUE]cdr[/color] ([color=BLUE]vl-remove-if-not[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]=[/color] 10 ([color=BLUE]car[/color] x))) ([color=BLUE]entget[/color] ent))) ) ) ([color=BLUE]princ[/color]) Quote Link to comment Share on other sites More sharing options...
jonthan313 Posted July 27, 2013 Author Share Posted July 27, 2013 I really appreciate all of the help Mr. Lee Mac! I know you take time to do this for a lot of people and expect nothing in return, but if theres anything you need please let me know. Thank you so much!!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 27, 2013 Share Posted July 27, 2013 You're welcome jonthan - thank you for appreciating the time I have donated. Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 13, 2015 Share Posted July 13, 2015 (edited) Hello I appreciate of sharing knowledge I tried to change your code to pick rectangle and plot rectangle and anything in rectangle with fit to paper what can i do?? Edited July 16, 2015 by hosyn 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.