Author Topic: Relative paths  (Read 580 times)

0 Members and 1 Guest are viewing this topic.

PKENEWELL

  • Bull Frog
  • Posts: 241
Re: Relative paths
« Reply #15 on: October 20, 2020, 03:41:12 PM »
Here is a new version of the batch import routine, using some ideas from kpblc and adding my own.

I added in a check at the beginning to make sure the user is in a new, blank drawing. I also made a choice at the end to close AutoCAD completely, or just close the open drawing.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:MicroStationToAutoCAD (/ acd doc *error* fil fn pth oecho odgn resp tx1 tx2 tx3 tx4 tx5)
  2.    
  3.    (defun *error* (msg)
  4.       (if (not (wcmatch (strcase msg T) "*break*,*cancel*,*quit*,*exit*"))
  5.          (princ (strcat "\nError: " msg "\n"))
  6.          (princ "\nProgram Aborted.\n")
  7.       )
  8.       (setvar "cmdecho" oecho)
  9.       (setvar "dgnimportmode" odgn)
  10.       (setvar "nomutt" omut)
  11.    )
  12.    
  13.    (setq fn "list.txt"
  14.          tx1 (findfile fn)
  15.          tx4 "Default"
  16.          oecho (getvar "cmdecho")
  17.          odgn (getvar "dgnimportmode")
  18.          omut (getvar "nomutt")
  19.          acd (vlax-get-acad-object)
  20.          doc (vla-get-activedocument acd)
  21.    )
  22.    (setvar "cmdecho" 0)
  23.    (setvar "dgnimportmode" 1)
  24.    
  25.    (if (not tx1)
  26.       (princ "\nList file not found! Check the support paths. ")
  27.       (progn
  28.          (setq pth (vl-filename-directory tx1)
  29.                tx2 (strcat pth "\\in\\")
  30.                tx3 (strcat pth "\\out\\")
  31.          )
  32.          (initget "Yes No")
  33.          (if (= (setq resp (getkword (strcat "\nFile List \"" fn "\" found. You should be in a new drawing to begin conversion. Proceed [Yes/No] <Yes>: "))) "No")
  34.             (setq pth nil)
  35.          )
  36.       )
  37.    )
  38.    (if pth
  39.       (progn
  40.          (setq fil (open tx1 "r")
  41.                tx5 (read-line fil)
  42.          )
  43.          (princ (strcat "\nConverting Files in " fn "> ="))
  44.          (setvar "nomutt" 1)
  45.          (while tx5
  46.             (if (and (wcmatch (strcase tx5) "*`.DGN")
  47.                      (findfile (strcat tx2 tx5))
  48.                 )
  49.                (progn
  50.                   (setq tx5 (vl-filename-base tx5))
  51.                   (command "._UNDO" "_MARK"
  52.                            "._-DGNIMPORT" (strcat tx2 tx5) tx4
  53.                   )
  54.                   (while (= (logand (getvar "cmdactive") 1) 1) (command ""))
  55.                   (vla-zoomall acd)
  56.                   (vla-saveas doc (strcat tx3 tx5 ".dwg") ac2013_dwg)
  57.                   (command "._UNDO" "_BACK")
  58.                   (if (= (logand (getvar "cmdactive") 1) 1)(Alert "Something Did not process correctly in this drawing.\nVerify the command sequence."))
  59.                   (princ "=")
  60.                )
  61.                (princ (strcat "\n file \"" tx5 "\" not found. File does not exist or filename is incorrect in \"" fn "\". Skipping file."))
  62.             )
  63.             (setq tx5 (read-line fil))
  64.          )
  65.          (close fil)
  66.          (princ " Conversion Completed! ")
  67.          (setvar "nomutt" omut)
  68.          (initget "Yes No")
  69.          (if (or (= (setq resp (getkword "\nDo you want to quit AutoCAD? [Yes/No] <Yes>: ")) "Yes")(= resp ""))
  70.            (command "._QUIT" "_Y")
  71.            (command "._CLOSE" "_y")
  72.          )
  73.       )
  74.    )
  75.    (setvar "cmdecho" oecho)
  76.    (setvar "dgnimportmode" odgn)
  77.    (princ)
  78. )
  79.  

EDIT: Added even more checks in the program, including testing if the file exists and is in fact a DGN file.
« Last Edit: October 20, 2020, 04:37:31 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

like_citrus

  • Newt
  • Posts: 32
Re: Relative paths
« Reply #16 on: October 21, 2020, 12:03:36 AM »
Thanks very much PKENEWELL, this works now.
I think your previous shorter version works as well.

Long story, but the issue was with the text file, as I discovered having issues with the initial code, once working, then not. It took me a while to figure it out. I was using Excel to dump the drawing list data into the text file and AutoCAD didn't seem to accept it.
Initially I tried the latest code, that did not work, then after working out the issue, your code did work and the previous shorter version seems to work as well.

Sorry if this wasted your time, but it may be useful for someone else.

PKENEWELL

  • Bull Frog
  • Posts: 241
Re: Relative paths
« Reply #17 on: October 21, 2020, 09:22:36 AM »
Thanks very much PKENEWELL, this works now.
I think your previous shorter version works as well.

Long story, but the issue was with the text file, as I discovered having issues with the initial code, once working, then not. It took me a while to figure it out. I was using Excel to dump the drawing list data into the text file and AutoCAD didn't seem to accept it.
Initially I tried the latest code, that did not work, then after working out the issue, your code did work and the previous shorter version seems to work as well.

Sorry if this wasted your time, but it may be useful for someone else.

No Problem Like_Citrus.  :-D I enjoyed playing with the program and trying to make it better! There is still more that could be done, but I like how this works.

Examples of improvements:
  • Store the name of the file list and the paths in the registry.
  • Add a DCL configuration interface to change saved values for above.
  • Create folders if they don't exist.
  • Eliminate the file list and just use (vl-directory-files) to get the list of files to import.

I might look back on these and add features if I have time.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt