Jump to content

Recommended Posts

Posted

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.

Posted

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 ?

Posted

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).

Posted
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))

Posted

Then you can use read function to read the string to list of coordinates .

Posted

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?

Posted

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"))

Posted

Sweet! Wonderful! Thank you! Works like a charm!

Posted
Sweet! Wonderful! Thank you! Works like a charm!

 

Excellent . You're very welcome .

Posted

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)

Posted
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.

Posted
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).

Posted
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.

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...