Adding drawing explorer folders using lisp.

Is there a method of GETTING and SETTING the drawing explorer folders paths via lisp or environment variables?

Comments

  • Here's something to get you started.

    [code](defun C:GetExplorerFolders ( / BaseKey CurProfile ExplorerFolders NoFolders ctr thisfolder folderlist)
        (setq BaseKey (strcat "HKCU\\" (vlax-product-key) "\\Profiles"))
        (setq CurProfile (getvar 'CPROFILE))
        (setq ExplorerFolders "Dialogs\\Drawing Explorer\\Folder List")
        (setq NoFolders (vl-registry-read (strcat BaseKey "\\" CurProfile "\\" ExplorerFolders) "FoldersCount"))
        (cond
            ((> Nofolders 0)
                (princ "\nExplorer Folder List: ")
                (setq ctr 0)
                (repeat NoFolders
                    (setq thisfolder (vl-registry-read (strcat BaseKey "\\" CurProfile "\\" ExplorerFolders) (strcat "Folder" (itoa ctr))))
                    (princ "\n")(princ thisfolder)
                    (setq folderlist (vle-append folderlist thisfolder))
                    (setq ctr (1+ ctr))
                )
                (princ (strcat "\nTotal: " (itoa NoFolders)))
            )
            (T (Princ "\nNo folders found "))
        )
    (prin1)
    )[/code]

    [code](defun C:SetExplorerFolders ( / BaseKey CurProfile ExplorerFolders NoFolders folderlist)
        (setq BaseKey (strcat "HKCU\\" (vlax-product-key) "\\Profiles"))
        (setq CurProfile (getvar 'CPROFILE))
        (setq ExplorerFolders "Dialogs\\Drawing Explorer\\Folder List")
        (setq folderlist '("C:\\MyFolder\\Folder-01" "C:\\MyFolder\\Folder-02" "C:\\MyFolder\\Folder-03"))
        (setq Nofolders 0)
        (foreach folder folderlist
            (cond
                ((findfile folder)
                    (vl-registry-write
                        (strcat BaseKey "\\" CurProfile "\\" ExplorerFolders)
                        (strcat "Folder" (itoa NoFolders))
                        folder
                    )
                    (setq NoFolders (1+ NoFolders))
                )
            )
        )
        (vl-registry-write (strcat BaseKey "\\" CurProfile "\\" ExplorerFolders) "FoldersCount" NoFolders)
        (princ (strcat "\nNumber of Explorer Folders set: " (itoa NoFolders)))
    (prin1)
    )E[/code]

    Regards,
    Jason Bourhill

  • re-post of SetExplorerFolders. My last post included a spurious "E" at the end.

    [code](defun C:SetExplorerFolders ( / BaseKey CurProfile ExplorerFolders NoFolders folderlist)
        (setq BaseKey (strcat "HKCU\\" (vlax-product-key) "\\Profiles"))
        (setq CurProfile (getvar 'CPROFILE))
        (setq ExplorerFolders "Dialogs\\Drawing Explorer\\Folder List")
        (setq folderlist '("C:\\MyFolder\\Folder-01" "C:\\MyFolder\\Folder-02" "C:\\MyFolder\\Folder-03"))
        (setq Nofolders 0)
        (foreach folder folderlist
            (cond
                ((findfile folder)
                    (vl-registry-write
                        (strcat BaseKey "\\" CurProfile "\\" ExplorerFolders)
                        (strcat "Folder" (itoa NoFolders))
                        folder
                    )
                    (setq NoFolders (1+ NoFolders))
                )
            )
        )
        (vl-registry-write (strcat BaseKey "\\" CurProfile "\\" ExplorerFolders) "FoldersCount" NoFolders)
        (princ (strcat "\nNumber of Explorer Folders set: " (itoa NoFolders)))
    (prin1)
    )[/code]

    Regards,
    Jason Bourhill

  • Thanks Jason.

    I'm going to need to explore all the Registry entries as it seems like a good way to customise the program.

    Mike.
  • If you haven't already done so, I would explore the User Profile Manager. This allows you to import and export BricsCAD Profiles, which are in effect registry snippets.
    http://www.cadconcepts.co.nz/creating-a-new-user-profile/

    Things like the explorer folder list are captured within your profile.

    Regards,
    Jason Bourhill

  • When customizing BricsCAD via the registry you should be aware that the program reads most values at start-up only. Most changes made during a CAD session will not have any effect and will be overwritten when the program closes.
  • When customizing BricsCAD via the registry you should be aware that the program reads most values at start-up only. Most changes made during a CAD session will not have any effect and will be overwritten when the program closes.


    Your right. It is also when BricsCAD commits any changes you've made via SETTINGS and the like. This can be a point of frustration if you crash out of BricsCAD, or you open another session. In the case of multiple sessions, I think it is last session that wins. It's for this reason I never launch the User Profile Manager from within BricsCAD.

    The OP asked for a LISP, and in this particular case it works. However I think capturing these settings using your profile is a better approach.

    Regards,
    Jason Bourhill


  • I'm trying to do everything through a partial menu so that a user's own customization isn't affected by adding an extra item to the menu bar.  That way the user only has to load the ".cui" file to have everything work.  We are using Google drive so the paths will be different on each machine.

    I've noticed that the registry values are not implemented in the current session or maybe reset by the program.

    Also my registry doesn't seem to have the "FoldersCount" property set so I'm reading the folder names incrementally.

    [code](defun getenvironmentroot ()
      (setq retval nil)
      (setq gdrivepath (strcat (getenv "USERPROFILE") "\\Google Drive\\DATA SOURCES\\CAD"))
      (setq localpath "C:\\CAD")
      (if (findfile gdrivepath)
        (setq retval gdrivepath)
        (if (findfile localpath)
          (setq retval localpath)
        )
      )
      (princ "\nLocated Red Earth ROOT path: ")
      (princ retval)
    )
    [/code]

    [code] ; Set Drawing Explorer Folders
      (setq rootpath (getenvironmentroot))
      (setq RegKey (strcat (strcat "HKEY_CURRENT_USER\\"
                             (vlax-product-key)
                             "\\Profiles") "\\"
                             (getvar 'CPROFILE) "\\"
                             "Dialogs\\Drawing Explorer\\Folder List")
      )
      (setq ctr 0)
      (setq folderlist "")
      (while (setq thisfolder (vl-registry-read RegKey (strcat "Folder" (itoa ctr))))
        (setq folderlist (strcat folderlist ";" thisfolder))
        (setq ctr (1+ ctr))
      )
      (if (> ctr 0)
        (setq folderlist (substr folderlist 2))
        (setq folderlist nil)
      )
      (if (not (vl-string-search rootpath folderlist))
        (progn
          (vl-registry-write RegKey
                             (strcat "Folder" (itoa (1+ ctr)))
                             (strcat rootpath "\\BLOCKS\\")
          )
          (vl-registry-write RegKey "FoldersCount" (1+ ctr))
          (princ (strcat "\n    Updated drawing explorer paths path: " rootpath "\\BLOCKS\\;" folderlist))
        )
        (princ (strcat "\n    No change to drawing explorer paths: " folderlist))
      )[/code]
  • Found the issue.  Increment the counter when writing the registry puts the registry name out of sequence.

    This works well...

    #TODO: add local variable declarations to function.

    [code]
    (defun getenvironmentroot ()
      (setq retval nil)
      (setq gdrivepath (strcat (getenv "USERPROFILE") "\\Google Drive\\DATA SOURCES\\CAD"))
      (setq localpath "C:\\CAD")
      (if (findfile gdrivepath)
        (setq retval gdrivepath)
        (if (findfile localpath)
          (setq retval localpath)
        )
      )
      (princ "\nLocated Red Earth ROOT path: ")
      (princ retval)
    )

    ; set up search and plotting paths
    (defun setenvironment (rootpath / path)
      ;;; Set file search path
      (setq path (getvar "SRCHPATH"))
      (if (not (vl-string-search rootpath path))
        (progn
          (setq path (strcat rootpath "\\MENUS;" rootpath "\\MACROS;" rootpath "\\BLOCKS;" path))
          (setvar "SRCHPATH" path)
          (princ (strcat "\n    Updated file search path: " path))
        )
        (princ (strcat "\n    No change to search path: " path))
      )
      ;;; Set plot config path
      (setq path (getvar "PLOTCFGPATH"))
      (if (not (vl-string-search rootpath path))
          (progn
            (setq path (strcat rootpath "\\PLOTCONFIG;" path))
            (setvar "PLOTCFGPATH" path)
            (princ (strcat "\n    Updated plot config path: " path))
          )
          (princ (strcat "\n    No change to plot config path: " path))
      )
      ;;; Set plot style path
      (setq path (getvar "PLOTSTYLEPATH"))
      (if (not (vl-string-search rootpath path))
          (progn
            (setq path (strcat rootpath "\\PLOTSTYLES;" path))
            (setvar "PLOTSTYLEPATH" path)
            (princ (strcat "\n    Updated plot styles path: " path))
          )
          (princ (strcat "\n    No change to plot styles path: " path))
      )
      ;;; Set drawing template path
      (setq path (getvar "TEMPLATEPATH"))
      (if (not (vl-string-search rootpath path))
          (progn
            (setq path (strcat rootpath "\\TEMPLATES;" path))
            (setvar "TEMPLATEPATH" path)
            (princ (strcat "\n    Updated template path: " path))
          )
          (princ (strcat "\n    No change to template path: " path))
      )
      ;;; Set sheet set template path
      (setq path (getvar "SHEETSETTEMPLATEPATH"))
      (if (not (vl-string-search rootpath path))
          (progn
            (setq path (strcat rootpath "\\TEMPLATES\\SHEETSETS;" path))
            (setvar "SHEETSETTEMPLATEPATH" path)
            (princ (strcat "\n    Updated sheet set template path: " path))
          )
          (princ (strcat "\n    No change to sheet set template path: " path))
      )
      ;;; Set drawing template path
      (setq path (getvar "TOOLPALETTEPATH"))
      (if (not (vl-string-search rootpath path))
        (progn
          (setq path (strcat rootpath "\\TOOLPALETTES;" path))
          (setvar "TOOLPALETTEPATH" path)
          (princ (strcat "\n    Updated toolpalettes path: " path))
        )
        (princ (strcat "\n    No change to toolpalettes path: " path))
      )
      (setq path (getvar "TOOLPALETTEPATH"))
      (if (= path "")
        (setvar "DEFAULTNEWSHEETTEMPLATE" "REE A1 DRAWING.dwt")
      )

      ; Set Drawing Explorer Folders
      (setq RegKey (strcat (strcat "HKEY_CURRENT_USER\\"
                             (vlax-product-key)
                             "\\Profiles") "\\"
                             (getvar 'CPROFILE) "\\"
                             "Dialogs\\Drawing Explorer\\Folder List")
      )
      (setq ctr 0)
      (setq folderlist "")
      (while (setq thisfolder (vl-registry-read RegKey (strcat "Folder" (itoa ctr))))
        (setq folderlist (strcat folderlist ";" thisfolder))
        (setq ctr (1+ ctr))
      )
      (if (> ctr 0)
        (setq folderlist (substr folderlist 2))
        (setq folderlist nil)
      )
      (if (not (vl-string-search rootpath folderlist))
        (progn
          (vl-registry-write RegKey
                             (strcat "Folder" (itoa ctr))
                             (strcat rootpath "\\BLOCKS\\")
          )
          (vl-registry-write RegKey "FoldersCount" (1+ ctr))
          (princ (strcat "\n    Updated drawing explorer paths path: " rootpath "\\BLOCKS\\;" folderlist))
        )
        (princ (strcat "\n    No change to drawing explorer paths: " folderlist))
      )
    )

    ; ============================================================
    ; locate root path and update environment variables
    ; ============================================================
    (if (setq rootpath (getenvironmentroot))
      (progn
        (setenvironment rootpath)
        ; load other macros
        (load "REDEARTH.LSP")
      )
      (princ "\m*** ERROR Unable to locate REE cad environment! ***")
    )
    (princ "\n==========================================")
    (princ)
    [/code]
This discussion has been closed.