Add and removing support files search paths

Add and removing support files search paths

jbear0000
Enthusiast Enthusiast
3,458 Views
13 Replies
Message 1 of 14

Add and removing support files search paths

jbear0000
Enthusiast
Enthusiast

We have a problem where the font folders in the support files search path keep disappearing. Our fonts folders are important enough that I'd like a lisp that adds them every time someone starts AutoCad. So I started looking for a lisp to add them, but the one I created adds them to the top of the list and there are duplicates. Having them at the top of the list created some problems so I want them placed in the correct order. I found this http://lee-mac.com/addremovesupportpaths.html and have tried to use it. I want it to first remove the font folders and then add them back in the correct location. I'm not great with coding so I'm not sure where I'm going wrong here. We have two font folders that we use. The one that comes with AutoCad "C:\\program files\\autodesk\\autocad 2016\\fonts" and one on our server "Y:\\Library\\CAD Support Files\\Fonts"

 

;; Remove Support File Search Paths  -  Lee Mac
;; Removes a list of Support File Search Paths if present.
;; lst - [lst] list of paths to remove (case-insensitive), e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; Returns: [str] "ACAD" Environment String following modification

(defun LM:sfsp- '("C:\\program files\\autodesk\\autocad 2016\\fonts" "Y:\\Library\\CAD Support Files\\Fonts" / pos str tmp )
    (setq str (strcat (vl-string-right-trim ";" (getenv "ACAD")) ";")
          tmp str
    )
    (foreach pth lst
        (if (/= "" pth)
            (while (setq pos (vl-string-search (strcase (strcat pth ";")) (strcase str)))
                (setq str (strcat (substr str 1 pos) (substr str (+ pos (strlen pth) 2))))
            )
        )
    )
    (if (/= tmp str) (setenv "ACAD" str))
)

;; Add Support File Search Paths at 'n'  -  Lee Mac
;; Adds a list of Support File Search Paths, excluding duplicates and invalid paths.
;; lst - [lst] list of paths to add, e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; idx - [int] [optional] zero-based index at which to add new paths
;; Returns: [str] "ACAD" Environment String following modification

(defun LM:sfsp+n '("C:\\program files\\autodesk\\autocad 2016\\fonts" "Y:\\Library\\CAD Support Files\\Fonts" 30 / add )

    (defun add ( str new idx / pos )
        (if (< 0 idx)
            (if (setq pos (vl-string-position 59 str))
                (strcat (substr str 1 (1+ pos)) (add (substr str (+ pos 2)) new (1- idx)))
                (strcat ";" new)
            )
            (strcat new str ";")
        )
    )
    (   (lambda ( str lst )
            (if (setq lst
                    (vl-remove-if
                       '(lambda ( x )
                            (or (vl-string-search (strcase x) (strcase str))
                                (not (findfile x))
                            )
                        )
                        lst
                    )
                )
                (setenv "ACAD" (add str (apply 'strcat (mapcar '(lambda ( x ) (strcat x ";")) lst)) idx))
            )
        )
        (vl-string-right-trim ";" (getenv "ACAD"))
        (mapcar '(lambda ( x ) (vl-string-right-trim "\\" (vl-string-translate "/" "\\" x))) lst)
    )
)

 

0 Likes
Accepted solutions (1)
3,459 Views
13 Replies
Replies (13)
Message 2 of 14

dlanorh
Advisor
Advisor

@jbear0000 wrote:

We have a problem where the font folders in the support files search path keep disappearing. Our fonts folders are important enough that I'd like a lisp that adds them every time someone starts AutoCad. So I started looking for a lisp to add them, but the one I created adds them to the top of the list and there are duplicates. Having them at the top of the list created some problems so I want them placed in the correct order. I found this http://lee-mac.com/addremovesupportpaths.html and have tried to use it. I want it to first remove the font folders and then add them back in the correct location. I'm not great with coding so I'm not sure where I'm going wrong here. We have two font folders that we use. The one that comes with AutoCad "C:\\program files\\autodesk\\autocad 2016\\fonts" and one on our server "Y:\\Library\\CAD Support Files\\Fonts"

 

;; Remove Support File Search Paths  -  Lee Mac
;; Removes a list of Support File Search Paths if present.
;; lst - [lst] list of paths to remove (case-insensitive), e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; Returns: [str] "ACAD" Environment String following modification

(defun LM:sfsp- '("C:\\program files\\autodesk\\autocad 2016\\fonts" "Y:\\Library\\CAD Support Files\\Fonts" / pos str tmp )
    (setq str (strcat (vl-string-right-trim ";" (getenv "ACAD")) ";")
          tmp str
    )
    (foreach pth lst
        (if (/= "" pth)
            (while (setq pos (vl-string-search (strcase (strcat pth ";")) (strcase str)))
                (setq str (strcat (substr str 1 pos) (substr str (+ pos (strlen pth) 2))))
            )
        )
    )
    (if (/= tmp str) (setenv "ACAD" str))
)

;; Add Support File Search Paths at 'n'  -  Lee Mac
;; Adds a list of Support File Search Paths, excluding duplicates and invalid paths.
;; lst - [lst] list of paths to add, e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; idx - [int] [optional] zero-based index at which to add new paths
;; Returns: [str] "ACAD" Environment String following modification

(defun LM:sfsp+n '("C:\\program files\\autodesk\\autocad 2016\\fonts" "Y:\\Library\\CAD Support Files\\Fonts" 30 / add )

    (defun add ( str new idx / pos )
        (if (< 0 idx)
            (if (setq pos (vl-string-position 59 str))
                (strcat (substr str 1 (1+ pos)) (add (substr str (+ pos 2)) new (1- idx)))
                (strcat ";" new)
            )
            (strcat new str ";")
        )
    )
    (   (lambda ( str lst )
            (if (setq lst
                    (vl-remove-if
                       '(lambda ( x )
                            (or (vl-string-search (strcase x) (strcase str))
                                (not (findfile x))
                            )
                        )
                        lst
                    )
                )
                (setenv "ACAD" (add str (apply 'strcat (mapcar '(lambda ( x ) (strcat x ";")) lst)) idx))
            )
        )
        (vl-string-right-trim ";" (getenv "ACAD"))
        (mapcar '(lambda ( x ) (vl-string-right-trim "\\" (vl-string-translate "/" "\\" x))) lst)
    )
)

 Check the Autocad file path using "windows explorer". On my system it reads "\\autocad 2016-English\\"  If in doubt use the browse feature built into the options-files tab. Highlight the font entry and click on browse.


 

I am not one of the robots you're looking for

0 Likes
Message 3 of 14

jbear0000
Enthusiast
Enthusiast

C:\program files\autodesk\autocad 2016\fonts is correct, we use Civil 3D so maybe that is why ours is different. I get a syntax error when trying to run the lisp.

0 Likes
Message 4 of 14

dlanorh
Advisor
Advisor

Before running check if they are there.

(vl-load-com)

(defun c:sfpaths ( / a_obj sf_paths)
  (setq a_obj (vlax-get-acad-object)
        sf_paths (vla-get-supportpath (vla-get-files (vla-get-preferences a_obj)))
  )
  (princ)
)  

The above will give you sf_paths, a string containing all the support paths in the files preference.

Don't try to change this string, but search it for your strings. You can remove something that isn't there.

If it's ot there add it, then re-run to get the new string and check again.

If you are still having problems i suggest sending Lee an email via his site

I am not one of the robots you're looking for

0 Likes
Message 5 of 14

jbear0000
Enthusiast
Enthusiast

I have no clue how to do that. I'm not a coder and I've even had our IT guy look at this who knows a bit about coding and he isn't sure what we are doing wrong either. I have no idea how to have it search for strings, have it add what isn't there or remove extra stuff. Besides, the font folders need to be in a certain order for us or they don't work. Lee's code claims it can do that, but I can't figure out how it works. Does anyone else here know how to make it work? Or does anyone know of a way to remove paths and then add them back in the correct order?

0 Likes
Message 6 of 14

dlanorh
Advisor
Advisor
I'll have a look at it over the weekend. Again your best bet is contacting Lee.

I am not one of the robots you're looking for

0 Likes
Message 7 of 14

ronjonp
Advisor
Advisor
Accepted solution

You're not using the routines as Lee has shown on his site.

Use like so:

 

(lm:sfsp- '("C:\\program files\\autodesk\\autocad 2016\\fonts" "Y:\\Library\\CAD Support Files\\Fonts"))

(lm:sfsp+n '("C:\\program files\\autodesk\\autocad 2016\\fonts" "Y:\\Library\\CAD Support Files\\Fonts") 30)
Message 8 of 14

dlanorh
Advisor
Advisor
Well spotted and **** the horizontal scroll

I am not one of the robots you're looking for

0 Likes
Message 9 of 14

ronjonp
Advisor
Advisor

LOL .. it would help if the board fit to the width of the screen .. this is what I see:

2018-05-25_13-05-26.png

0 Likes
Message 10 of 14

john.uhden
Mentor
Mentor

I am afraid this won't work at all.  Our primary goal is to help you learn how to help yourself.  If we show you how you could use the donated code, but you have no idea what to do with it, then it would require our doing everything for you and each time you needed to do it.  That creates a state of dependency, not learning.

John F. Uhden

0 Likes
Message 11 of 14

jbear0000
Enthusiast
Enthusiast
Thank you for your help. This solved my problem and I now have it working correctly. I appreciate you taking the time to help me out today.
0 Likes
Message 12 of 14

jbear0000
Enthusiast
Enthusiast
rperez already gave me the solution I needed. Sorry that me asking for help with such a bother to you that you felt you needed to respond in this way. My company does not pay me to sit for hour upon hour learning to code. I already spent way too much time trying to work this through on my own and I am grateful for kind people who are willing to help. Unfortunately you are not one of those people.
0 Likes
Message 13 of 14

ronjonp
Advisor
Advisor

 


@jbear0000 wrote:
Thank you for your help. This solved my problem and I now have it working correctly. I appreciate you taking the time to help me out today.

Glad to help out 🙂

0 Likes
Message 14 of 14

dgorsman
Consultant
Consultant

@jbear0000 wrote:
rperez already gave me the solution I needed. Sorry that me asking for help with such a bother to you that you felt you needed to respond in this way. My company does not pay me to sit for hour upon hour learning to code. I already spent way too much time trying to work this through on my own and I am grateful for kind people who are willing to help. Unfortunately you are not one of those people.

Steady - he *is* trying to help, even if he was a little short with you.  The main point of boards like this is to help people to write code (good code, preferably).  What sometimes happens is users come in with what you might term "Want fries with that..." questions i.e. they want more and more complicated work done for them.  A little volunteer work is good for the soul and brain exercise, but doing other peoples work for them on a regular basis is not.

 

I strongly encourage you to start becoming proficient with LISP, at least with the basics.  It won't take "hour after hour" and will be of benefit to your job, as you've seen.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes