PDuMont Posted May 17, 2017 Posted May 17, 2017 Hell All, I have searched and have not found anything to specifically point me in the right direction. Here is what I want to do: I have 1 to 10 title blocks in model space. I have 10 layout tabs, each with a viewport focused on it's corresponding title block. Some, or all title blocks may need to move in x, y, or xy, to accommodate material size. Typically I would need to switch to each layout and "zoom object" the title block for plotting purposes. I am trying to automate this process. I could create named groups around each title block and zoom to those, but I would like to find a better way. Each title block will have a unique number attribute, 4001 to 4110 for instance. Would there be a way to iterate through the blocks per layout, find this attribute, and zoom to the block? So Layout1 will zoom to 4001, Layout2 will zoom to 4002, etc. Any ideas or different approaches would be appreciated. Thanks Quote
tombu Posted May 17, 2017 Posted May 17, 2017 Layouts are for Title Blocks, Paper Space Viewports are for scaled areas of the drawing. Quote
BIGAL Posted May 18, 2017 Posted May 18, 2017 This has been discussed at length best way is to take the Title block from Model place it in a layout make a view port that matches then plot from layouts. I will have to find it but started a lisp to do this and auto converts and it takes into account different title block sizes. I know its at home and I may have done for Augi.com If you want I do have plot all title blocks in model space. Like tombu start the easy way next time with title block in layouts. Quote
PDuMont Posted May 18, 2017 Author Posted May 18, 2017 tombu, BIGAL, thanks for the replies. These title blocks are in model space for a specific reason. Each title block has unique attribute information, and the attribute information is much easier to fill out in model space via properties. Some of the information in these title blocks are needed for additional drawings, as well as different software, and the information needs to remain relative to 0,0,0. Quote
PDuMont Posted May 18, 2017 Author Posted May 18, 2017 Hi maratovich, In the dwg, material sizes can be 4'x8', 4'x10', 5'x8' and 5'x10'. Looking at the layouts will show how the viewport needs to be centered when the title block shifts. To this point I was iterating through the layouts to retrieve the number of the layout, Layout1, Layout2, etc. Then iterate through the blocks to retrieve PROGRAM_#: tag, 4011, 4012,etc, compare layout to blocks and zoom block using vl-remove possibly. Any help would be appreciated. Thanks TEST.dwg Quote
maratovich Posted May 18, 2017 Posted May 18, 2017 I have a solution, but it's not a lisp. This is a special program for printing. Here is an example. If necessary, write a private message. New TEST.dwg Quote
PDuMont Posted June 1, 2017 Author Posted June 1, 2017 In case anyone needs a clue to achieve something similar: (defun c:ZAC (/ *error* vars x doc tab curtab sset i ent attval pos ans) (defun *error* (msg) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) ) ;_ end of and (princ (strcat "\nError: " msg)) ) ;_ end of if (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars) ;reset vars ) ;_ end of defun (setq vars (mapcar '(lambda (x) (cons x (getvar x))) '(ctab cmdecho ) ) ;_ end of mapcar ) ;_ end of setq (if (not (eq (getvar 'ctab) "Model")) (progn (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark doc) (setvar 'cmdecho 0) (foreach tab (layoutlist) (setvar 'ctab tab) (setq curtab (substr (getvar 'ctab) ) (vla-put-MSpace doc :vlax-true) (if (setq sset (ssget "_X" '((0 . "INSERT") (66 . 1))) ) ;_ end of setq (progn (setq i 0) (repeat (sslength sset) (setq ent (ssname sset i)) (while (not (eq "SEQEND" (cdr (assoc 0 (entget (setq ent (entnext ent)) ) ;_ end of entget ) ;_ end of assoc ) ;_ end of cdr ) ;_ end of eq ) ;_ end of not (if (eq "PROGRAM_#:" (cdr (assoc 2 (entget ent)))) (progn (setq attval (cdr (assoc 1 (entget ent)))) (setq pos (substr attval 4)) (if (= curtab pos) (command "_ZOOM" "O" ent "") ) ;_ end of if ) ;_ end of progn ) ;_ end of if ) ;_ end of while (setq i (1+ i)) ) ;_ end of repeat ) ;_ end of progn ) ;_ end of if (vla-put-MSpace doc :vlax-false) ) ;_ end of foreach (initget "Yes No") (setq ans (getkword "Export PDF? [Yes/No]: <Y> ")) (if (not ans) (setq ans "Yes") ) ;_ end of if (if (eq ans "Yes") (command "EXPORTPDF") ) ;_ end of if (vla-endundomark doc) (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars) ) ;_ end of progn (princ "\nUse in layout tab only, exiting... ") ) ;_ end of if (princ) ) ;_ end of defun Quote
Jef! Posted June 2, 2017 Posted June 2, 2017 Hi everyone Layouts are for Title Blocks, Paper Space Viewports are for scaled areas of the drawing. I use to work for a company that were using exclusively modelspace, for everything including titleblocks. Sometimes it is due to to habits, existing product series or compatibility with some third party software. We all have our preferred practices, but on another hand, CAD being highly customizable, everyone (and every company) molds it to suit their own needs. Hi PDuMont. Francophone? I didn't look at the lisp you posted, I just did mine. Sometimes it is harder to to try to understand someone else's logic flow than to start from scratch. Looking at your example and given information, I take for granted that you always have a 4010 offset between Layout number and "PROGRAM_#:". I made a variable corresponding to the offset. I added few handy switches. RestoreZoomPrevious variable when set nil will leave layours zoomed to extent. (setq RestoreZoomPrevious t) will restore the zoom as it was on each layout when the command was launched LeaveVPLocked variable (setq LeaveVPLocked :vlax-true) will leave all viewports locked upon completion (setq LeaveVPLocked :vlax-false) will leave all viewports unlocked upon completion (setq LeaveVPLocked nil) will leave all viewports locked property as it was prior to running the lisp Here's what I made. Works flawlessly on my side on the drawing you provided. Let me know how it goes! (defun c:Zvp ( / LeaveVPLocked RestoreZoomPrevious BList oldctab offset acadObj doc TBs cnt en bename vplst minExt maxExt mspace oldvplocked) ;zoom Viewports v1.0 ;routine made by Jef! on 2017-06-02 ;change RestoreZoomPrevious and LeaveVPLocked to modify behavior as shown in comments beside them (setq RestoreZoomPrevious nil); nil will leave each Layout zoomed as it was. T will zoom all each layout (setq LeaveVPLocked nil); nil will leave VP as it was. :vlax-true will lock them all. :vlax-false will unlock them all (setq offset 4010); layout1 > prog 4011 (vl-load-com) (setq oldctab (getvar 'ctab)) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq TBs (ssget "_x" (list '(410 . "Model") '(0 . "INSERT") (cons 2 "`*U*") ) ) ) (setq cnt (sslength TBs)) (while (setq en (ssname TBs (setq cnt (1- cnt)))) (if (wcmatch (vla-get-effectivename (vlax-ename->vla-object en)) "CNC TITLE BLOCK-CIN-v2") (setq BList (cons (cons ((lambda (x / assoclst retbename) (while (and (setq x (entnext x)) (eq "ATTRIB" (cdr (assoc 0 (setq assoclst (entget x))))) (null retbename) ) (if (eq "PROGRAM_#:" (cdr(assoc 2 assoclst))) (setq retbename (atoi(cdr(assoc 1 assoclst)))) ) ) ) en ) en ) BList ) ) ) ) (foreach layout (layoutlist) (if (and (setq bename (cdr (assoc (+ offset (atoi (vl-string-left-trim "Layout" layout))) BList ))) (setq vplst (ssget "_x" (list (cons 410 layout) '(0 . "VIEWPORT") '(-4 . ">") '(69 . 1) ) ) ) ) (progn (setvar 'ctab layout) (setq cnt (sslength vplst)) (if (= (setq mspace (vla-get-mspace doc)) :vlax-true) (vla-put-MSpace doc :vlax-false) ) (vla-ZoomAll acadObj) (while (setq en (ssname vplst (setq cnt (1- cnt)))) (if (= (vla-get-DisplayLocked (vlax-ename->vla-object en)) :vlax-true) (and (setq oldvplocked :vlax-true) (vla-put-DisplayLocked (vlax-ename->vla-object en):vlax-false) ) (setq oldvplocked nil) ) (vla-put-MSpace doc :vlax-true) (vla-put-ActivePViewport doc (vlax-ename->vla-object en)) (vla-GetBoundingBox (vlax-ename->vla-object bename) 'minExt 'maxExt) (vla-zoomwindow (vlax-get-acad-object) (vlax-make-variant minExt)(vlax-make-variant maxExt)) (if LeaveVPLocked (vla-put-DisplayLocked (vlax-ename->vla-object en)LeaveVPLocked) (and oldvplocked (vla-put-DisplayLocked (vlax-ename->vla-object en)oldvplocked) ) ) ) (vla-put-MSpace doc :vlax-false) (if RestoreZoomPrevious (vla-ZoomPrevious acadObj) ) ) ) ) (setvar 'ctab oldctab) (vla-Regen doc acAllViewports) (princ) ) Beer-o-clock! Cheers Quote
PDuMont Posted June 7, 2017 Author Posted June 7, 2017 Hi Jef!, thanks for the response. Of French descent, but American. That's a nice bit of code you have there, but doesn't work for me. If you look at my code, the two matching criteria are last digit of attribute tag and last digit of layout tab name. I can't quite tell what you are doing with the offset. I will study yours more closely, thank you. Quote
PDuMont Posted June 7, 2017 Author Posted June 7, 2017 So, in trying something different, perhaps I stumbled upon something odd. Using an ssget window in model space, you need to zoom out to have the window area in the visible drawing area. It seems that is not a limitation when using an ssget window through a viewport. This works without the need for zooming out. (defun c:ZAC (/ *error* vars x doc tab curtab sset i ent attval pos ans) (defun *error* (msg) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) ) ;_ end of and (princ (strcat "\nError: " msg)) ) ;_ end of if (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars) ;reset vars ) ;_ end of defun (setq vars (mapcar '(lambda (x) (cons x (getvar x))) '(ctab cmdecho ) ) ;_ end of mapcar ) ;_ end of setq (if (not (eq (getvar 'ctab) "Model")) (progn (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark doc) (setvar 'cmdecho 0) (foreach tab (layoutlist) (setvar 'ctab tab) (setq curtab (substr (getvar 'ctab) ) (vla-put-MSpace doc :vlax-true) (if (setq sset (ssget "_C" '(264 -1265) '(-168 86) '((0 . "INSERT") (66 . 1))) ) ;_ end of setq (progn (setq i 0) (repeat (sslength sset) (setq ent (ssname sset i)) (while (not (eq "SEQEND" (cdr (assoc 0 (entget (setq ent (entnext ent)) ) ;_ end of entget ) ;_ end of assoc ) ;_ end of cdr ) ;_ end of eq ) ;_ end of not (if (eq "PROGRAM_#:" (cdr (assoc 2 (entget ent)))) (progn (setq attval (cdr (assoc 1 (entget ent)))) (setq pos (substr attval 4)) (if (= curtab pos) (command "_ZOOM" "O" ent "") ) ;_ end of if ) ;_ end of progn ) ;_ end of if ) ;_ end of while (setq i (1+ i)) ) ;_ end of repeat ) ;_ end of progn ) ;_ end of if (vla-put-MSpace doc :vlax-false) ) ;_ end of foreach (initget "Yes No") (setq ans (getkword "Export PDF? [Yes/No]: <Y> ")) (if (not ans) (setq ans "Yes") ) ;_ end of if (if (eq ans "Yes") (command "EXPORTPDF") ) ;_ end of if (vla-endundomark doc) (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars) ) ;_ end of progn (princ "\nUse in layout tab only, exiting... ") ) ;_ end of if (princ) ) ;_ end of defun Quote
PDuMont Posted June 7, 2017 Author Posted June 7, 2017 I stand corrected, the window does behave the same as in actual model space. Quote
Jef! Posted June 7, 2017 Posted June 7, 2017 (edited) That's a nice bit of code you have there, but doesn't work for me. If you look at my code, the two matching criteria are last digit of attribute tag and last digit of layout tab name. I can't quite tell what you are doing with the offset. I will study yours more closely, thank you. The way you just gave your criteria it doesn't work as soon as you have 10+ layouts like in the sample drawing you provided ( layout10 > prog #4020 ). As for what I did with the offset, I just hardcoded with the provided dwg sample Layout1 = prog4011 so 4011 - 1... offset 4010. Aparently it is subject to vary from dwg to dwg. That I couldn't know. No worries. Ok, I updated my code and made a slight change. I retrieve all layout #, all prog# attributes, and use the smallest value of each to calculate the offset on the fly. (defun c:Zvp ( / tmpblk tmplay LeaveVPLocked RestoreZoomPrevious BList oldctab offset acadObj doc TBs cnt en bename vplst minExt maxExt mspace oldvplocked);LeaveVPLocked RestoreZoomPrevious BList oldctab offset acadObj doc TBs cnt en bename vplst minExt maxExt mspace oldvplocked) ;zoom Viewports v1.0 ;routine made by Jef! on 2017-06-07 ;change RestoreZoomPrevious and LeaveVPLocked to modify behavior as shown in comments beside them (setq RestoreZoomPrevious nil); nil will leave each Layout zoomed as it was. T will zoom all each layout (setq LeaveVPLocked nil); nil will leave VP as it was. :vlax-true will lock them all. :vlax-false will unlock them all (vl-load-com) (setq oldctab (getvar 'ctab)) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq TBs (ssget "_x" (list '(410 . "Model") '(0 . "INSERT") (cons 2 "`*U*") ) ) ) (setq cnt (sslength TBs)) (while (setq en (ssname TBs (setq cnt (1- cnt)))) (if (wcmatch (vla-get-effectivename (vlax-ename->vla-object en)) "CNC TITLE BLOCK-CIN-v2") (setq BList (cons (cons ((lambda (x / assoclst retbename) (while (and (setq x (entnext x)) (eq "ATTRIB" (cdr (assoc 0 (setq assoclst (entget x))))) (null retbename) ) (if (eq "PROGRAM_#:" (cdr(assoc 2 assoclst))) (progn (setq tmpblk (cons (atoi(cdr(assoc 1 assoclst)))tmpblk)) (setq retbename (atoi(cdr(assoc 1 assoclst)))) ) ) ) ) en ) en ) BList ) ) ) ) (foreach layout (layoutlist) (setq tmplay (cons (atoi (vl-string-left-trim "Layout" layout)) tmplay)) ) (setq offset (- (car(vl-sort tmpblk '<)) (car(vl-sort tmplay '<)))); calculated diff between the smallest lay# and the lowest prog# attribute found (foreach layout (layoutlist) (if (and (setq bename (cdr (assoc (+ offset (atoi (vl-string-left-trim "Layout" layout))) BList ))) (setq vplst (ssget "_x" (list (cons 410 layout) '(0 . "VIEWPORT") '(-4 . ">") '(69 . 1) ) ) ) ) (progn (setvar 'ctab layout) (setq cnt (sslength vplst)) (if (= (setq mspace (vla-get-mspace doc)) :vlax-true) (vla-put-MSpace doc :vlax-false) ) (vla-ZoomAll acadObj) (while (setq en (ssname vplst (setq cnt (1- cnt)))) (if (= (vla-get-DisplayLocked (vlax-ename->vla-object en)) :vlax-true) (and (setq oldvplocked :vlax-true) (vla-put-DisplayLocked (vlax-ename->vla-object en):vlax-false) ) (setq oldvplocked nil) ) (vla-put-MSpace doc :vlax-true) (vla-put-ActivePViewport doc (vlax-ename->vla-object en)) (vla-GetBoundingBox (vlax-ename->vla-object bename) 'minExt 'maxExt) (vla-zoomwindow (vlax-get-acad-object) (vlax-make-variant minExt)(vlax-make-variant maxExt)) (if LeaveVPLocked (vla-put-DisplayLocked (vlax-ename->vla-object en)LeaveVPLocked) (and oldvplocked (vla-put-DisplayLocked (vlax-ename->vla-object en)oldvplocked) ) ) ) (vla-put-MSpace doc :vlax-false) (if RestoreZoomPrevious (vla-ZoomPrevious acadObj) ) ) ) ) (setvar 'ctab oldctab) (vla-Regen doc acAllViewports) (princ) ) Tell me how it goes. Cheers Edited June 7, 2017 by Jef! removed empty line from code 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.