vernonlee Posted March 22, 2015 Posted March 22, 2015 Anyone has a LISP that will zoom to a specific location for all opening drawings base on one of the open drawings? Meaning 1) I open drawing 1,drawing 2.........drawing 100. 2) In drawing 1, I have zoom to a specifc location. From here I would like to activite a LISP for drawing 2 to drawing 100 to zoom to the same location. In addition, any subsequent drawing that opens will also zoom to the same location until i deactivate the LISP. Thanks Quote
vernonlee Posted March 22, 2015 Author Posted March 22, 2015 Hint:'Viewsize 'Screensize vl-propagate Thanks. Will search more on this. Quote
marko_ribar Posted March 22, 2015 Posted March 22, 2015 (edited) If pBe could point us in right direction how to do this automatically - with (vla-activate)... The problem is that when new document is activated CAD jumps to it and continue evaluation of lisp in started document - not in switched - new one... Only I could compose is this lines, but actually if you have 100 DWGs, you have to do it manually 100 times... So if someone knows something we are missing here, show some light on us... (defun c:setcurrentviewtoalldwgs ( / v c uo ux uy vd pe ) (setq v (getvar 'viewsize) c (getvar 'viewctr)) (setq uo (trans '(0.0 0.0 0.0) 1 0)) (setq ux (trans '(1.0 0.0 0.0) 1 0)) (setq uy (trans '(0.0 1.0 0.0) 1 0)) (if (eq (getvar 'cvport) 1) (progn (mapcar 'vl-propagate (list 'v 'c 'uo 'ux 'uy)) (setq fn (open "c:/processdoc.lsp" "w")) (write-line "(vl-load-com)" fn) (write-line "(setq d (vla-get-activedocument (vlax-get-acad-object)))" fn) (write-line "(vla-regen d acactiveviewport)" fn) (write-line "(if" fn) (write-line "(not" fn) (write-line "(and" fn) (write-line "(equal uo '(0.0 0.0 0.0))" fn) (write-line "(equal ux '(1.0 0.0 0.0))" fn) (write-line "(equal uy '(0.0 1.0 0.0))" fn) (write-line ")" fn) (write-line ")" fn) (write-line "(progn" fn) (write-line "(setq ucs (vla-add (vla-get-usercoordinatesystems d) (vlax-3d-point uo) (vlax-3d-point ux) (vlax-3d-point uy) \"{ UCS }\"))" fn) (write-line "(vla-put-activeucs d ucs)" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line "(vla-delete ucs)" fn) (write-line "(command \"_.UCS\" \"_P\")" fn) (write-line ")" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line ")" fn) (write-line "(command \"_.ZOOM\" \"_C\" c v)" fn) (write-line "(if ucs (setq ucs nil))" fn) (write-line "(if d (setq d nil))" fn) (write-line "(mapcar '(lambda ( x ) (set x nil)) (list 'v 'c 'uo 'ux 'uy))" fn) (write-line "(princ)" fn) (close fn) ) (progn (setq vd (trans (getvar 'viewdir) 1 0 t)) (setq pe (getvar 'perspective)) (mapcar 'vl-propagate (list 'v 'c 'uo 'ux 'uy 'vd 'pe)) (setq fn (open "c:/processdoc.lsp" "w")) (write-line "(vl-load-com)" fn) (write-line "(setq d (vla-get-activedocument (vlax-get-acad-object)))" fn) (write-line "(command \"_.DVIEW\" \"\" \"_PO\" \"0,0,0\" vd \"\")" fn) (write-line "(vla-regen d acactiveviewport)" fn) (write-line "(if" fn) (write-line "(not" fn) (write-line "(and" fn) (write-line "(equal uo '(0.0 0.0 0.0))" fn) (write-line "(equal ux '(1.0 0.0 0.0))" fn) (write-line "(equal uy '(0.0 1.0 0.0))" fn) (write-line ")" fn) (write-line ")" fn) (write-line "(progn" fn) (write-line "(setq ucs (vla-add (vla-get-usercoordinatesystems d) (vlax-3d-point uo) (vlax-3d-point ux) (vlax-3d-point uy) \"{ UCS }\"))" fn) (write-line "(vla-put-activeucs d ucs)" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line "(vla-delete ucs)" fn) (write-line "(command \"_.UCS\" \"_P\")" fn) (write-line ")" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line ")" fn) (write-line "(command \"_.ZOOM\" \"_C\" c v)" fn) (write-line "(setvar 'perspective pe)" fn) (write-line "(if ucs (setq ucs nil))" fn) (write-line "(if d (setq d nil))" fn) (write-line "(mapcar '(lambda ( x ) (set x nil)) (list 'v 'c 'uo 'ux 'uy 'vd 'pe))" fn) (write-line "(command \"_.-PURGE\" \"_B\" \"DVIEWBLOCK\" \"_N\")" fn) (write-line "(princ)" fn) (close fn) ) ) (prompt "\nSwitch to each opened DWG, and type (load \"c:/processdoc.lsp\") and when finished return to master DWG and type (vl-file-delete \"c:/processdoc.lsp\")") (textscr) (princ) ) (defun c:scvtad nil (c:setcurrentviewtoalldwgs)) M.R. Edited March 22, 2015 by marko_ribar code changed to suit and paperspace view (cvport=1) Quote
pBe Posted March 22, 2015 Posted March 22, 2015 Not really sure what the OP meant by From here I would like to activite a LISP for drawing 2 to drawing 100 to zoom to the same location. If by that you mean not opening the drawing files? [ODBX ; What i had in mind was get the desired coordinates and pass the value via vl-propagate use a short code using the previous value from the opened drawing. In addition, any subsequent drawing that opens will also zoom to the same location until i deactivate the LISP. @vernonlee (setq var "Banana Cake") (vl-propagate 'var) Those values will float around the drawing session until such time the user set the values to nil. Will work on new drawings and newly open drawing as well values for var variable is "Global" Open an existing drawing Command: !var "Banana Cake" vl-propagateCopies the value of a variable into all open document namespaces (and sets its value in any subsequent drawings opened during the current AutoCAD session) Quote
vernonlee Posted March 22, 2015 Author Posted March 22, 2015 Not really sure what the OP meant by If by that you mean not opening the drawing files? Hi pBe. To clarify this is the scenario:- 1) Open dwg A, dwg B & dwg C 2) At dwg A (active dwg), I will zoom to the bottom left corner (in paper space) (At this point I will activate the LISP, whereby when i go to dwg B & dwg C their views will be zoomed to the bottom left corner (in paper space) just like dwg A. Just ignore step 3. It just makes it more complex [i][size=1]3)I will then open dwg D, dwg E & dwg F & automatically they will zoom to the same location as dwg A. Having said that, STEP 3 if it complicate matters, I can do without it. Since i can just do them in batches (step 1 & step 2), meaning[/size][/i] So for my 100 drawings this i what i hope to do:- 1) opening 20 drawings, 2) At dwg 1 (active dwg) I just zoom to the location, then activate the LISP & the rest of the 19 dwg will follow. I just repeat this steps 5 times & i am done with 100 drawings. This beats having to zoom in 100 times right? Quote
vernonlee Posted March 22, 2015 Author Posted March 22, 2015 Thanks marko_ribar for your suggested LISP. WIll try it out. If this covers step 2 then i am all set to go. Quote
pBe Posted March 22, 2015 Posted March 22, 2015 Its really easy vernonlee even without any fancy coding, Tell me, are you going to open all 20 files? EDIT: Yeah better try the code by Marko_ribar, that may very well work for your requirement. I see marko considered UCS conditions as well. I dont have cad with me right now Quote
marko_ribar Posted March 22, 2015 Posted March 22, 2015 pBe, yes it works, but you still have to switch to opened DWGs manually and manually paste line : (load "c:/processdoc.lsp") in every different DWG... So if there are 100 of them I think this isn't time saver for sure... Still we need to pass command line to opened DWGs and activate them before in some different way - automatically (maybe I am wrong, but I think that this is impossible - and even if we can pass complete function via (vl-propagate) function, how can we execute it after switching DWGs???) Quote
pBe Posted March 22, 2015 Posted March 22, 2015 A simple code [loaded / acaddoc.lsp or what not ] [Not Tested] (defun c:dew () (if (or OneCorner (setq OneCorner (getpoint "\nPick Lower left corner"))) (progn (command "_Zoom" "_Window" "_non" OneCorner "_non" (if OtherCorner OtherCorner (setq OtherCorner (getcorner OneCorner "\nSpecify opposite corner:")))) (vl-propagate 'OneCorner) (vl-propagate 'OtherCorner)))) (Defun c:rdew () (setq OneCorner nil OtherCorner nil) (c:dew) ) Quote
pBe Posted March 22, 2015 Posted March 22, 2015 pBe, yes it works Pretty sure it does but you still have to switch to opened DWGs manually Maybe , just maybe a short code using (vla-activate ....) (Defun c:next () (vla-activate [vla-item [document collection] index]) (c:dew);<-- will this run? ) Not sure, no way of knowing on my end under the current circumstances EDIT: i see what you mean now. Applying the "zoom" without switching thru opened drawings? I think it can be done though. or maybe NOT. NEED LAPTOP WITH AUTOCAD!!! Quote
marko_ribar Posted March 22, 2015 Posted March 22, 2015 (edited) Yes, it's better through acaddoc.lsp... Here is my version for this method... (defun c:scv nil (setq v (getvar 'viewsize) c (getvar 'viewctr)) (setq uo (trans '(0.0 0.0 0.0) 1 0)) (setq ux (trans '(1.0 0.0 0.0) 1 0)) (setq uy (trans '(0.0 1.0 0.0) 1 0)) (if (eq (getvar 'cvport) 1) (progn (mapcar 'vl-propagate (list 'v 'c 'uo 'ux 'uy)) ) (progn (setq vd (trans (getvar 'viewdir) 1 0 t)) (setq pe (getvar 'perspective)) (mapcar 'vl-propagate (list 'v 'c 'uo 'ux 'uy 'vd 'pe)) ) ) (prompt "\nSwitch to each opened DWG, and type \"rscv\"") (princ) ) (defun c:rscv nil (vl-load-com) (setq d (vla-get-activedocument (vlax-get-acad-object))) (if vd (command "_.DVIEW" "" "_PO" "0,0,0" vd "")) (vla-regen d acactiveviewport) (if (not (and (equal uo '(0.0 0.0 0.0)) (equal ux '(1.0 0.0 0.0)) (equal uy '(0.0 1.0 0.0)) ) ) (progn (setq ucs (vla-add (vla-get-usercoordinatesystems d) (vlax-3d-point uo) (vlax-3d-point ux) (vlax-3d-point uy) "{ UCS }")) (vla-put-activeucs d ucs) (command "_.UCS" "_W") (vla-delete ucs) (command "_.UCS" "_P") ) (command "_.UCS" "_W") ) (command "_.ZOOM" "_C" c v) (if pe (setvar 'perspective pe)) (if ucs (setq ucs nil)) (if d (setq d nil)) (if vd (command "_.-PURGE" "_B" "DVIEWBLOCK" "_N")) (prompt "\nWhen you're finished with all opened DWGs and with all \"rscv\", type \"scvc\"...") (princ) ) (defun c:scvc nil (mapcar '(lambda ( x ) (set x nil)) (list 'v 'c 'uo 'ux 'uy 'vd 'pe)) (mapcar 'vl-propagate (list 'v 'c 'uo 'ux 'uy 'vd 'pe)) (princ) ) Edited March 22, 2015 by marko_ribar Quote
vernonlee Posted March 22, 2015 Author Posted March 22, 2015 Yes, it's better through acaddoc.lsp... Here is my version for this method... So means do i run just this code? & it has to be through acaddoc.lsp? I have not experimented with acaddoc.lsp yet ALl this are beyond my depth but I will try my best to understand all suggestions. Thanks guys Quote
vernonlee Posted March 23, 2015 Author Posted March 23, 2015 Its really easy vernonlee even without any fancy coding, Tell me, are you going to open all 20 files? EDIT: Yeah better try the code by Marko_ribar, that may very well work for your requirement. I see marko considered UCS conditions as well. I dont have cad with me right now Hi pBe, Yes i will be opening as many drawing as i can without overloading the PC (I have opening as many as 30 before, but it does some time). Mainly is i need to check something at the same spot for all drawings. Thanks Quote
vernonlee Posted March 23, 2015 Author Posted March 23, 2015 Tried out this code. Got this errors Command: Command: '_.zoom _e Command: [b]z ZOOM[/b] [color=red]>>>>>> zoom to the location of the first dwg[/color] Specify corner of window, enter a scale factor (nX or nXP), or [All/Center/Dynamic/Extents/Previous/Scale/Window/Object] <real time>: Specify opposite corner: Command: Command: (LOAD "D:/Office/AutoCAD/lsp/Test/Zoom.lsp") C:SCVTAD [color=red]>load the LISP[/color] Command: SCVTAD [color=red]>>>>>>use this command [/color] (vl-load-com) (setq d (vla-get-activedocument (vlax-get-acad-object))) (vla-regen d acactiveviewport) (if (not (and (equal uo '(0.0 0.0 0.0)) (equal ux '(1.0 0.0 0.0)) (equal uy '(0.0 1.0 0.0)) ) ) (progn (setq ucs (vla-add (vla-get-usercoordinatesystems d) (vlax-3d-point uo) (vlax-3d-point ux) (vlax-3d-point uy) "{ UCS }")) (vla-put-activeucs d ucs) (command "_.UCS" "_W") (vla-delete ucs) (command "_.UCS" "_P") ) (command "_.UCS" "_W") ) (command "_.ZOOM" "_C" c v) (if ucs (setq ucs nil)) (if d (setq d nil)) (mapcar '(lambda ( x ) (set x nil)) (list 'v 'c 'uo 'ux 'uy)) (princ) ; error: bad argument type: streamp nil [color=red] >>>>>error?[/color] Command: Command: SETCURRENTVIEWTOALLDWGS [color=red]>>>>>>try this command [/color] (vl-load-com) (setq d (vla-get-activedocument (vlax-get-acad-object))) (vla-regen d acactiveviewport) (if (not (and (equal uo '(0.0 0.0 0.0)) (equal ux '(1.0 0.0 0.0)) (equal uy '(0.0 1.0 0.0)) ) ) (progn (setq ucs (vla-add (vla-get-usercoordinatesystems d) (vlax-3d-point uo) (vlax-3d-point ux) (vlax-3d-point uy) "{ UCS }")) (vla-put-activeucs d ucs) (command "_.UCS" "_W") (vla-delete ucs) (command "_.UCS" "_P") ) (command "_.UCS" "_W") ) (command "_.ZOOM" "_C" c v) (if ucs (setq ucs nil)) (if d (setq d nil)) (mapcar '(lambda ( x ) (set x nil)) (list 'v 'c 'uo 'ux 'uy)) (princ) ; error: bad argument type: streamp nil [color=red]>>>>>error?[/color] Command: 2nd dwg no change in view (defun c:setcurrentviewtoalldwgs ( / v c uo ux uy vd pe ) (setq v (getvar 'viewsize) c (getvar 'viewctr)) (setq uo (trans '(0.0 0.0 0.0) 1 0)) (setq ux (trans '(1.0 0.0 0.0) 1 0)) (setq uy (trans '(0.0 1.0 0.0) 1 0)) (if (eq (getvar 'cvport) 1) (progn (mapcar 'vl-propagate (list 'v 'c 'uo 'ux 'uy)) (setq fn (open "c:/processdoc.lsp" "w")) (write-line "(vl-load-com)" fn) (write-line "(setq d (vla-get-activedocument (vlax-get-acad-object)))" fn) (write-line "(vla-regen d acactiveviewport)" fn) (write-line "(if" fn) (write-line "(not" fn) (write-line "(and" fn) (write-line "(equal uo '(0.0 0.0 0.0))" fn) (write-line "(equal ux '(1.0 0.0 0.0))" fn) (write-line "(equal uy '(0.0 1.0 0.0))" fn) (write-line ")" fn) (write-line ")" fn) (write-line "(progn" fn) (write-line "(setq ucs (vla-add (vla-get-usercoordinatesystems d) (vlax-3d-point uo) (vlax-3d-point ux) (vlax-3d-point uy) \"{ UCS }\"))" fn) (write-line "(vla-put-activeucs d ucs)" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line "(vla-delete ucs)" fn) (write-line "(command \"_.UCS\" \"_P\")" fn) (write-line ")" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line ")" fn) (write-line "(command \"_.ZOOM\" \"_C\" c v)" fn) (write-line "(if ucs (setq ucs nil))" fn) (write-line "(if d (setq d nil))" fn) (write-line "(mapcar '(lambda ( x ) (set x nil)) (list 'v 'c 'uo 'ux 'uy))" fn) (write-line "(princ)" fn) (close fn) ) (progn (setq vd (trans (getvar 'viewdir) 1 0 t)) (setq pe (getvar 'perspective)) (mapcar 'vl-propagate (list 'v 'c 'uo 'ux 'uy 'vd 'pe)) (setq fn (open "c:/processdoc.lsp" "w")) (write-line "(vl-load-com)" fn) (write-line "(setq d (vla-get-activedocument (vlax-get-acad-object)))" fn) (write-line "(command \"_.DVIEW\" \"\" \"_PO\" \"0,0,0\" vd \"\")" fn) (write-line "(vla-regen d acactiveviewport)" fn) (write-line "(if" fn) (write-line "(not" fn) (write-line "(and" fn) (write-line "(equal uo '(0.0 0.0 0.0))" fn) (write-line "(equal ux '(1.0 0.0 0.0))" fn) (write-line "(equal uy '(0.0 1.0 0.0))" fn) (write-line ")" fn) (write-line ")" fn) (write-line "(progn" fn) (write-line "(setq ucs (vla-add (vla-get-usercoordinatesystems d) (vlax-3d-point uo) (vlax-3d-point ux) (vlax-3d-point uy) \"{ UCS }\"))" fn) (write-line "(vla-put-activeucs d ucs)" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line "(vla-delete ucs)" fn) (write-line "(command \"_.UCS\" \"_P\")" fn) (write-line ")" fn) (write-line "(command \"_.UCS\" \"_W\")" fn) (write-line ")" fn) (write-line "(command \"_.ZOOM\" \"_C\" c v)" fn) (write-line "(setvar 'perspective pe)" fn) (write-line "(if ucs (setq ucs nil))" fn) (write-line "(if d (setq d nil))" fn) (write-line "(mapcar '(lambda ( x ) (set x nil)) (list 'v 'c 'uo 'ux 'uy 'vd 'pe))" fn) (write-line "(command \"_.-PURGE\" \"_B\" \"DVIEWBLOCK\" \"_N\")" fn) (write-line "(princ)" fn) (close fn) ) ) (prompt "\nSwitch to each opened DWG, and type (load \"c:/processdoc.lsp\") and when finished return to master DWG and type (vl-file-delete \"c:/processdoc.lsp\")") (textscr) (princ) ) (defun c:scvtad nil (c:setcurrentviewtoalldwgs)) M.R. Quote
BIGAL Posted March 23, 2015 Posted March 23, 2015 Seems like lots of code for Zoom C Pt Scale why not just write the pt and scale to a file and then like a 3 line defun. C:ZOOMTOMYPT stored in acaddoc.lsp etc Z2P. Like wise the store pt&scale part so to reset Z22P. Z Quote
marko_ribar Posted March 23, 2015 Posted March 23, 2015 vermonlee, you used my previous and old code badly... You should load it and type SCVTAD when view in master dwg is set correctly, and you should read what's written in textscreen when SCVTAD is executed... You should then see that you have to copy+paste this line : (load "c:/processdoc.lsp") into new switched drawing in the same space as it's in master DWG... When you copy+paste this line - the code from c:\processdoc.lsp will execute automatically as it don't have defined function name and therefore view will be automatically setup... But this procedure is bad and as I said it's old code... You should use code posted here : http://www.cadtutor.net/forum/showthread.php?91547-HELP-A-LISP-that-will-zoom-to-a-same-specific-location-for-all-opening-drawings/page2&p=#12 Only thing you should do is to save it in some lsp file, for example : SCV.lsp, and if you already haven't created acaddoc.lsp, create one in folder c:\Program Files\Autodesk\AutoCAD ???\support\... I suggest that you place SCV.lsp also there in the same folder, as this folder is already part of SFSP (support file search path) assigned by default by installing AutoCAD software under OPTIONS -> FILES -> +SUPPORT SEARCH PATH menu tab... So you have to add this line in your acaddoc.lsp, so that AutoCAD can automatically load all 3 functions upon starting every new DWG... This line should look like this : (if (findfile "scv.lsp") (load "scv.lsp") (load (getfiled "Select scv.lsp file" "\\" "lsp" 16))) Of course, you can try to create your unique acaddoc.lsp adding as much *lsp files in the same manner I've used in my acaddoc.lsp, but only thing you should do is to remember with which commandname adequate lisp executes... In this case - main commandname is : SCV... Then upon autoloading SCV.lsp automatically in all opened DWGs, you execute it in master DWG with "scv" command and upon its finish of passing view setting variables on all opened other DWGs via (vl-propagate) function, the message will pop up in textscreen explaining new commandname you should use in restoring set current view - "rscv" command... So if you switch to other opened DWG, you only have to set that current active space matches with master DWG and there you type "rscv" - view will be synchronized with master DWG view, and after this command in textscreen also will pop up message explaining that you can use "rscv" on as many opened DWGs you have, but upon finish of synchronizing views to all of them where you wish to be synchronized, it's strongly suggested that you type "scvc" command to clear all variables that are been propagated through all opened DWGs, so that new other routines you may also have loaded via acaddoc.lsp or through "APPLOAD" command can work properly without interferences with previously propagated variables that are now nil... Quote
pBe Posted March 23, 2015 Posted March 23, 2015 Hi pBe, Yes i will be opening as many drawing as i can .... Mainly is i need to check something at the same spot for all drawings. Really? just to do what? Have you ever considered using XREF? Did you even try the snippet i posted vernonlee? Quote
vernonlee Posted March 23, 2015 Author Posted March 23, 2015 Really? just to do what? Have you ever considered using XREF? Did you even try the snippet i posted vernonlee? Well just the other day, my supervisor asked me to check if the levels have been updated & in their correct colour. This levels for all the drawings are located at the bottom right hand corner of the drawings. The levels cannot be xref since all storey will have different levels. So my job was to open all the drawings & zoom to the lower right corner of each drawing to check. Now this is not the first time i am asked to do. Hence I was thinking of haveing a LISP to make my work easier. Hope this answer your query. As for the snippets if you are refering to this:- Hint: 'Viewsize 'Screensize vl-propagate I still need to do some more research Quote
vernonlee Posted March 23, 2015 Author Posted March 23, 2015 Thanks for the detailed explanation marko_ribar. I will definitely need some time to read & understand. Quote
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.