Jump to content

Adding environment path variable in lisp


Recommended Posts

Posted

Hello everybody,

I would like to work with a colleague via one drive and I have a lisp to redefine all block from different folders.

The problem that I have is, using One Drive, the path of my blocks is not the same for both.

Is it possible to add, in lisp, an environment variable to avoid this problem?

Part of my lisp:

(setq G:LISTDIR (list "C:\Users\username\OneDrive\.....\01_Profiles"

"C:\Users\username\OneDrive\...\02_Gaskets"

)

For example on my computer I would add the environment variable : username = francine2013

Posted (edited)
(strcat  (getenv "userprofile") "\\OneDrive\\.....\\01_Profiles")

 

--edit

in windows explorer its %USERPROFILE%

Edited by mhupp
  • Like 1
Posted

Thank a lot

It works fine in the first lisp but in another one where I search for blocks I get an error message  : error: bad argument type: stringp (STRCAT (GETENV "userprofile") "\\OneDrive....

Part of this lisp: 

(defun findblock ( dwg )
    (vl-some '(lambda ( p ) (findfile (strcat p dwg)))
       '(   ""
(strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\")
(strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\")

)))

Posted
16 minutes ago, francine2013 said:

Thank a lot

It works fine in the first lisp but in another one where I search for blocks I get an error message  : error: bad argument type: stringp (STRCAT (GETENV "userprofile") "\\OneDrive....

Part of this lisp: 

  '(   "" (strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\")
(strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\")

)))

The " quote doesn't evaluate list items like the list (AutoLISP) function does, you need to use list instead.

Lee Mac explains The Apostrophe and the Quote Function pretty well.

  • Like 2
Posted

Thanks

A bit complicated for my lisp notions, but I'll try 🙂

  • Like 1
Posted

I've found a way to make it work but it's more by luck and your guidance. Thanks again.

 

Part of this lisp: 

(defun findblock ( dwg )
    (vl-some '(lambda ( p ) (findfile (strcat p dwg)))
       (list
(strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\")
(strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\")

)))

  • Like 1
Posted

in laymen terms what tombu is saying

 

'((strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\") (strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\"))

with the ' it only outputs what is in the list
strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\"
strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\"


(list (strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\") (strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\"))

where list runs the starcat and getenv funtions to output
C:\\Users\\username\\OneDrive\\....\\01_Profiles\\
C:\\Users\\username\\OneDrive\\....\\02_Gaskets\\

 

  • Like 2
Posted
7 minutes ago, francine2013 said:

Thanks

A bit complicated for my lisp notions, but I'll try 🙂

 

Anything after a '( is a fixed list, CAD will take it as it is, anything after (list and CAD will try to calculate this list

 

For example

'( 1 2 3 4 5) is a list, 1 2 3 4 5

'(1 (+ 8 9) 3 4 5) is also a list 1 (+ 8 9) 3 4 5, and will probably be an error since it thinks the + is text, and wants it as "+"

 

(list 1 2 3 4 5) is also a list 1 2 3 4 5

(list 1 (+ 8 9) 3 4 5 is a list 1 17 3 4 5, noting that the 8+9 has been calculated now

 

That's the basic difference

Remember to define any lists within your list as a list too

 

In your case

'(
    ""
   (strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\")
   (strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\")
)

 

this list is seen as all text items, errors for example (strcat CAD wants that to be a text string "(strcat....)

Make it up as

(list
  ""
 (strcat (getenv "userprofile") "\\OneDrive\\....\\01_Profiles\\")
 (strcat (getenv "userprofile") "\\OneDrive\\....\\02_Gaskets\\")
)

 

and it should work it all out. Lee Macs description is better than mine

 

 

  • Like 3
  • Agree 1

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