Author Topic: Trouble with LISP file location  (Read 2696 times)

0 Members and 1 Guest are viewing this topic.

aflett74

  • Guest
Trouble with LISP file location
« on: May 04, 2017, 08:14:16 PM »
I have scrounged up a code that allows me to insert a particular block on a particular drawing using ObjectDBX. For some reason, I have to use the full address of the file in order for the LISP to retrieve the block. My intention is to set up a simple database for field laptops to use our blocks and thus the address of the file will most likely vary for each laptop. For that reason, I would prefer the LISP look in the support file path (easy enough for me to set that up when I prepare the new laptops). I am by no means an adequate LISP writer but I can typically figure these things out, any help would be appreciated.
Code: [Select]

;; (copy-blk  "T:\\ACLAND\\2016\\Next_Gen\\APENDIX.dwg" "NORTH");;;;;;
;; return T if successful, nil otherwise;;;;;;;;;;

(vl-load-com)
(defun copy-blk (dwg blk / blkdbx catch odbx)
  (if (findfile dwg)
    (progn
      (if (< (atoi (substr (getvar "ACADVER") 1 2)) 16)
        (setq odbx (vlax-create-object "ObjectDBX.AxDbDocument"))
        (setq odbx (vlax-create-object
                     (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2))
                   )
        )
      )
      (vla-open odbx dwg)
      (if (not
            (setq
              catch (vl-catch-all-error-p
                      (vl-catch-all-apply
                        (function (lambda () (setq blkdbx (vla-item (vla-get-blocks odbx) blk))))
                      )
                    )
            )
          )
        (vla-copyobjects
          odbx
          (vlax-safearray-fill
            (vlax-make-safearray vlax-vbObject '(0 . 0))
            (list blkdbx)
          )
          (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
        )
      )
      (vlax-release-object odbx)
      (if (and (null catch)
               (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
                         blk
               )
          )
        T
        nil
      )
    )
    nil
  )
)


Edit: help I'm just a Mosquito!!!! haha

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Trouble with LISP file location
« Reply #1 on: May 05, 2017, 01:52:38 AM »
You could just add to the support paths using the ACAD environment variable (this gets saved into registry so you only need do it once on each machine). E.g. http://www.lee-mac.com/addremovesupportpaths.html

After that you can use FindFile to get the full path if you so wish.

Otherwise, just save the folder into an environment variable of your own using the setenv function. I.e. add the blocks into any path you wish, then use setenv to save a registry setting to remember where it is. After which use getenv with the same name you gave that variable to obtain the path. I would suggest this route instead of adding onto the support folders - if those get very long and/or full it impacts on performance, not to mention there's a limit on how long the ACAD variable's contents can be.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

aflett74

  • Guest
Re: Trouble with LISP file location
« Reply #2 on: May 05, 2017, 11:36:54 AM »
You could just add to the support paths using the ACAD environment variable (this gets saved into registry so you only need do it once on each machine). E.g. http://www.lee-mac.com/addremovesupportpaths.html

After that you can use FindFile to get the full path if you so wish.

Otherwise, just save the folder into an environment variable of your own using the setenv function. I.e. add the blocks into any path you wish, then use setenv to save a registry setting to remember where it is. After which use getenv with the same name you gave that variable to obtain the path. I would suggest this route instead of adding onto the support folders - if those get very long and/or full it impacts on performance, not to mention there's a limit on how long the ACAD variable's contents can be.

K I have no clue how to do the latter but I will give it a search. It sounds like I would have to save everything to a basic directory... like C:// something-something then add a routine that adds that directory to other machines and uses the data (menu files LISP files DWG's etc...) from there.

I was really hoping to utilize our hybrid cloud server to allow me to make changes to all the computers menu and block databases by just changing the files at the office here and the files would sync to their laptops. the synced folders are already in place under the user directories (so different for everyone).

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Trouble with LISP file location
« Reply #3 on: May 05, 2017, 12:11:14 PM »
Assuming they are in the same folders under the user profile, you can use this code in cad to get the correct location: (getenv "userprofile")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Trouble with LISP file location
« Reply #4 on: May 07, 2017, 09:15:38 PM »
You can add paths etc via lisp much easier than doing one by one. Have you path order set so it looks in c:\.... before the network g:\....

here is a simple example of a laptop setup lisp. Note the strcat to add exsiting paths and new hence two disk drives.
Code: [Select]
; This sets paths for Geoffs local computer
; the gets are their for info maybe other use

(vl-load-com)
; make temp directory
;(vl-mkdir "c:\\ACADTEMP")

(setq *files*  (vla-get-files  (vla-get-preferences (vlax-get-acad-object))))

; savepath
;(vla-get-AutoSavepath *files*)
(vla-put-AutoSavepath *files* "C:\\ACADTemp")

; custom icons
;(vla-get-CustomIconPath *files*))
(vla-put-CustomIconPath *files* "C:\\Autodesk\\ICONS")

; printers config
;(vla-get-PrinterConfigPath *files*)
(vla-put-PrinterConfigPath *files* "C:\\AutoDESK\\Plotting\\Plot Styles 2011")

; printers style sheet
;(vla-get-PrinterStyleSheetPath *files*)
(vla-put-PrinterStyleSheetPath *files* "C:\\AutoDESK\\Plotting\\Plot Styles")

; printer drv's
;(vla-get-PrinterDescPath *files*)
(vla-put-PrinterDescPath *files* "C:\\AutoDESK\\Plotting\\Drv")

; print spooler
;(vla-get-PrintSpoolerPath *files*)
(vla-put-PrintSpoolerPath *files* "C:\\ACADTemp\\")

; template location
;(vla-get-QnewTemplateFile *files*)
(vla-put-QnewTemplateFile *files* "C:\\Autodesk\\c3d Templates\\xxxx.dwt")

;make new support paths exist + new
(setq paths (vla-get-SupportPath *files*))
 
 (setq xxxxpaths
  "C:\\autodesk\\supportfiles;
  C:\\autodesk\\lisp;
  C:\\autodesk\\fonts;
  C:\\autodesk\\hfs fonts;"
  )

(setq newpath (strcat xxxxpaths paths))
(vla-put-SupportPath *files* newpath)

; Tempdirectory
;(vla-get-TempFilePath *files*))
(vla-put-TempFilePath *files* "C:\\ACADTemp\\")

; template  path
;(vla-get-TemplateDwgPath *files*)
(vla-put-TemplateDwgPath *files* "C:\\Autodesk\\c3d Templates")

; xref temp path
;(vla-get-TempXrefPath *files*))
(vla-put-TempXrefPath *files* "C:\\ACADTemp\\")

; end use of *files*
(vlax-release-object *files*)

; exit quitely
(princ "All Done")
A man who never made a mistake never made anything