msweeney Posted February 2, 2010 Share Posted February 2, 2010 I have an existing LISP routine for Acad r14 and I'm trying to convert it to Acad 2008, but I have no clue what I'm doing. It asks for a drawing number, then looks through a text database (path2.txt) of different file locations. Once it finds the file in one of those locations it opens it. Real simple, but the open command seems to work differently than it did in r14. The routine seems to work fine until it actually gets to the open command, then it stops. Any help would be greatly appreciated. Thanks, Mark (defun C:find1test () (setq a "") (setq b "") (setq test "") (setq dwg "") (setq f "") (setq dwg (getstring T "\nEnter drawing name:")) ;pauses for user response (command "pan" "0,0" "0,.001") (setq ext ".dwg") (setq c (strcat "l:/users/none/" dwg ext)) (setq f (open "l:/apps/acad/path2.txt" "r")) ;opens text file to read. (while (/= T test) ;loop through until nil response. (setq a (read-line f)) ;reads first line of open text file. (setq b (strcat a dwg ext)) (setq test (or (findfile b))) (if (= b c) (progn (setq tt1 (strcat "DRAWING \"" dwg "\" NOT FOUND!!")) (alert tt1) (exit) ) ) ) (close f) ;closes the open text file. (setq y (getstring "\nHey do you want to save changes? [Y] yes or [ENTER] no ")) (if (or (= y "Y") (= y "y")) (command "qsave" "open" b)(command "open" "y" b)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 2, 2010 Share Posted February 2, 2010 Perhaps something like this? (defun C:find1test (/ GetPaths dwg file) (vl-load-com) (defun GetPaths (fname / file line lst) (cond ( (not (and (setq fname (findfile fname)) (setq file (open fname "r"))))) ( (while (setq line (read-line file)) (setq lst (cons line lst))) (close file))) (reverse lst)) (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (if (not (zerop (strlen (setq dwg (getstring t "\nEnter Drawing Name: "))))) (if (setq file (vl-some (function (lambda (x) (findfile (strcat x dwg ".dwg")))) (GetPaths "l:/apps/acad/path2.txt"))) (progn (initget "Yes No") (if (/= "No" (getkword "\nSave Changes? <Yes> : ")) (if (eq "" (vla-get-fullname *doc)) (vla-saveas *doc (strcat (vla-get-Path *doc) (vla-get-Name *doc))) (vla-save *doc))) (vla-Activate (vla-open (if (zerop (getvar 'SDI)) (vla-get-Documents (vlax-get-acad-object)) *doc) file :vlax-false))) (princ "\n** Drawing not Found **"))) (princ)) Quote Link to comment Share on other sites More sharing options...
msweeney Posted February 3, 2010 Author Share Posted February 3, 2010 Thanks so much for rewriting this for me. I replaced it with the existing routine, but I'm getting the same results. It seems to grab the drawing number from the correct directory, but it uses the filename and location as a command rather than a file to open. Here is the sequence from the command window: (I renamed the routine find-2008.lsp) Command: find-2008 Initializing... Enter Drawing Name: 0809635 Save Changes? : _.open Command: L:\drawings\part-0809\0809635.dwg Unknown command "L:\DRAWINGS\PART-0809\0809635.DWG". Press F1 for help. Command: Any ideas on how to correct this? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 3, 2010 Share Posted February 3, 2010 Believe it or not, I have never actually used Open in this way, so this is new ground for me, but that said, I have updated the above code, could you give it a try. If that doesn't work, I have one more idea Quote Link to comment Share on other sites More sharing options...
msweeney Posted February 3, 2010 Author Share Posted February 3, 2010 Same result as the first. Very strange. But I really appreciate the help. It just doesn't know to use the file name as the thing to open. Although, it is finding the drawing in the proper directory - so that much is working. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 3, 2010 Share Posted February 3, 2010 Its good to know that its finding the file ok Code updated once more - using a different opening method. Quote Link to comment Share on other sites More sharing options...
msweeney Posted February 3, 2010 Author Share Posted February 3, 2010 HEY! It works! Thank you so much. I guess we both learned something today. Well, you learned something. I'm going to have to study your code a lot before I fully get it. I'm very new to LISP, and have just minimal VBA experience. Put this one in your toolbar for sure. It's nice to not have to look for drawings all over the network - you never know if somebody else saved a drawing in the wrong location. Thanks again, Mark Quote Link to comment Share on other sites More sharing options...
msweeney Posted February 3, 2010 Author Share Posted February 3, 2010 Ok, one small glitch. If you have more than one drawing open, it doesn't make the newest open drawing the current drawing. It opens the file, then reverts back to the previous drawing. Any way to open it and make it the active file? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 3, 2010 Share Posted February 3, 2010 Code updated again - hopefully this should make it current Put this one in your toolbar for sure. It's nice to not have to look for drawings all over the network - you never know if somebody else saved a drawing in the wrong location.Just a programmer I'm afraid - I have no use for any of the codes I create... - I just enjoy the coding Quote Link to comment Share on other sites More sharing options...
msweeney Posted February 3, 2010 Author Share Posted February 3, 2010 That did it. Thanks again. I will definitely be coming back to this site whenever I need help. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 3, 2010 Share Posted February 3, 2010 That did it. Thanks again. I will definitely be coming back to this site whenever I need help. You're welcome Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.