Search Paths Keep Piling up

Search Paths Keep Piling up

chris.neelin
Contributor Contributor
839 Views
3 Replies
Message 1 of 4

Search Paths Keep Piling up

chris.neelin
Contributor
Contributor

I have the following lisp that works perfectly .. except that each time it runs it adds the same path again and again. e.g. I set the path to "\\HELP\\" so each time I run the lisp I get , I would like it to just do it once ... any suggestions are greatly appreciated.

1st

c:\users\neelinch\iescad\help

 

2nd time

c:\users\neelinch\iescad\help

c:\users\neelinch\iescad\help

 

3rd time

c:\users\neelinch\iescad\help

c:\users\neelinch\iescad\help

c:\users\neelinch\iescad\help

 

-----------------------------------------------------------------------------

Below is the lisp

-----------------------------------------------------------------------------

;-----------------------------------------
; Add additional support File Paths
;-----------------------------------------
(defun MTO_PATH ( / )

;Get environment variable USERPROFILE
(setq IESCAD2016 (strcat (getenv "USERPROFILE") "\\IESCAD2016"))

(setq Help (strcat IESCAD2016 "\\Help\\"))

(setq COM (strcat IESCAD2016 "\\com\\lisp\\"))

(setq FONT (strcat IESCAD2016 "\\MTO_Fonts")) ; set path to MTO Specific fonts

(setq HATCH (strcat IESCAD2016 "\\MTO_HATCH"))

(setq HelpPD (strcat IESCAD2016 "\\PD\\Lisp\\")); Planning and Design Lisp

(setq TrafficHelp (strcat IESCAD2016 "\\tr\\Help")); Traffic Sign Manuals

(setq PD_Block (strcat IESCAD2016 "\\PD\\Symbols\\")); Planning and Design Blocks

(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 paths
(setq thePath (strcat FONT ";" Help ";" COM ";" HATCH ";" HelpPD ";" TrafficHelp ";" PD_Block ";" thePath))

; update support path variable
(vlax-put-property tabnameObject 'SupportPath thePath)
)
(MTO_PATH)

 

0 Likes
Accepted solutions (1)
840 Views
3 Replies
Replies (3)
Message 2 of 4

ambrosl
Autodesk
Autodesk

You could split the values of the Support File Search Path and determine if the path already exists before adding it.  You can find an example of how to split a string into individual elements based on a delimiter here:

http://hyperpics.blogs.com/beyond_the_ui/2017/02/splitting-a-string-into-a-list-of-elements-based-on...

 

Once the string is split, you can then test each element in the list for the path you want to add.



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 3 of 4

Scottu2
Advocate
Advocate
Accepted solution

Hello chris.neelin,

 

Try changing the last line to test the path string for an existing \\Help\\.

When the vl-string-search can not find the key word it returns nil (does not exist)

If is did find the key word it returns the character position in the string.

 

(vlax-put-property tabnameObject 'SupportPath thePath)

 

to

 

(if (= nil (vl-string-search "\\Help\\ thePath)) (vlax-put-property tabnameObject 'SupportPath thePath) )

 

 

Message 4 of 4

chris.neelin
Contributor
Contributor

Thanks Scott and Lee for the great suggestions, below is what I ended up with .......works like a charm now

 

(setq IESCAD2016 (strcat (getenv "USERPROFILE") "\\IESCAD2016"))
(setq
 ies-paths
 (list
  (strcat IESCAD2016 "\\com\\")
  (strcat IESCAD2016 "\\Help\\")
  (strcat IESCAD2016 "\\com\\lisp\\")
  (strcat IESCAD2016 "\\MTO_Fonts")
  (strcat IESCAD2016 "\\MTO_HATCH")
  (strcat IESCAD2016 "\\PD\\Lisp\\")
  (strcat IESCAD2016 "\\ST\\Lisp\\")
  (strcat IESCAD2016 "\\tr\\Help")
  (strcat IESCAD2016 "\\PD\\Symbols\\")
 )
)

(defun IES:prepend-support-paths (addpaths / acFiles paths)
 (setq acFiles (vla-get-files (vla-get-preferences (vlax-get-acad-object))))
 (setq paths (vla-get-SupportPath acFiles))
 (mapcar
  '(lambda (path)
   (setq path (strcat (vl-string-right-trim "\\" path) "\\;"))
   (while (wcmatch (strcat "*" path "*") paths)
    (setq paths (vl-string-subst "" path paths))
   )
   (setq paths (strcat path paths))
  )
  (reverse addpaths)
 )
 (vla-put-SupportPath acFiles paths)
 (vlax-release-object acFiles)
 (princ)
)

(IES:prepend-support-paths ies-paths)

0 Likes