vlisp for adding to support file search path

vlisp for adding to support file search path

Anonymous
Not applicable
2,886 Views
16 Replies
Message 1 of 17

vlisp for adding to support file search path

Anonymous
Not applicable

This adds the folder C:\TEMP1 to my support file search path (SFSP). However if I later use the same code to add a different folder such as C:\TEMP2, the first folder I added gets removed. How do I append to my current folders in SFSP  and not replace any folder previously added.

 

;Load the VLisp support
(vl-load-com)
;Store a reference to the Application Object
(setq acadObject (vlax-get-acad-object))
;Store a reference to the Preferences Object
(setq prefsObject (vlax-get-property acadObject 'Preferences))
;Store a reference to the Files Object
(setq tabnameObject (vlax-get-property prefsObject 'Files))
;Get the Support Path
(setq thePath (vlax-get-property tabnameObject 'SupportPath))
;add your new path to the existing path variable
(setq thePath (strcat thePath ";" "C:\\TEMP1"))
(vlax-put-property tabnameObject 'SupportPath thePath)

2,887 Views
16 Replies
Replies (16)
Message 2 of 17

redtransitconsultants
Collaborator
Collaborator

This is what I use for add in support paths... just pay attention to the last lines as those are where you add in your paths. They need to be numbered 0, 1, 2, ... etc. Blue is your path and red is the number... (addSupportPath "C:\\My\\Path1" 0)

 

(defun addSupportPath (dir pos / tmp c lst)
   (setq tmp ""
         c -1
   )
   (if
      (not
        (member (strcase dir)
         (setq lst 
           (mapcar 'strcase 
            (parse (getenv "ACAD") ";")
           )
         );setq
        );member
      );not 
   (progn
      (if (not pos)
         (setq tmp (strcat (getenv "ACAD") ";" dir))
         (mapcar '(lambda (x)
         (setq tmp (if (= (setq c (1+ c)) pos)
               (strcat tmp ";" dir ";" x)
               (strcat tmp ";" x)
              )
         )
         )
      lst
      )
   )
   (setenv "ACAD" tmp)
   )
   )
(princ)
);end defun

(defun parse (str delim / lst pos)
   (setq pos (vl-string-search delim str))
   (while pos
      (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))
         pos (vl-string-search delim str)
      )
   )
   (if (> (strlen str) 0)
      (setq lst (cons str lst))
   )
      (reverse lst)
);end defun



(addSupportPath "C:\\My\\Path1" 0)
(addSupportPath "C:\\My\\Path2" 1)
(addSupportPath "C:\\My\\Path3" 2)

 

Steve Hill,Civil Designer / .NET Developer / AutoCAD and AutoCAD Civil 3D Certified Professional
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

http://redtransitconsultants.com/
Autodesk Exchange Store
Twitter | LinkedIn | YouTube

Message 3 of 17

Anonymous
Not applicable

Thanks for the input. Still not quite what I am looking for. I could not get the paths to add below what I already have (have 10 paths now which includes the defaults), only on top using 0,1, etc. Also, putting added paths on top causes AutoCAD to become unstable and it will crash when trying to save workspace. I want to use a seperate support path lisp with each loader of the menus (located in different folders) that will "append" the existing list and add to bottom of list, and as a result, each seperately added path will need to be added last to the SFSP list no matter how many existing paths are listed. I don't want to globally add all of the paths or load the menus. I'd also rather not control with profiles. My approach may not be the best method, or feasible, and perhaps I will need to persue other method for our office CAD staff to choose which menus to load.

0 Likes
Message 4 of 17

hmsilva
Mentor
Mentor

@Anonymous wrote:

This adds the folder C:\TEMP1 to my support file search path (SFSP). However if I later use the same code to add a different folder such as C:\TEMP2, the first folder I added gets removed. How do I append to my current folders in SFSP  and not replace any folder previously added.

 

;Load the VLisp support
(vl-load-com)
;Store a reference to the Application Object
(setq acadObject (vlax-get-acad-object))
;Store a reference to the Preferences Object
(setq prefsObject (vlax-get-property acadObject 'Preferences))
;Store a reference to the Files Object
(setq tabnameObject (vlax-get-property prefsObject 'Files))
;Get the Support Path
(setq thePath (vlax-get-property tabnameObject 'SupportPath))
;add your new path to the existing path variable
(setq thePath (strcat thePath ";" "C:\\TEMP1"))
(vlax-put-property tabnameObject 'SupportPath thePath)


Hi mishman,

 

to add or to remove a path from Support File Search Paths, try this Lee Mac's Add & Remove Support File Search Paths functions.

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 17

redtransitconsultants
Collaborator
Collaborator

@Anonymous wrote:

Also, putting added paths on top causes AutoCAD to become unstable and it will crash when trying to save workspace.


I'm running this for 80 some users and have for quite a while. I haven't seen any unstable issues regarding the order of the search paths.

 

I suppose you could do a count on the number of paths though and have it increment the numbers of where it's placing the paths so they are at the end. You could modify my code to do that pretty easily I think.

 

 

Steve Hill,Civil Designer / .NET Developer / AutoCAD and AutoCAD Civil 3D Certified Professional
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

http://redtransitconsultants.com/
Autodesk Exchange Store
Twitter | LinkedIn | YouTube

0 Likes
Message 6 of 17

Anonymous
Not applicable

You most likely will not experience any stability issues unless your users utilize workspaces. I have experienced that if you have non-default support paths at the top of the list then try to create or save a workspace your session of AutoCAD will crash. I am going to take a look at Lee-Mac's function sand give that a try based on recommendation from hmsilva.

0 Likes
Message 7 of 17

jpCADconsulting
Advocate
Advocate

This one has been working for me for a long while (all glory to Lee MAC!).

 

Puts them at the end of the list.

 

Note: No backslashes if you want to add just the root drive letter.

 

(defun AddSupportPath (dir / Cpath Uname) ;http://lee-mac.com/addremovesupportpaths.html
  (setq Cpath (getenv "ACAD") Uname (getenv "Username") dir (vl-string-subst Uname "%Username%" dir))
  (or (vl-string-search dir Cpath) (setenv "ACAD" (strcat Cpath ";" dir)))
  (princ)
)
(AddSupportPath "R:")
(AddSupportPath "R:\\Slides")
(AddSupportPath "R:\\Fonts")
(AddSupportPath "R:\\Patterns")

paths.png

0 Likes
Message 8 of 17

c3dsolutions
Advocate
Advocate

Hi,

 

After adding the support file paths, though they appear in the list, but AutoCAD/Civil 3D does not recognize them until I open the Options window and click OK. The same problem happens when adding the printer style support paths (PrinterStyleSheetDir) but nobody knows why: (setenv "PrinterStyleSheetDir") Not applying? 

 

Any idea how to force feed the file paths?

0 Likes
Message 9 of 17

john.uhden
Mentor
Mentor

The new paths probably also have to be added to TrustedPaths in the same manner.

John F. Uhden

0 Likes
Message 10 of 17

c3dsolutions
Advocate
Advocate

Sounds good, does not work. 😄

0 Likes
Message 11 of 17

john.uhden
Mentor
Mentor

When I said "in the same manner" I meant generally.

You can't use the same exact code you were provided.

But you can try this function.

You provide it a list of paths, as in

(setq paths (list "C:\\Mystuff" "H:\\Custom" "G:\\Add-Ons"))

Then run the function...

(AddTrusted paths)

Here's the function

(defun AddTrusted (newpaths / Old New)
  (vl-load-com)
  (setq Old (getvar "TrustedPaths") New Old)
  (foreach path newpaths
    (if (vl-file-directory-p path)
      (setq New (strcat New ";" path))
      (alert (strcat "Directory " path " does not exist."))
    )
  )
  (if (/= New Old)(setvar "TrustedPaths" New))
)

It will warn you if any of the paths is not found.

It could be more embellished to check if the path is already trusted, but that's up to you to check existing conditions.

I really don't know if it makes any difference, but I'm not going to experiment on my office PC.

John F. Uhden

0 Likes
Message 12 of 17

c3dsolutions
Advocate
Advocate

John, 

 

Of course, I did not use the same code. I can add the file paths to all lists (trusted paths, working file support paths and printer support file paths) using separate lisps, but the file paths are somehow not recognised until I open the Options window and click Ok. I.e.: I want to plot something after adding the plot style table search file path, but the ctb file is marked as missing. I open the Options window and without changing anything I close with Ok. I go back to plot, and the ctb is there. This is just frustrating.

0 Likes
Message 13 of 17

c3dsolutions
Advocate
Advocate

Just in case I will give a try to your code to see whether it resolves the issue. 

0 Likes
Message 14 of 17

john.uhden
Mentor
Mentor

@c3dsolutions 

I recall that sometimes the changes you make programmatically don't become effective until you restart AutoCAD.

See if that is the case for you.

John F. Uhden

0 Likes
Message 15 of 17

Sea-Haven
Mentor
Mentor

John is on the money a few different things are read on start up and not changed during a session. If you edit a custom mnu you will not see changes till you do a menuload, did this for multiple users only 1 cuix saved on server changes made were seen on next user startup. 

 

Not sure if reinit will help

 

0 Likes
Message 16 of 17

c3dsolutions
Advocate
Advocate

Silly Me!

The solution was to write the file paths in one line:

 

(list path "\\filepath\\numberone\\;\\filepath\\numbertwo")

 

instead of:

(list path "\\filepath\\numberone\\;

\\filepath\\numbertwo")

 

After this change the file paths get recognised.

0 Likes
Message 17 of 17

john.uhden
Mentor
Mentor

@c3dsolutions 

That may be the case for the support file paths, but the trusted function I gave you wants the paths as a list, not a long string.  That's because it verifies each path existence.

John F. Uhden

0 Likes