xikes Posted July 16, 2013 Posted July 16, 2013 Hello. I'm trying to come up with a simple one-line lisp routine for writing the information stored in lastpoint variable to my own defined environment variable. I tried this and it didn't work: (setenv "xReadout_001" (getvar "lastpoint")) it gave me an error "error: bad argument type: stringp" Can someone please help me? Thanks. Quote
Tharwat Posted July 16, 2013 Posted July 16, 2013 It throw the error because the value must be string and not list of points or so . What is the goal of storing the last point system variable to the environment ? Quote
xikes Posted July 16, 2013 Author Posted July 16, 2013 Hmm. Is it possible to convert it to string (in the same line) and store it then? How do I modify it? How does one convert list to string? Sorry. I'm a newbie at Lisp. I know how to do this on LT version with diesel, unfortunately full AutoCad doesn't have setenv command outside lisp (as LT version did). As for the goal, I am writing an external Java application, that will read the stored environment variable and use it for later purposes. And yes, I know VBA exists. I want get this working my way. As for why it need to be one-liner: the entire routine will be send from Java as well (via DDE). Quote
Tharwat Posted July 16, 2013 Posted July 16, 2013 Hmm. Is it possible to convert it to string (in the same line) and store it then? How do I modify it? How does one convert list to string? Check this out . e.g. (vl-princ-to-string '(1.0 2.0 3.0)) Quote
Tharwat Posted July 16, 2013 Posted July 16, 2013 Then you can use read function to read the string to list of coordinates . Quote
xikes Posted July 16, 2013 Author Posted July 16, 2013 Yes that's it. Getting closer. Still now this happens: (vl-princ-to-string '(getvar "lastpoint")) "(GETVAR lastpoint)" As I see I somehow need to tell autocad to evaluate the getvar command first. Is there a way to make some actions evaluate before others? Quote
Tharwat Posted July 16, 2013 Posted July 16, 2013 You have use the quote symbol which would not evaluate the feeded value , try it as the following . (setenv "xReadout_001" (vl-princ-to-string (getvar 'lastpoint))) (read (getenv "xReadout_001")) Quote
xikes Posted July 16, 2013 Author Posted July 16, 2013 Sweet! Wonderful! Thank you! Works like a charm! Quote
Tharwat Posted July 16, 2013 Posted July 16, 2013 Sweet! Wonderful! Thank you! Works like a charm! Excellent . You're very welcome . Quote
Lee Mac Posted July 16, 2013 Posted July 16, 2013 The solution utilising the vl-princ-to-string function is most likely the simplest method, however, be aware that the coordinate values will be expressed to a limited precision (usually ~4dp), irregardless of your LUPREC system variable setting. To retain full precision, I would suggest perhaps: ([color=BLUE]setq[/color] dim ([color=BLUE]getvar[/color] 'dimzin)) ([color=BLUE]setvar[/color] 'dimzin [color=GREEN];; Suppress trailing decimal zeros[/color] ([color=BLUE]setenv[/color] [color=MAROON]"xReadout_001"[/color] ([color=BLUE]vl-princ-to-string[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]rtos[/color] x 2 16)) ([color=BLUE]getvar[/color] 'lastpoint)))) ([color=BLUE]setvar[/color] 'dimzin dim) Quote
xikes Posted July 16, 2013 Author Posted July 16, 2013 The solution utilising the vl-princ-to-string function is most likely the simplest method, however, be aware that the coordinate values will be expressed to a limited precision (usually ~4dp), irregardless of your LUPREC system variable setting. To retain full precision, I would suggest perhaps: ([color=BLUE]setq[/color] dim ([color=BLUE]getvar[/color] 'dimzin)) ([color=BLUE]setvar[/color] 'dimzin [color=GREEN];; Suppress trailing decimal zeros[/color] ([color=BLUE]setenv[/color] [color=MAROON]"xReadout_001"[/color] ([color=BLUE]vl-princ-to-string[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]rtos[/color] x 2 16)) ([color=BLUE]getvar[/color] 'lastpoint)))) ([color=BLUE]setvar[/color] 'dimzin dim) Brilliant! Thank you very much! +__+ This is even better. Quote
MSasu Posted July 17, 2013 Posted July 17, 2013 I am writing an external Java application, that will read the stored environment variable and use it for later purposes. I may missing something, but the key/values saved by SETENV function were not truly Windows environment variables, since were saved into Registry for current AutoCAD version and user. So, you cannot access them from other languages or even other AutoCAD installations (apart from hard-coding their path). Quote
xikes Posted July 17, 2013 Author Posted July 17, 2013 I may missing something, but the key/values saved by SETENV function were not truly Windows environment variables, since were saved into Registry for current AutoCAD version and user. So, you cannot access them from other languages or even other AutoCAD installations (apart from hard-coding their path). Even if tis hard-coding.. Values set by SETENV are stored in the windows registry (under HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R19.0\ACAD-B001:409\FixedProfile\General), which is readable from other applications. Anyway, this works. I was only having trouble writing lastpoint to setenv via lisp. Now that this is resolved, it works, my Java application can grab those coordinates at will. Quote
MSasu Posted July 17, 2013 Posted July 17, 2013 For sure you can access the Registry from other languages. The point that I was trying to make is that you need to adjust the Java code (or other technology, for that matter) for each version of AutoCAD. 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.