vernonlee Posted November 11, 2015 Share Posted November 11, 2015 (edited) Could some help me with a LISP. Basically a LISP to 1) obtain the Coordinates of a user input point & 2) the zoom magnification of the same point and 3) save the values to an existing file & override it: ZoomToView.scr This is the individual command I run to obtain the values for item 1 & 2 Command: [b]ID[/b] Specify point: X = [color=red][b]540.4345[/b][/color] Y = [b][color=red]166.2423[/color][/b] Z = [b][color=red]0.0000[/color][/b] Command: [b]Z[/b] ZOOM Specify corner of window, enter a scale factor (nX or nXP), or [All/Center/Dynamic/Extents/Previous/Scale/Window/Object] <real time>: C Specify center point: Enter magnification or height <[color=blue][b]112.1034[/b][/color]>: *Cancel* Then transfer the values to an existing script file, save & override the existing file: ZoomToView.scr This is what is inside ZoomToView.scr Zoom C [color=red][b]540.4345[/b][/color],[b][color=red]166.2423[/color][/b],[b][color=red]0.0000[/color][/b] [color=blue][b]112.1034[/b][/color] The location of the script where i save to is as follows:- D:\Office\AutoCAD\Scripts\ZoomToView.scr Thanks Edited November 11, 2015 by vernonlee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 11, 2015 Share Posted November 11, 2015 Use getpoint to obtain the point and query the VIEWSIZE system variable for the height. Quote Link to comment Share on other sites More sharing options...
vernonlee Posted November 11, 2015 Author Share Posted November 11, 2015 Use getpoint to obtain the point and query the VIEWSIZE system variable for the height. Thanks Lee for the advise. Alas, I do not understand LISP enough to write it out from scratch. Do appreciate if someone can help me out on this. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 11, 2015 Share Posted November 11, 2015 This one is pretty simple so you should at least be able to give it a try with some guidance - The basic functions you will need are as follows: defun if getpoint getvar open progn write-line strcat rtos close princ I would first suggest reading the developer documentation for each of the above functions if you don't already know what they do. The pseudo-code for the program (that is, the basic operations it needs to perform) would be something like: [color=blue]def[/color]i[color=blue]n[/color]e function [color=blue]if[/color] user [color=blue]get[/color]s [color=blue]point [/color] then [color=blue]if [/color]the target .scr file can be [color=blue]open[/color]ed for [color=darkred]w[/color]riting then [color=blue]progn[/color] [color=blue]write-line[/color] [color=darkred]"_.zoom"[/color] to file [color=blue]write-line[/color][color=darkred] "_C"[/color] to file [color=blue]write-line[/color] [[color=blue]strcat [/color][[color=blue]rtos [/color]x-coord] [[color=blue]rtos [/color]y-coord] [[color=blue]rtos [/color]z-coord]] to file [color=blue]write-line[/color] [[color=blue]rtos [/color][[color=blue]getvar [/color][color=darkred]viewsize[/color]]] to file [color=blue]close [/color]file else [color=blue]princ [/color]file could not be opened for writing [color=blue]princ[/color] Quote Link to comment Share on other sites More sharing options...
vernonlee Posted November 12, 2015 Author Share Posted November 12, 2015 Thanks Lee. Will give it a shot. Hope you can continue to guide me along the way. For a start, any recommended link for the developer documentation I can read up on those functions you mention. Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 12, 2015 Share Posted November 12, 2015 pretty simple HELP and find developers help which is say the same as this link http://docs.autodesk.com/ACDMAC/2013/ENU/PDFs/acdmac_2013_autolisp_reference_guide.pdf Quote Link to comment Share on other sites More sharing options...
broncos15 Posted November 12, 2015 Share Posted November 12, 2015 My suggestion is that there isn't really a need to create a script file. Instead, it would be easier to just create two separate lisp routines, one that stores the zoom information and one that zooms to the stored information. It is fairly easy using the commands Lee gave, you'll just need to make sure that your variables you store the zoom information in are global, not local. This way you won't have to mess with an extra file, but it will function the same way, it will just be quicker and more efficient. Let me know if you need any more help/suggestions because I'm glad to help. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 12, 2015 Share Posted November 12, 2015 boncos15 I agree with Lee with no disrespect to Vernonlee he has 494 posts its about time to start learning rather than just take the freebies. Lots like me are here to help not just write code. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted November 12, 2015 Share Posted November 12, 2015 BigAl, I agree, and I didn't know he had that many posts. By the way your posts have been really helpful to me for learning lisp. Quote Link to comment Share on other sites More sharing options...
vernonlee Posted November 13, 2015 Author Share Posted November 13, 2015 pretty simple HELP and find developers help which is say the same as this link http://docs.autodesk.com/ACDMAC/2013/ENU/PDFs/acdmac_2013_autolisp_reference_guide.pdf Thanks BIGAL. Quote Link to comment Share on other sites More sharing options...
vernonlee Posted November 13, 2015 Author Share Posted November 13, 2015 My suggestion is that there isn't really a need to create a script file. Instead, it would be easier to just create two separate lisp routines, one that stores the zoom information and one that zooms to the stored information. It is fairly easy using the commands Lee gave, you'll just need to make sure that your variables you store the zoom information in are global, not local. This way you won't have to mess with an extra file, but it will function the same way, it will just be quicker and more efficient. Let me know if you need any more help/suggestions because I'm glad to help. Hi. The reason why i needed to "export" this values is I need to zoom to the same location for multiple drawings. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted November 13, 2015 Share Posted November 13, 2015 Hi. The reason why i needed to "export" this values is I need to zoom to the same location for multiple drawings.If your variables are global, they will be remembered between drawings. That way, you can zoom to the same location in as many drawings as you want. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 13, 2015 Share Posted November 13, 2015 If your variables are global, they will be remembered between drawings Having a problem with this do you know a secret ? Global variables as per help is about running within one dwg not across multiples outside of say multiple defuns running in a session, the code by Lee hints at this by writing to file. Another alternative is to write say a string to the registery. vl-registry-write vl-registry-read Quote Link to comment Share on other sites More sharing options...
vernonlee Posted November 13, 2015 Author Share Posted November 13, 2015 If your variables are global, they will be remembered between drawings. That way, you can zoom to the same location in as many drawings as you want. Could you elobrate? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 13, 2015 Share Posted November 13, 2015 If your variables are global, they will be remembered between drawings. That way, you can zoom to the same location in as many drawings as you want. Not true I'm afraid: all symbols in AutoLISP are defined within the document namespace by default and therefore cannot be accessed outside of this namespace (unless you use vl-bb-set/vl-bb-ref to define symbols within the blackboard namespace which is a document-independent namespace and may therefore be accessed from any drawing). Another alternative is to use vl-propagate to propagate a variable across all document namespaces. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 13, 2015 Share Posted November 13, 2015 Thanks Lee Quote Link to comment Share on other sites More sharing options...
broncos15 Posted November 15, 2015 Share Posted November 15, 2015 Lee, I thought setenv and getenv could be used to store variables in the registry (just need to be careful to not use the same variables and to not overuse it because it can bloat it). I haven't used them yet (haven't seen the need) but I remember reading about it when I was first learning lisp, did I misunderstand it? Also can't vl-propagate be used to "store" the variable so that it can be used for all open drawings in the current session? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 15, 2015 Share Posted November 15, 2015 Lee, I thought setenv and getenv could be used to store variables in the registry (just need to be careful to not use the same variables and to not overuse it because it can bloat it). I haven't used them yet (haven't seen the need) but I remember reading about it when I was first learning lisp, did I misunderstand it? Also can't vl-propagate be used to "store" the variable so that it can be used for all open drawings in the current session? Indeed, getenv & setenv can be used to read & write a string value (REG_SZ / REG_EXPAND_SZ) to a specific branch of the registry [specifically the location given by: (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\FixedProfile\\General") ], however, these are not global variables as you stated in your post. Writing such values to the registry is essentially the same as reading & writing data to a text file (which may in fact be a preferred option due to the ease of removal - this is the route I follow with the majority of my larger applications). As noted in my post above, vl-propagate is also an option, however, this will cause a global variable to persist only during the current instance of the application. 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.