View Full Version : Use Relative Paths when inserting Blocks via LISP
TSqwear
2007-04-26, 12:19 AM
We use a lisp routine to set the 'drawing scale' (text style, height, dimstyle, etc.) that I would like to share w/ a drafting service we've started to use. However, we have some fixed paths to the drawings that support the routine...here's an excerpt:
(defun C:db48()
(command "-insert" "ADTdimblock1=S:/cga-cadlibrary/dimblock1")
(COMMAND /e "Resume")
(command "-insert" "_Dot=S:/cga-cadlibrary/_Dot")
(COMMAND /e "Resume")
(command "-dimstyle" "r" "CGA_Standard")
(command "dimscale" "48")
(command "-style" "dimension" "archstyl.shx" "0" "" "" "" "")
(command "-style" "Room_Title" "Times.ttf" "6" "" "" "" "")
(command "-style" "annotation" "archstyl.shx" "4.5" "" "" "" "")
(command "-layer" "s" "A-Anno-Dims" "")
)
For example, can I repath the
"ADTdimblock1=S:/cga-cadlibrary/dimblick1"
to
"ADTdimblock1=.../cga-cadlibrary/dimblock1"
so when I send the lisp file and the support DWG files, all the consultant needs to do is create a sub-directory in the working directory called 'cga-cadlibrary' and place the support DWG's there???
kennet.sjoberg
2007-04-26, 06:49 AM
Yes an No
Yes you can, but you have to think old DOS
step up one level cd ..
step up two levels cd ../..
step up tree levels cd ../../..
and point to the file ../../../_Dot.dwg
so this would replace the dot in your drawing
(command "-insert" "_Dot=../../_Dot.dwg" )
But No the relative path referee to the "current directory" and that is not necessary where you are right now, and it also depends on how you started your drawing.
So I would recommend an absolute path to the library file.
Or put the _Dot.dwg in AutoCADs Support File Search Path
(command "insert" "_Dot=_Dot" nil )
: ) Happy Computing !
kennet
Terry Cadd
2007-04-26, 03:41 PM
Regarding paths in AutoLISP code, I've included the following line in our AcadDoc.lsp file to setq the *AcadPath$ global variable, which is used throughout the programs. The code, blocks, and supporting files and sub-folders can be copied to a CD or other computer or server and still function the same. All that is needed is to map the folder location of one unique filename in your Support File Search Path. The file AutoLISP.lsp can be replaced with one of your own unique filenames. None of the drive paths in the code are hard coded.
(setq *AcadPath$ (strcat (vl-filename-directory (findfile "AutoLISP.lsp")) "\\"))
Returns a pathname similar to: "E:\\Engineering\\AutoCAD\\"
Here are a few examples of how it is incorporated in the code.
(command "INSERT" (strcat *AcadPath$ "Blocks\\Borders\\11x17") "0,0" "1" "" "0" ...
(setq SlideName$ (strcat *AcadPath$ "Blocks\\AnchorBolts\\" Choice$ ".sld"))
(command "INSERT" (strcat *AcadPath$ "Blocks\\Symbols\\BUB") Pt Scale~ "" 0 Num$)
(setq BlockName$ (strcat *AcadPath$ "Blocks\\Symbols\\" BlockName$ ".dwg"))
(command "INSERT" (strcat Border$ "=" *AcadPath$ "Blocks\\Borders\\" Border$)
(setq DataFile$ (strcat *AcadPath$ "WideFlange\\WideFlange.dat"))
(startapp (strcat *AcadPath$ "Programs\\Convert.exe"))
(setq XlsFileName$ (strcat *AcadPath$ "Excel\\CamberCalcs.xls"))
This was very easy to setup here at work, as I set everything up from scratch. However, the concept can be a nightmare to implement if the code, blocks, and supporting files are stored all over the place.
kennet.sjoberg
2007-04-26, 06:39 PM
. . . Returns a pathname similar to: "E:\\Engineering\\AutoCAD\\"
...Ooops Terry, where is the Relative Path ?
: ) Happy Computing !
kennet
abdulhuck
2007-04-29, 11:51 AM
(getvar "localrootprefix")
; Will return "C:\\Documents and Settings\\<login name>\\Local Settings\\Application Data\\Autodesk\\AutoCAD 2005\\R16.1\\enu\\"
(getvar "roamablerootprefix")
; Will return "C:\\Documents and Settings\\<login name>\\Application Data\\Autodesk\\AutoCAD 2005\\R16.1\\enu\\"
(getvar "mydocumentsprefix")
; Will return "C:\\Documents and Settings\\<login name>\\My Documents"
(getvar "tempprefix")
; Will return "C:\\Documents and Settings\\<login name>\\Local Settings\\Temp\\"
(setq AcadFolder (vl-registry-read (strcat "HKEY_LOCAL_MACHINE\\" (vlax-product-key)) "ACADLOCATION"))
; Will return your AutoCAD product installation path, for example "C:\\Program Files\\AutoCAD 2006"
You can use any of the relative path above, or use any portion of the above path as below:
(setq drive (substr (getvar "localrootprefix") 1 3))
; Will return "C:\\"
Now, you may define your folder as below
(setq CADLibPath (strcat AcadFolder "\\cga-cadlibrary\\"))
(setq dimblock (strcat CADLibPath "dimblock.dwg")
So that you can advise your consultants to copy "cga-cadlibrary" to their AutoCAD folder.
Regards,
Abdul Huck
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.