guitarguy1685 Posted April 14, 2020 Posted April 14, 2020 (edited) So I have this weird situation. In a list I have the following line (findfile "C:\\Windows\\Fonts\\arial.ttf") It returns "nil" on my home computer but it returns the path on my work computer. It's a standard font, but I did make sure it is installed on both computers. I have no idea why it can't find the file on my home desktop. I thought it could be permission thing because looking for files in the root directory, but I can find other files in the Windows folder. I don't know what I'm doing wrong. This happens on ACAD 2020 and ACAD2021 Edited April 14, 2020 by guitarguy1685 Quote
hanhphuc Posted April 14, 2020 Posted April 14, 2020 (edited) 9 hours ago, guitarguy1685 said: So I have this weird situation. In a list I have the following line (findfile "C:\\Windows\\Fonts\\arial.ttf") It returns "nil" on my home computer but it returns the path on my work computer. It's a standard font, but I did make sure it is installed on both computers. I have no idea why it can't find the file on my home desktop. I thought it could be permission thing because looking for files in the root directory, but I can find other files in the Windows folder. I don't know what I'm doing wrong. This happens on ACAD 2020 and ACAD2021 hi, not sure this alternative working? ; ;(defun _findfile (fn) ; (if ((lambda (l) (vl-directory-files (car l) ; (apply 'strcat (cdr l)) ; ) ; ) ; (fnsplitl fn) ; ) ; fn ; ) ;) ;;if findfile null , attempt to search local directory ;;"c:\\windows\\" ---> "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\" (defun _findfile (fn) (cond ;; search as "C:\\windows\\Fonts\\arial.ttf" ((findfile fn)) ;; search local as "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\fonts\\arial.ttf" ((findfile (strcat (getenv "userprofile") "\\AppData\\Local\\Microsoft\\Windows\\" (vl-string-left-trim "c:\\windows" (strcase fn t)) ) ) ) ;; search in ACAD directory only as "arial.ttf" ((findfile (vl-string-left-trim (vl-filename-directory fn ) fn ) ) ) ) ) try ( _findfile "C:\\Windows\\Fonts\\arial.ttf" ) Edited April 14, 2020 by hanhphuc findfile local sorted by OP Quote
ronjonp Posted April 14, 2020 Posted April 14, 2020 3 hours ago, guitarguy1685 said: It's a standard font, but I did make sure it is installed on both computers. I have no idea why it can't find the file on my home desktop. Did you check that the 'arial.ttf' file is in that location? Quote
guitarguy1685 Posted April 14, 2020 Author Posted April 14, 2020 28 minutes ago, ronjonp said: Did you check that the 'arial.ttf' file is in that location? Okay so it appears to be a windows thing. When I go to C:\Windows\Fonts, Windows10 uses some "font display window", different from file explorer. On both computers the font shows that Arial is installed. However if I use UNC convention to view the folder such as "\\computer-name\C$\Windows\Fonts" i can view the folder in a standard file explorer view. When I do this, I only see the arial.ttf on my work station and not my home desktop. So while Arial is installed on my home desktop the file is somewhere else. I'll find it. So the (findfile) is working as it should. Quote
guitarguy1685 Posted April 14, 2020 Author Posted April 14, 2020 I found it. This font is installed on my user folder. %userprofile%\AppData\Local\Microsoft\Windows\Fonts I didn't know that was a thing. Quote
ronjonp Posted April 14, 2020 Posted April 14, 2020 1 hour ago, guitarguy1685 said: I found it. This font is installed on my user folder. %userprofile%\AppData\Local\Microsoft\Windows\Fonts I didn't know that was a thing. Glad you got it sorted! Quote
guitarguy1685 Posted April 15, 2020 Author Posted April 15, 2020 8 hours ago, hanhphuc said: I completely glossed over the fact that your solution includes searches in user profile and root directory. That would've solved my issue. hi, not sure this alternative working? ; ;(defun _findfile (fn) ; (if ((lambda (l) (vl-directory-files (car l) ; (apply 'strcat (cdr l)) ; ) ; ) ; (fnsplitl fn) ; ) ; fn ; ) ;) ;;if findfile null , attempt to search local directory ;;"c:\\windows\\" ---> "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\" (defun _findfile (fn) (cond ;; search as "C:\\windows\\Fonts\\arial.ttf" ((findfile fn)) ;; search local as "C:\\Users\\user\\AppData\\Local\\Microsoft\\Windows\\fonts\\arial.ttf" ((findfile (strcat (getenv "userprofile") "\\AppData\\Local\\Microsoft\\Windows\\" (vl-string-left-trim "c:\\windows" (strcase fn t)) ) ) ) ;; search in ACAD directory only as "arial.ttf" ((findfile (vl-string-left-trim (vl-filename-directory fn ) fn ) ) ) ) ) try ( _findfile "C:\\Windows\\Fonts\\arial.ttf" ) Quote
Lee Mac Posted April 15, 2020 Posted April 15, 2020 The following should present a far more reliable method across multiple systems: (defun LM:findfontfile ( fnt / dir ) (if (setq dir (LM:specialfolder "fonts")) (progn (eval (list 'defun 'LM:findfontfile '( fnt ) (list 'findfile (list 'strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir) ) "\\" 'fnt ) ) ) ) (LM:findfontfile fnt) ) ) ) ;; Special Folder - Lee Mac ;; Queries the WshSpecialFolders collection for the specified folder ;; Ref: http://msdn.microsoft.com/en-us/library/9x9e7edx%28v=vs.85%29.aspx (defun LM:specialfolder ( fld / rtn spf wsh ) (if (setq wsh (vlax-get-or-create-object "wscript.shell")) (progn (setq rtn (vl-catch-all-apply '(lambda ( ) (setq spf (vlax-get-property wsh 'specialfolders)) (vlax-invoke-method spf 'item fld) ) ) ) (if spf (vlax-release-object spf)) (vlax-release-object wsh) (if (not (vl-catch-all-error-p rtn)) rtn) ) ) ) (vl-load-com) (princ) _$ (LM:findfontfile "arial.ttf") "C:\\Windows\\Fonts\\arial.ttf" 3 Quote
guitarguy1685 Posted April 16, 2020 Author Posted April 16, 2020 works like a charm. thanks lee-mac 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.