lemacs Posted December 2, 2010 Share Posted December 2, 2010 I am looking for a command that would open the NEXT drawing in a folder. Example: You have file A.dwg you just type "open-next" it opens B.dwg You have file C.dwg you just type "open-next" it opens D.dwg, and so on. Thanks in advance Quote Link to comment Share on other sites More sharing options...
CADkitt Posted December 6, 2010 Share Posted December 6, 2010 You can read the filename with: (vl-filename-base (getvar 'dwgname)) You then could make a if/else routine with if filename=A.dwg then open B.dwg. With (setq str1 (strcat (vl-filename-base (getvar 'dwgname)))) [b](setq str4(substr str1 5 )[/b] You can remove certain letters from your filename. And then mold it together with: (setq str8 (strcat "blablabla" str4 "-" str6)) I'm not that good (like some here) that I can make the code in 5 minutes But I think it is a good lisp to learn autolisp because it is not to complicated. (so try it yourself!) Quote Link to comment Share on other sites More sharing options...
lemacs Posted December 6, 2010 Author Share Posted December 6, 2010 Thanks for the replay, I not good at all with lisp but i will give it a try, I can edit them to do what I need that is about as far as I can go. Quote Link to comment Share on other sites More sharing options...
irneb Posted December 6, 2010 Share Posted December 6, 2010 Maybe something like this (untested): (vl-load-com) (defun c:Open-Next (/ path files-list files DocCol item n) (setq path (getvar "DWGPREFIX") ;Get the current DWG's path DocCol (vla-get-Documents (vlax-get-acad-object)) ;Get the ActiveX collection of open DWG's n 0 ) (if (and (setq files-list (vl-bb-ref 'Open-Next-List)) ;Check if Open-Next has been used before (setq files (assoc path files-list)) ;If so has it been used on this folder? ) ;; Then (setq files (cdr files)) ;Remove the path prefix of the list ;; Else (setq files (vl-directory-files path "*.DWG" 1)) ;Get the files in this directory ) (while (and (< n (length files)) (or (not (eq (strcase (getvar "DWGNAME")) (strcase (nth n files)))) ;Check that not the current DWG (and (setq item (vl-catch-all-apply 'vla-Item (list DocCol (nth n files)))) ;Check if one of the other opened (not (vl-catch-all-error-p item)) ;Check if error ) ) ) (if (and item (not (vl-catch-all-error-p item))) ;If another DWG (vla-Close item) ) (setq n (1+ n) item nil) ;Increment counter ) (if (setq item (assoc path files-list)) ;If already in list ;; Then (setq files-list (subst (cons path files) item files-list)) ;Replace with the new set of files ;; Else (setq files-list (cons (cons path files) files-list)) ;Add the current folder & files list ) (vl-bb-set 'Open-Next-List files-list) (if (< n (length files)) (vl-cmdf "_.OPEN" (strcat "\"" path (nth n files) "\"")) ) (princ) ) (defun Open-Next-Cleanup (/ files-list files path DocCol) (setq path (getvar "DWGPREFIX") ;Get the current DWG's path DocCol (vla-get-Documents (vlax-get-acad-object)) ;Get the ActiveX collection of open DWG's n 0 ) (if (and (setq files-list (vl-bb-ref 'Open-Next-List)) (setq files (assoc path files-list)) ) (while (or (not (eq (strcase (getvar "DWGNAME")) (strcase (car files)))) ;Check that not the current DWG (and (setq item (vl-catch-all-apply 'vla-Item (list DocCol (car files)))) ;Check if one of the other opened (not (vl-catch-all-error-p item)) ;Check if error ) ) (if (and item (not (vl-catch-all-error-p item))) ;If another DWG (vla-Close item) ) (setq files (cdr files) item nil) ) ) (if (setq item (assoc path files-list)) ;If already in list ;; Then (setq files-list (subst (cons path files) item files-list)) ;Replace with the new set of files ;; Else (setq files-list (cons (cons path files) files-list)) ;Add the current folder & files list ) (vl-bb-set 'Open-Next-List files-list) ) (if (and s::startup (= (type s::startup) 'LIST)) (setq s::startup (append s::startup (list (Open-Next-Cleanup)))) (defun-q s::startup () (Open-Next-Cleanup) ) ) Needs to be copied to your ACADDOC.LSP file so it clears the list as new drawings are opened. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 6, 2010 Share Posted December 6, 2010 Nice idea to use the blackboard namespace Irne, nice coding Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 6, 2010 Share Posted December 6, 2010 I might approach it this way: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:open-next [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] dwg doc docs f [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac 2010[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] dwg [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]member[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=DARKRED]'[/color][/b]DWGNAME[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] f [b][color=RED]([/color][/b][b][color=BLUE]vl-sort[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-directory-files[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=DARKRED]'[/color][/b]DWGPREFIX[b][color=RED])[/color][/b] [b][color=#a52a2a]"*.dwg"[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]<[/color][/b][b][color=RED]))[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] f[b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-Activate[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-error-p[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] doc [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-apply[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vla-item[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] docs [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Documents[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])))[/color][/b] dwg[b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] doc [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-open[/color][/b] docs [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=DARKRED]'[/color][/b]DWGPREFIX[b][color=RED])[/color][/b] dwg[b][color=RED]))[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] Quote Link to comment Share on other sites More sharing options...
lemacs Posted December 6, 2010 Author Share Posted December 6, 2010 While trying to use your Code irned, I get this error: ; error: Automation Error. Drawing is busy. Quote Link to comment Share on other sites More sharing options...
lemacs Posted December 6, 2010 Author Share Posted December 6, 2010 WOW, Lee Mac that seemed to work great Quote Link to comment Share on other sites More sharing options...
lemacs Posted December 6, 2010 Author Share Posted December 6, 2010 So if i just change: (setq f (vl-sort (vl-directory-files (getvar 'DWGPREFIX) "*.dwg" 1) ' to (setq f (vl-sort (vl-directory-files (getvar 'DWGPREFIX) "*.dwg" 1) '>)) It will open the previous drawing, I gave it a try and it worked. Quote Link to comment Share on other sites More sharing options...
CADkitt Posted December 6, 2010 Share Posted December 6, 2010 This isn't coding this is black magic Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 6, 2010 Share Posted December 6, 2010 WOW, Lee Mac that seemed to work great Excellent - glad it worked for you Quote Link to comment Share on other sites More sharing options...
irneb Posted December 7, 2010 Share Posted December 7, 2010 I might approach it this way:Awesome! I think I went too far . Yours is simple and straightforward, without needing to fiddle around with a saved list. The thing is, I was trying to "close" the current drawing as well - otherwise you could end up with all the DWGs in the folder open at the same time (which may be an extreme memory hog). That's why you get that error. But that's also why I needed to save a list and then run the cleanup routine on drawing open. I suppose a change to the SDI sysvar could fix that, but would cause other problems. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 7, 2010 Share Posted December 7, 2010 Awesome! I think I went too far . Yours is simple and straightforward, without needing to fiddle around with a saved list. Thanks Irne - but yours is good for those looking to learn how to manipulate data stored in the blackboard namespace. The thing is, I was trying to "close" the current drawing as well - otherwise you could end up with all the DWGs in the folder open at the same time (which may be an extreme memory hog). That's why you get that error. But that's also why I needed to save a list and then run the cleanup routine on drawing open. I suppose a change to the SDI sysvar could fix that, but would cause other problems. I did consider the case of having all the drawings open, but I didn't want to involve any closing of drawings as you would have to deal with whether or not to save changes etc, and I wouldn't want to chance losing any of the user's work. Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 7, 2010 Share Posted December 7, 2010 Plus, if SDI mode is something other than zero, you can't just close the drawing. 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.