Open from en Plot to current directory

I have been using this code to get open dwg's and print allways from the current working directory.
Could it work for BricsCAD as well?

        (progn
            (setq dp   (getvar 'dwgprefix)
                  hkcu (strcat "HKEY_CURRENT_USER\\" (vlax-product-key))   ; "Software\\Bricsys\\BricsCAD\\V20x64\\en_US\\"
                  key  (strcat hkcu
                               "\\Profiles\\"
                               (getvar 'cprofile)
                               "\\Default\\Dialogs\\"
                       )

;; <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 updatexrefpath (/ 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 "XattachFileDialog") id dp)
;;; (vl-registry-write (strcat key "Import File") 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)
;;;)

Comments

  • Similar code can work for BricsCAD. It is just that the information is stored under different keys. Just do some research in the registry and you should be able to solve this.

  • Hans Lammerts
    edited December 2019

    Thanks Roy, I don't want to break good stuff but you are right. I can figure out most parts myself.
    The biggest difference with this in AutoCAD is the missing of \userprofile\ part
    Some work but some don't seem to work.
    When i look at the value of XATTACH / initialdir it does not work with the button pushed.
    Neither when DWG is closed and re-opened. I don't understand the trigger.

  • Roy Klein Gebbinck
    edited December 2019

    By running the code in its current form you have added registry keys that BricsCAD does not use.
    On my machine (note: BricsCAD V18) the paths for the "2D Drafting" profile are stored under:
    HKEY_CURRENT_USER\Software\Bricsys\BricsCAD\V18x64\en_US\Profiles\2D Drafting\Recent Paths

  • So the code for BricsCAD can look like this:

    (defun c:PathsToDwgPath ( / key new nmeLst)
      (if
        (or
          (= 1 (getvar 'dwgtitled))
          (prompt "\nError: drawing not saved ")
        )
        (progn
          (setq nmeLst
            '(
              "Default"
              "Dwg"
              "Dxf"
              "ExportFile"
              "Insert"
              "Script"
              "Xref"
    
              ; Let's skip these:
              ; "BmInsert"
              ; "Dwt"
              ; "Font"
              ; "MECHCOMPONENTS"
              ; "SmReplace"
            )
          )
          (setq key (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (getvar 'cprofile) "\\Recent Paths"))
          (setq new (getvar 'dwgprefix))
          (foreach nme nmeLst
            (vl-registry-write key nme new)
          )
        )
      )
      (princ)
    )
    
  • Hans Lammerts
    edited December 2019

    Roy
    cprofile keeps being 'default' and seems to be something else then my 'BricsCAD profiles' in my instal (?).
    I don't have the BricsCAD profiles in my register. Thought i found the key for output of plotfiles. However, changing the value doesn't seem to have effect either:/

  • Roy Klein Gebbinck
    edited December 2019

    I see that I should have looked beyond the "Recent Paths" node. "PlotOutputPath" is actually a setting that can be changed with setvar.

    Revised code:

    (defun c:PathsToDwgPath ( / key new nmeLst varLst)
      (if
        (or
          (= 1 (getvar 'dwgtitled))
          (prompt "\nError: drawing not saved ")
        )
        (progn
          (setq new (getvar 'dwgprefix))
          ; _Etransmit:
          (vl-registry-write
            (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\eTransmit\\Standard")
            "DestFolder"
            new
          )
          ; _Publish:
          (vl-registry-write
            (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (getvar 'cprofile) "\\Dialogs\\DLG_PUBLISH")
            "Location"
            new
          )
          ; Recent paths:
          (setq key (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (getvar 'cprofile) "\\Recent Paths"))
          (setq nmeLst
            '(                 ; (*): If the command is used in a saved dwg the dwg's folder is used.
              "Default"        ; _Publish (initial folder) + _Settings (export).
              "Dwg"            ; _Open + _Save (*) + _SaveAs (*).
              "Dxf"            ; _DxfIn + _DxfOut (*).
              "ExportFile"     ; _Export (*).
              "Insert"         ; _Insert.
              "Script"         ; _Script.
              "Xref"           ; _Xref.
    
              ; Not used?:
              ; "Dwt"
    
              ; Skip:
              ; "BmInsert"
              ; "Font"
              ; "MECHCOMPONENTS"
              ; "SmReplace"
            )
          )
          (foreach nme nmeLst
            (vl-registry-write key nme new)
          )
          ; Variables:
          (setq varLst
            '(
              "PlotOutputPath"
    
              ; Not used?:
              ; "BlocksPath"
              ; "DrawingPath"
              ; "RecentPath"
              ; "TemplatePath" ; _New uses the folder of the BASEFILE.
    
              ; Skip:
              ; "SheetSetTemplatePath"
            )
    
    
          )
          (foreach var varLst
            (setvar var new)
          )
          (princ "\nDone! ")
        )
      )
      (princ)
    )
    
  • For Plot and Open it works!
    Xref or Xattach does work after an update of the regkey .
    That is strange.

    Computer\HKEY_CURRENT_USER\Software\Bricsys\BricsCAD\V20x64\en_US\Profiles\Default\Recent Paths\xref\

  • Roy Klein Gebbinck
    edited January 2020

    What does that mean: 'Update of the regkey'?. The code should change that registry value and in V18 the new value is used in the current CAD session.

  • The update works. Registery entry is being made.
    But using the BricsCAD pallette it still goes to my other (latest) used directory.
    Minor issue. Happy that open and plot works. Saves me tons of surfing time :)

  • That is strange. If I click the Xattach ('Attach Xref') button on the default 'Draw' tool palette the folder set with the code is used. Maybe this is version related. I still use V18.

  • In V19 and later, you have to modify the in-memory user profile values. Normally that can be done via lisp with (setenv) and (setvar), but I'm not sure if the (vl-registry-*) functions have been updated to modify the in-memory values.

  • Roy Klein Gebbinck
    edited January 2020

    Thanks for your comments Owen. From Hans's experience I conclude that the (vl-registry-*) function do not update the in-memory values. Using (setvar) or (setenv) is not an option as there is not variable for the xref path.

  • Maybe should do a trick like
    command -xattach
    Dwgprefix
    Escape / cancel or load "some air"
    ?
  • BRX and .NET have specific APIs that provide complete access to in-memory user profile values, so one avenue would be to use a helper function defined in a separate BRX or .NET module. I can think of a way to do it in lisp, but it's long-winded. There are COM methods to export and import profiles; you could export the current profile, modify the exported file, then import it again. It would not be an ideal user experience, but it should work.

  • Roy Klein Gebbinck
    edited January 2020

    It is a bit hard for me to test things as for many of the paths in the code V18 does not rely on 'in-memory' values. But focusing on the PlotOutputPath setting I find that using (vla-importprofile) and a modified arg/reg file does not work. The registry will show the new PlotOutputPath value, but BricsCAD does not use it. This may of course be different in V19 and V20.

  • Hans Lammerts
    edited January 2020
    In stead of registry method. Can this be done in a xattach way? The Vla-open part.

    Source: Autocad forum / c:ocd

    (vl-load-com)
    (defun c:xacd (/ dwgname)
    (if (setq dwgname (getfiled "select drawing file" (getvar "dwgprefix") "dwg" 0))
    (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) dwgname)) )
    (princ) )
  • Roy Klein Gebbinck
    edited January 2020

    Using (getfiled) can indeed be a solution:

    (defun c:Test ( / fnm)
      (if (setq fnm (getfiled "Select Reference File" (getvar 'dwgprefix) "dwg" 0))
        (progn
          (command "_.xattach" fnm)
          (while (/= 0 (getvar 'cmdactive)) (command pause))
        )
      )
      (princ)
    )
    
  • One challenge i have now is that the XREF palette is not automatically being updated for some reason.
    Either i have to give it a manual refresh or do open/close. The open / close command could be done within the lisp routine.
    However, i would be more beautiful if the palette would react in a automatic / dynamic way.

    See att.

  • That seems to be the wrong MP4. To use the getfiled solution from a palette you would have to either update the palette tool(s) or redefine the _Xattach command.

  • Yes it was the wrong upload. Here is the correct one.
    What i mean is that the XREF "palette" does not update.
    I see this as a little shortcoming.

  • That's a different topic. Suggest you send in a support request,

  • Hans Lammerts
    edited January 2020

    I got a couple of routines tweaked sofar.
    Like the 'getfiled' method better than editing the registry.

    The only problem i now have is the way multiple resources are being presented.
    The supported files should be presented as : "OR" resulting in either one of them.
    The way i did it now is fixed per choice. See att.

    (defun c:OP ( / fnm)
    
      (if (setq fnm (getfiled "Select DWG or DXF File" (getvar 'dwgprefix) "dwg,dxf" 0))
        (progn
          (command "OPEN" fnm)
          (while (/= 0 (getvar 'cmdactive)) (command pause))
        )
      )
      (princ)
    )
    
    (defun c:IM ( / fnm)
    
      (if (setq fnm (getfiled "Select image File" (getvar 'dwgprefix) "bmp,jpg,jpeg,pcx,png,gif,tga,tif,tiff,jp2,jp2,j2k,ecw,sid,mti" 0))
        (progn
          (command "imageattach" fnm)
          (while (/= 0 (getvar 'cmdactive)) (command pause))
        )
      )
      (princ)
    )
    
    (defun c:PC ( / fnm)
      (setq getworlducs (getvar "worlducs"))
      (if (= getworlducs 1)
        ()
        (progn
          (alert "Not in UCS WORLD!")
          (initget "y n")
          (setq blkflg (getkword "\n.. set to WCS ?   Y/N <Y>: "))
          (if (= blkflg "n")
        ()
        (command "ucs" "world")
          )
        )
      )
      (if (setq fnm (getfiled "Select pointcloud File" (getvar 'dwgprefix) "las,pts,ptx,rcp,rcs" 0))
        (progn
          (command "pointcloudattach" "file" fnm)
          (while (/= 0 (getvar 'cmdactive)) (command pause))
        )
      )
      (princ)
    )
    
    
    (defun c:XA ( / fnm)
      (setq getworlducs (getvar "worlducs"))
      (if (= getworlducs 1)
        ()
        (progn
          (alert "Not in UCS WORLD!")
          (initget "y n")
          (setq blkflg (getkword "\n.. set to WCS ?   Y/N <Y>: "))
          (if (= blkflg "n")
        ()
        (command "ucs" "world")
          )
        )
      )
      (if (setq fnm (getfiled "Select Reference File" (getvar 'dwgprefix) "dwg" 0))
        (progn
          (command "_.xattach" fnm)
          (while (/= 0 (getvar 'cmdactive)) (command pause))
        )
      )
      (princ)
    )
    
  • If you want to have files with several extensions listed together you can use the (dos_getfiled) or the (dos_getfilem) DOSLib functions. The (dos_getfilem) function is built-in but actually intended for the selection of multiple files.

  • Hans Lammerts
    edited January 2020
    Thanks Roy!
    I figured out the *,.. notation works as "all files"
    "*,bmp;jpg;jpeg;pcx;png;gif;tga;tif;tiff;jp2;jp2;j2k;ecw;sid;mti"
  • Roy Klein Gebbinck
    edited January 2020

    Using "*" here is not ideal IMO.

    You can also change the 4th argument:
    (getfiled "Select DWG or DXF File" (getvar 'dwgprefix) "dwg,dxf" 4)