TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ronjonp on May 04, 2005, 12:35:13 PM

Title: (getvar 'dwgprefix) xref path
Post by: ronjonp on May 04, 2005, 12:35:13 PM
I've been running this in my startup at work because I hate having to browse all over the network for these files: Currently AutoCAD uses the last opened folder and this allows for the current dwgpath to be shown. I'm sure it could use some cleaning up so knock yourself out :)

One question....how can I extract this info (in red) from the registry so I don't have to hard code it?

(setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\XattachFileDialog"))

Latest code is below in this thread .. tested on AutoCAD 2014.
http://www.theswamp.org/index.php?topic=5029.msg502985#msg502985 (http://www.theswamp.org/index.php?topic=5029.msg502985#msg502985)

Code: [Select]
;_____________________________________________________________________________
;;SETS XREF ATTACH DIALOGUE AND SHEET MANAGER START FOLDER TO CURRENT DRAWING PATH
;_____________________________________________________________________________

(defun writereg (/  dwgpath profile hkey version regpath)
  (if (not (wcmatch (getvar 'dwgname) "Drawing*.dwg"))
    (progn
     
      (setq dwgpath  (strcat (getvar 'dwgprefix))
              profile (strcat (getvar 'cprofile))
              hkey "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\"
              version (strcat "R" (substr (getvar 'acadver) 1 4)))

      (setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\XattachFileDialog"))
      (if (vl-registry-read regpath "InitialDirectory")
      (vl-registry-write regpath "InitialDirectory" dwgpath)
       )

      (setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\XrefFileDialog"))
      (if (vl-registry-read regpath "InitialDirectory")
      (vl-registry-write regpath "InitialDirectory" dwgpath)
       )

      (setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\Sheet Set Wizard"))
      (if (vl-registry-read regpath "BrowseForLayoutsPath")
      (vl-registry-write regpath "BrowseForLayoutsPath" dwgpath)
       )

      (setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\Sheet Set Wizard"))
      (if (vl-registry-read regpath "SheetSetCreatePath")
      (vl-registry-write regpath "SheetSetCreatePath" dwgpath)
       )

      (setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\eTransAddFile"))
      (if (vl-registry-read regpath "InitialDirectory")
      (vl-registry-write regpath "InitialDirectory" dwgpath)
       )

      (setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\SSMNavigator"))
      (if (vl-registry-read regpath "OpenSheetSetPath")
      (vl-registry-write regpath "OpenSheetSetPath" dwgpath)
       )

      (setq regpath  (strcat hkey version "\\ACAD-301:409\\Profiles\\" profile "\\Dialogs\\SSMNavigator"))
      (if (vl-registry-read regpath "ImportLayoutsAsSheetsPath")
      (vl-registry-write regpath "ImportLayoutsAsSheetsPath" dwgpath)
       )

    )
  )
)
(writereg)
Title: (getvar 'dwgprefix) xref path
Post by: Keith™ on May 04, 2005, 12:44:45 PM
you need to look into a different registry key ...

1 - Grab the value of the key: HKLM\Software\Autodesk\AutoCAD\CurVer
2 - Use the value from #1 to get the value of key: HKLM\Software\Autodesk\AutoCAD\%value goes here%\CurVer
3 - The return value of 2 will be: ACAD-301:409 (or whatever version you have installed)
Title: (getvar 'dwgprefix) xref path
Post by: ronjonp on May 04, 2005, 01:12:15 PM
Thanks Keith.....with that said:

Code: [Select]
;;;;____________________________________________________________________________________________
;;;;SETS XREF ATTACH DIALOG, ETRANSMIT, AND SHEET MANAGER START FOLDER TO CURRENT DRAWING PATH
;;;;____________________________________________________________________________________________

(defun writereg   (/ DP HKCU key regpath)
  (if (= (getvar 'dwgtitled) 1)
    (progn
      (setq DP    (getvar 'dwgprefix)
       HKCU (strcat "HKEY_CURRENT_USER\\" (vlax-product-key))
       key    (strcat HKCU
          "\\Profiles\\"
          (getvar 'cprofile)
          "\\Dialogs\\"
       )
      )
      (setq regpath (strcat HKCU "\\ETransmit\\Setups\\Standard\\"))
      (vl-registry-write regpath "DestFolder" DP)

      (setq regpath (strcat key "XattachFileDialog"))
      (vl-registry-write regpath "InitialDirectory" DP)

      (setq regpath (strcat key "XrefFileDialog"))
      (vl-registry-write regpath "InitialDirectory" DP)

      (setq regpath (strcat key "Sheet Set Wizard"))
      (vl-registry-write regpath "BrowseForLayoutsPath" DP)

      (setq regpath (strcat key "Sheet Set Wizard"))
      (vl-registry-write regpath "SheetSetCreatePath" DP)

      (setq regpath (strcat key "eTransAddFile"))
      (vl-registry-write regpath "InitialDirectory" DP)

      (setq regpath (strcat key "SSMNavigator"))
      (vl-registry-write regpath "OpenSheetSetPath" DP)

      (setq regpath (strcat key "SSMNavigator"))
      (vl-registry-write regpath "ImportLayoutsAsSheetsPath" DP)
    )
  )
)
(writereg)

(vlr-command-reactor nil '((:vlr-commandWillStart . startCommand)))

(defun startCommand
       (calling-reactor startcommandInfo / thecommandstart)
  (setq thecommandstart (nth 0 startcommandInfo))
  (cond
    ((= thecommandstart "XREF") (writereg))
    ((= thecommandstart "ETRANSMIT") (writereg))
    ((= thecommandstart "NEWSHEETSET") (writereg))
  )
)
Title: Re: (getvar 'dwgprefix) xref path
Post by: hyposmurf on August 09, 2013, 09:01:15 AM

ronjonp this routine used to be really helpful, however it no longer works,maybe due to the registry locations being different for the later releases. Have you by any chance got an updated version please?
Title: Re: (getvar 'dwgprefix) xref path
Post by: ronjonp on August 09, 2013, 09:35:56 AM
I really miss this too .. since upgrading to 2014 it does not work :(.
I may have some down time today to try and get it working again.
Title: Re: (getvar 'dwgprefix) xref path
Post by: ronjonp on August 09, 2013, 10:59:18 AM
Hypo,

Give the following code a try .. it appears to be working in AutoCAD 2014 :).
Code - Auto/Visual Lisp: [Select]
  1. (defun rjp-currentpath (/ dp hkcu key)
  2.   ;; RJP » 2019-03-27
  3.   ;; Sets current drawing directory for XREF, ETRANSMIT, SHEETSET and PUBLISH commands
  4.   ;; Writes to registry so use at your own risk...
  5.   (cond ((= (getvar 'dwgtitled) 1)
  6.          (setq dp   (getvar 'dwgprefix)
  7.                hkcu (strcat "HKEY_CURRENT_USER\\"
  8.                             (cond ((vlax-user-product-key))
  9.                                   ((vlax-product-key))
  10.                             )
  11.                     )
  12.                key  (strcat hkcu "\\Profiles\\" (getvar 'cprofile) "\\Dialogs\\")
  13.          )
  14.          (vl-registry-write (strcat hkcu "\\ETransmit\\Setups\\Standard\\") "Destfolder" dp)
  15.          (cond ((wcmatch (getenv "username") "*")
  16.                 (vl-registry-write (strcat key "AllAnavDialogs\\") "PlacesOrder6" dp)
  17.                 (vl-registry-write
  18.                   (strcat key "AllAnavDialogs\\")
  19.                   "PlacesOrder6Display"
  20.                   "Current Directory"
  21.                 )
  22.                 (vl-registry-write (strcat key "AllAnavDialogs\\") "PlacesOrder6Ext" "")
  23.                )
  24.          )
  25.          (vl-registry-write (strcat hkcu "\\ETransmit\\Setups\\Standard\\") "Destfolder" dp)
  26.          (foreach reg '(("acad-131" "InitialDirectory")
  27.                         ("AcPublishDlg" "Location")
  28.                         ("AcSmNav:OpenSheetSet" "InitialDirectory")
  29.                         ("BrowseFolder" "InitialDirectory")
  30.                         ("BrowseforPlotFilePlotDlg" "InitialDirectory")
  31.                         ("BrowseropenDialog" "InitialDirectory")
  32.                         ("CreateTransmittalDialog" "DefaultPath")
  33.                         ("DSDNavDlg" "InitialDirectory")
  34.                         ("DWFNavDlg" "InitialDirectory")
  35.                         ("OUTPUTFOLDERDLG" "InitialDirectory")
  36.                         ("OpenSaveAnavDialogs" "InitialDirectory")
  37.                         ("PDFopenDialog" "InitialDirectory")
  38.                         ("SSMNavigator" "OpenSheetSetPath")
  39.                         ("SSMNavigator" "ImportLayoutsAsSheetsPath")
  40.                         ("Save Drawing As" "InitialDirectory")
  41.                         ("Select File" "InitialDirectory")
  42.                         ("Select a drawing to compare" "InitialDirectory")
  43.                         ;; RJP » 2022-01-05 -XREF dialog key
  44.                         ("Select Reference File" "InitialDirectory")
  45.                         ("Enter name of file to overlay" "InitialDirectory")
  46.                         ("Sheet Set Wizard" "BrowseForLayoutsPath")
  47.                         ("Sheet Set Wizard" "SheetSetCreatePath")
  48.                         ("XattachFileDialog" "InitialDirectory")
  49.                        )
  50.            (vl-registry-write (strcat key (car reg)) (cadr reg) dp)
  51.          )
  52.         )
  53.   )
  54.   (princ)
  55. )
  56. (or *current-path-reactor*
  57.     (setq *current-path-reactor* (vlr-command-reactor nil '((:vlr-commandwillstart . startcommand))))
  58. )
  59. (defun startcommand (calling-reactor startcommandinfo)
  60.   (and (wcmatch (car startcommandinfo) "*XREF,XATTACH,ETRANSMIT,*SHEET*,PUBLISH,*SAVEAS*,OPEN")
  61.        (rjp-currentpath)
  62.   )
  63. )
*edit to latest version
Title: Re: (getvar 'dwgprefix) xref path
Post by: irneb on August 12, 2013, 01:02:19 AM
Did you guys try using the vlax-machine-product-key perhaps, or the vlax-user-product-key? They work fine in 2013, as does the vlax-product-key, but it's been noted a while back that it's deprecated.

You might find my get-acad-regroots routine helpful: https://www.theswamp.org/index.php?topic=44891.msg501096#msg501096
It "should" work for any acad since 2000, though I've not tested it on 2014 yet. I'd greatly appreciate it if you could give feedback.
Title: Re: (getvar 'dwgprefix) xref path
Post by: hyposmurf on August 12, 2013, 04:00:51 AM
Hypo,


Give the following code a try .. it appears to be working in AutoCAD 2014 :).

Code: [Select]
;; <08.09.2013> RJP updated code and tested on AutoCAD 2014
;; Obviously this writes to the registry so use at your own risk
;; Sets current drawing directory for XREF, ETRANSMIT, SHEETSET, SAVEAS, OPEN and PUBLISH commands
(defun writereg (/ dp hkcu id key)
  (if (= (getvar 'dwgtitled) 1)
    (progn (setq dp   (getvar 'dwgprefix)
hkcu (strcat "HKEY_CURRENT_USER\\" (vlax-product-key))
key  (strcat hkcu "\\Profiles\\" (getvar 'cprofile) "\\Dialogs\\")
id   "InitialDirectory"
   )
   (vl-registry-write (strcat hkcu "\\ETransmit\\Setups\\Standard\\") "Destfolder" dp)
   (vl-registry-write (strcat key "acad-131") id dp)
   (vl-registry-write (strcat key "BrowseropenDialog") id dp)
   (vl-registry-write (strcat key "OUTPUTFOLDERDLG") id dp)
   (vl-registry-write (strcat key "Save Drawing As") id dp)
   (vl-registry-write (strcat key "OpenSaveAnavDialogs") id dp)
   (vl-registry-write (strcat key "AcPublishDlg") "Location" dp)
   (vl-registry-write (strcat key "Sheet Set Wizard") "BrowseForLayoutsPath" dp)
   (vl-registry-write (strcat key "Sheet Set Wizard") "SheetSetCreatePath" dp)
   (vl-registry-write (strcat key "SSMNavigator") "OpenSheetSetPath" dp)
   (vl-registry-write (strcat key "SSMNavigator") "ImportLayoutsAsSheetsPath" dp)
    )
  )
  (princ)
)
(writereg)


(or *current-path-reactor*
    (setq *current-path-reactor* (vlr-command-reactor nil '((:vlr-commandwillstart . startcommand))))
)


(defun startcommand (calling-reactor startcommandinfo)
  (and (wcmatch (car startcommandinfo) "*XREF,XATTACH,ETRANSMIT,*SHEET*,PUBLISH,*SAVEAS*,OPEN")
       (writereg)
  )
)

Ronjop that routine seems to work!! Thanks you very much!  :-)
Title: Re: (getvar 'dwgprefix) xref path
Post by: ronjonp on August 12, 2013, 08:48:35 AM
Hypo,


Give the following code a try .. it appears to be working in AutoCAD 2014 :).

Code: [Select]
;; <08.09.2013> RJP updated code and tested on AutoCAD 2014
;; Obviously this writes to the registry so use at your own risk
;; Sets current drawing directory for XREF, ETRANSMIT, SHEETSET, SAVEAS, OPEN and PUBLISH commands
(defun writereg   (/ dp hkcu id key)
  (if (= (getvar 'dwgtitled) 1)
    (progn (setq dp   (getvar 'dwgprefix)
       hkcu (strcat "HKEY_CURRENT_USER\\" (vlax-product-key))
       key  (strcat hkcu "\\Profiles\\" (getvar 'cprofile) "\\Dialogs\\")
       id   "InitialDirectory"
      )
      (vl-registry-write (strcat hkcu "\\ETransmit\\Setups\\Standard\\") "Destfolder" dp)
      (vl-registry-write (strcat key "acad-131") id dp)
      (vl-registry-write (strcat key "BrowseropenDialog") id dp)
      (vl-registry-write (strcat key "OUTPUTFOLDERDLG") id dp)
      (vl-registry-write (strcat key "Save Drawing As") id dp)
      (vl-registry-write (strcat key "OpenSaveAnavDialogs") id dp)
      (vl-registry-write (strcat key "AcPublishDlg") "Location" dp)
      (vl-registry-write (strcat key "Sheet Set Wizard") "BrowseForLayoutsPath" dp)
      (vl-registry-write (strcat key "Sheet Set Wizard") "SheetSetCreatePath" dp)
      (vl-registry-write (strcat key "SSMNavigator") "OpenSheetSetPath" dp)
      (vl-registry-write (strcat key "SSMNavigator") "ImportLayoutsAsSheetsPath" dp)
    )
  )
  (princ)
)
(writereg)


(or *current-path-reactor*
    (setq *current-path-reactor* (vlr-command-reactor nil '((:vlr-commandwillstart . startcommand))))
)


(defun startcommand (calling-reactor startcommandinfo)
  (and (wcmatch (car startcommandinfo) "*XREF,XATTACH,ETRANSMIT,*SHEET*,PUBLISH,*SAVEAS*,OPEN")
       (writereg)
  )
)

Ronjop that routine seems to work!! Thanks you very much!  :-)


Glad to help out .. thanks for the prompt. This one has been bugging me for a bit :)>
Title: Re: (getvar 'dwgprefix) xref path
Post by: BlackBox on August 12, 2013, 09:57:18 AM
Give the following code a try .. it appears to be working in AutoCAD 2014 :).

FWIW -

As I understand it, newer products (2013+) use vlax-User-Product-Key... More info at the bottom of this post (http://www.theswamp.org/index.php?topic=42257.msg474024#msg474024).

Accessing the product key was changed in .NET API as well, as shown here (http://forums.autodesk.com/t5/NET/productkey-replacement-in-dot-net-4/td-p/3532628).

Cheers

Cheers
Title: Re: (getvar 'dwgprefix) xref path
Post by: ronjonp on August 12, 2013, 10:36:12 AM
Give the following code a try .. it appears to be working in AutoCAD 2014 :) .

FWIW -

As I understand it, newer products (2013+) use vlax-User-Product-Key... More info at the bottom of this post (http://www.theswamp.org/index.php?topic=42257.msg474024#msg474024).

Accessing the product key was changed in .NET API as well, as shown here (http://forums.autodesk.com/t5/NET/productkey-replacement-in-dot-net-4/td-p/3532628).

Cheers

Cheers


So does this mean that vlax-product-key is going to be retired at some point?
Title: Re: (getvar 'dwgprefix) xref path
Post by: BlackBox on August 12, 2013, 11:15:39 AM
Give the following code a try .. it appears to be working in AutoCAD 2014 :) .

FWIW -

As I understand it, newer products (2013+) use vlax-User-Product-Key... More info at the bottom of this post (http://www.theswamp.org/index.php?topic=42257.msg474024#msg474024).

Accessing the product key was changed in .NET API as well, as shown here (http://forums.autodesk.com/t5/NET/productkey-replacement-in-dot-net-4/td-p/3532628).

Cheers

Cheers


So does this mean that vlax-product-key is going to be retired at some point?

From the More on vlax-User-Product-Key (http://hyperpics.blogs.com/beyond_the_ui/2012/07/autolisp-api-changes-for-autocad-2013.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+BeyondTheUi+%28HyperPics%3A+Beyond+the+UI%29) link at the bottom of my original post:

Quote from: Hyperpics (aka Lee Ambrosius)

New Functions:
<snip>
VLAX-MACHINE-PRODUCT-KEY - Returns the AutoCAD product key from the Machine hive in the Windows Registry.  (ie. "Software\\Autodesk\\AutoCAD\\R19.0\\ACAD-B001:409")
VLAX-USER-PRODUCT-KEY - Returns the AutoCAD product keyfrom the User hive in the Windows Registry.  (ie. "Software\\Autodesk\\AutoCAD\\R19.0\\ACAD-B001:409")



Obsolete Functions:
VLAX-PRODUCT-KEY - While still supported, it is recommended to use the new function VLAX-MACHINE-PRODUCT-KEY instead which returns the same value.

... So as I understand it, while it is still supported, calls to vlax-Product-Key will result in the HKLM hive location, in lieu of the HKCU hive location (which is what we're after)... This is the reason for the simple if statement in my offering at the original post:

Code - Auto/Visual Lisp: [Select]
  1. (if vlax-user-product-key                                               ; If 2013+
  2.   (vlax-user-product-key)                                               ; Use new function
  3.   (vlax-product-key)                                                    ; Use legacy function
  4. )
  5.  
Title: Re: (getvar 'dwgprefix) xref path
Post by: ronjonp on August 12, 2013, 11:28:46 AM
Cool .. thanks.  :)
Title: Re: (getvar 'dwgprefix) xref path
Post by: BlackBox on August 12, 2013, 11:40:00 AM
Cool .. thanks.  :)

You're welcome; I'm happy to help.  :-)